mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
kubectl top pod|node should handle when Heapster is somewhere else
OpenShift runs Heapster on HTTPS, which means `top node` and `top pod` are broken because they hardcode 'http' as the scheme. Provide an options struct allowing users to specify `--heapster-namespace`, `--heapster-service`, `--heapster-scheme`, and `--heapster-port` to the commands (leveraging the existing defaults).
This commit is contained in:
parent
a2d5df40af
commit
3d237cac2e
@ -247,6 +247,10 @@ hard
|
|||||||
hard-pod-affinity-symmetric-weight
|
hard-pod-affinity-symmetric-weight
|
||||||
healthz-bind-address
|
healthz-bind-address
|
||||||
healthz-port
|
healthz-port
|
||||||
|
heapster-namespace
|
||||||
|
heapster-port
|
||||||
|
heapster-scheme
|
||||||
|
heapster-service
|
||||||
horizontal-pod-autoscaler-sync-period
|
horizontal-pod-autoscaler-sync-period
|
||||||
host-cluster-context
|
host-cluster-context
|
||||||
host-ipc-sources
|
host-ipc-sources
|
||||||
|
@ -118,6 +118,7 @@ go_library(
|
|||||||
"//vendor:github.com/jonboulle/clockwork",
|
"//vendor:github.com/jonboulle/clockwork",
|
||||||
"//vendor:github.com/renstrom/dedent",
|
"//vendor:github.com/renstrom/dedent",
|
||||||
"//vendor:github.com/spf13/cobra",
|
"//vendor:github.com/spf13/cobra",
|
||||||
|
"//vendor:github.com/spf13/pflag",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||||
@ -35,10 +35,25 @@ type TopNodeOptions struct {
|
|||||||
ResourceName string
|
ResourceName string
|
||||||
Selector string
|
Selector string
|
||||||
NodeClient coreclient.NodesGetter
|
NodeClient coreclient.NodesGetter
|
||||||
|
HeapsterOptions HeapsterTopOptions
|
||||||
Client *metricsutil.HeapsterMetricsClient
|
Client *metricsutil.HeapsterMetricsClient
|
||||||
Printer *metricsutil.TopCmdPrinter
|
Printer *metricsutil.TopCmdPrinter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HeapsterTopOptions struct {
|
||||||
|
Namespace string
|
||||||
|
Service string
|
||||||
|
Scheme string
|
||||||
|
Port string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *HeapsterTopOptions) Bind(flags *pflag.FlagSet) {
|
||||||
|
flags.StringVar(&o.Namespace, "heapster-namespace", metricsutil.DefaultHeapsterNamespace, "Namespace Heapster service is located in")
|
||||||
|
flags.StringVar(&o.Service, "heapster-service", metricsutil.DefaultHeapsterService, "Name of Heapster service")
|
||||||
|
flags.StringVar(&o.Scheme, "heapster-scheme", metricsutil.DefaultHeapsterScheme, "Scheme (http or https) to connect to Heapster as")
|
||||||
|
flags.StringVar(&o.Port, "heapster-port", metricsutil.DefaultHeapsterPort, "Port name in service to use")
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
topNodeLong = templates.LongDesc(`
|
topNodeLong = templates.LongDesc(`
|
||||||
Display Resource (CPU/Memory/Storage) usage of nodes.
|
Display Resource (CPU/Memory/Storage) usage of nodes.
|
||||||
@ -75,6 +90,7 @@ func NewCmdTopNode(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
Aliases: []string{"nodes"},
|
Aliases: []string{"nodes"},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on")
|
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on")
|
||||||
|
options.HeapsterOptions.Bind(cmd.Flags())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +107,7 @@ func (o *TopNodeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
o.NodeClient = clientset.Core()
|
o.NodeClient = clientset.Core()
|
||||||
o.Client = metricsutil.DefaultHeapsterMetricsClient(clientset.Core())
|
o.Client = metricsutil.NewHeapsterMetricsClient(clientset.Core(), o.HeapsterOptions.Namespace, o.HeapsterOptions.Scheme, o.HeapsterOptions.Service, o.HeapsterOptions.Port)
|
||||||
o.Printer = metricsutil.NewTopCmdPrinter(out)
|
o.Printer = metricsutil.NewTopCmdPrinter(out)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ type TopPodOptions struct {
|
|||||||
AllNamespaces bool
|
AllNamespaces bool
|
||||||
PrintContainers bool
|
PrintContainers bool
|
||||||
PodClient coreclient.PodsGetter
|
PodClient coreclient.PodsGetter
|
||||||
|
HeapsterOptions HeapsterTopOptions
|
||||||
Client *metricsutil.HeapsterMetricsClient
|
Client *metricsutil.HeapsterMetricsClient
|
||||||
Printer *metricsutil.TopCmdPrinter
|
Printer *metricsutil.TopCmdPrinter
|
||||||
}
|
}
|
||||||
@ -93,6 +94,7 @@ func NewCmdTopPod(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on")
|
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on")
|
||||||
cmd.Flags().BoolVar(&options.PrintContainers, "containers", false, "If present, print usage of containers within a pod.")
|
cmd.Flags().BoolVar(&options.PrintContainers, "containers", false, "If present, print usage of containers within a pod.")
|
||||||
cmd.Flags().BoolVar(&options.AllNamespaces, "all-namespaces", false, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
|
cmd.Flags().BoolVar(&options.AllNamespaces, "all-namespaces", false, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
|
||||||
|
options.HeapsterOptions.Bind(cmd.Flags())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +115,7 @@ func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
o.PodClient = clientset.Core()
|
o.PodClient = clientset.Core()
|
||||||
o.Client = metricsutil.DefaultHeapsterMetricsClient(clientset.Core())
|
o.Client = metricsutil.NewHeapsterMetricsClient(clientset.Core(), o.HeapsterOptions.Namespace, o.HeapsterOptions.Scheme, o.HeapsterOptions.Service, o.HeapsterOptions.Port)
|
||||||
o.Printer = metricsutil.NewTopCmdPrinter(out)
|
o.Printer = metricsutil.NewTopCmdPrinter(out)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user