add flag --no-headers to kubectl top ...

This commit is contained in:
WanLinghao
2018-08-27 19:27:48 +08:00
parent 4733b85714
commit c9b6c92f10
5 changed files with 36 additions and 14 deletions

View File

@@ -40,6 +40,7 @@ import (
type TopNodeOptions struct {
ResourceName string
Selector string
NoHeaders bool
NodeClient corev1client.CoreV1Interface
HeapsterOptions HeapsterTopOptions
Client *metricsutil.HeapsterMetricsClient
@@ -118,6 +119,8 @@ func NewCmdTopNode(f cmdutil.Factory, o *TopNodeOptions, streams genericclioptio
Aliases: []string{"nodes", "no"},
}
cmd.Flags().StringVarP(&o.Selector, "selector", "l", o.Selector, "Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)")
cmd.Flags().BoolVar(&o.NoHeaders, "no-headers", o.NoHeaders, "If present, print output without headers")
o.HeapsterOptions.Bind(cmd.Flags())
return cmd
}
@@ -216,7 +219,7 @@ func (o TopNodeOptions) RunTopNode() error {
allocatable[n.Name] = n.Status.Allocatable
}
return o.Printer.PrintNodeMetrics(metrics.Items, allocatable)
return o.Printer.PrintNodeMetrics(metrics.Items, allocatable, o.NoHeaders)
}
func getNodeMetricsFromMetricsAPI(metricsClient metricsclientset.Interface, resourceName string, selector labels.Selector) (*metricsapi.NodeMetricsList, error) {