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

@@ -45,6 +45,7 @@ type TopPodOptions struct {
Selector string
AllNamespaces bool
PrintContainers bool
NoHeaders bool
PodClient corev1client.PodsGetter
HeapsterOptions HeapsterTopOptions
Client *metricsutil.HeapsterMetricsClient
@@ -109,6 +110,7 @@ func NewCmdTopPod(f cmdutil.Factory, o *TopPodOptions, streams genericclioptions
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.PrintContainers, "containers", o.PrintContainers, "If present, print usage of containers within a pod.")
cmd.Flags().BoolVar(&o.AllNamespaces, "all-namespaces", o.AllNamespaces, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
cmd.Flags().BoolVar(&o.NoHeaders, "no-headers", o.NoHeaders, "If present, print output without headers.")
o.HeapsterOptions.Bind(cmd.Flags())
return cmd
}
@@ -198,7 +200,7 @@ func (o TopPodOptions) RunTopPod() error {
return err
}
return o.Printer.PrintPodMetrics(metrics.Items, o.PrintContainers, o.AllNamespaces)
return o.Printer.PrintPodMetrics(metrics.Items, o.PrintContainers, o.AllNamespaces, o.NoHeaders)
}
func getMetricsFromMetricsAPI(metricsClient metricsclientset.Interface, namespace, resourceName string, allNamespaces bool, selector labels.Selector) (*metricsapi.PodMetricsList, error) {