mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #102917 from bysnupy/patch-1
Use "Capacity" instead of "Allocatable" for an accurate node memory total size
This commit is contained in:
		@@ -44,6 +44,7 @@ type TopNodeOptions struct {
 | 
			
		||||
	SortBy             string
 | 
			
		||||
	NoHeaders          bool
 | 
			
		||||
	UseProtocolBuffers bool
 | 
			
		||||
	ShowCapacity       bool
 | 
			
		||||
 | 
			
		||||
	NodeClient      corev1client.CoreV1Interface
 | 
			
		||||
	Printer         *metricsutil.TopCmdPrinter
 | 
			
		||||
@@ -93,6 +94,7 @@ func NewCmdTopNode(f cmdutil.Factory, o *TopNodeOptions, streams genericclioptio
 | 
			
		||||
	cmd.Flags().StringVar(&o.SortBy, "sort-by", o.SortBy, "If non-empty, sort nodes list using specified field. The field can be either 'cpu' or 'memory'.")
 | 
			
		||||
	cmd.Flags().BoolVar(&o.NoHeaders, "no-headers", o.NoHeaders, "If present, print output without headers")
 | 
			
		||||
	cmd.Flags().BoolVar(&o.UseProtocolBuffers, "use-protocol-buffers", o.UseProtocolBuffers, "Enables using protocol-buffers to access Metrics API.")
 | 
			
		||||
	cmd.Flags().BoolVar(&o.ShowCapacity, "show-capacity", o.ShowCapacity, "Print node resources based on Capacity instead of Allocatable(default) of the nodes.")
 | 
			
		||||
 | 
			
		||||
	return cmd
 | 
			
		||||
}
 | 
			
		||||
@@ -188,13 +190,17 @@ func (o TopNodeOptions) RunTopNode() error {
 | 
			
		||||
		nodes = append(nodes, nodeList.Items...)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	allocatable := make(map[string]v1.ResourceList)
 | 
			
		||||
	availableResources := make(map[string]v1.ResourceList)
 | 
			
		||||
 | 
			
		||||
	for _, n := range nodes {
 | 
			
		||||
		allocatable[n.Name] = n.Status.Allocatable
 | 
			
		||||
		if !o.ShowCapacity {
 | 
			
		||||
			availableResources[n.Name] = n.Status.Allocatable
 | 
			
		||||
		} else {
 | 
			
		||||
			availableResources[n.Name] = n.Status.Capacity
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return o.Printer.PrintNodeMetrics(metrics.Items, allocatable, o.NoHeaders, o.SortBy)
 | 
			
		||||
	return o.Printer.PrintNodeMetrics(metrics.Items, availableResources, o.NoHeaders, o.SortBy)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getNodeMetricsFromMetricsAPI(metricsClient metricsclientset.Interface, resourceName string, selector labels.Selector) (*metricsapi.NodeMetricsList, error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user