mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +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
|
||||
healthz-bind-address
|
||||
healthz-port
|
||||
heapster-namespace
|
||||
heapster-port
|
||||
heapster-scheme
|
||||
heapster-service
|
||||
horizontal-pod-autoscaler-sync-period
|
||||
host-cluster-context
|
||||
host-ipc-sources
|
||||
|
@ -118,6 +118,7 @@ go_library(
|
||||
"//vendor:github.com/jonboulle/clockwork",
|
||||
"//vendor:github.com/renstrom/dedent",
|
||||
"//vendor:github.com/spf13/cobra",
|
||||
"//vendor:github.com/spf13/pflag",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
@ -32,11 +32,26 @@ import (
|
||||
|
||||
// TopNodeOptions contains all the options for running the top-node cli command.
|
||||
type TopNodeOptions struct {
|
||||
ResourceName string
|
||||
Selector string
|
||||
NodeClient coreclient.NodesGetter
|
||||
Client *metricsutil.HeapsterMetricsClient
|
||||
Printer *metricsutil.TopCmdPrinter
|
||||
ResourceName string
|
||||
Selector string
|
||||
NodeClient coreclient.NodesGetter
|
||||
HeapsterOptions HeapsterTopOptions
|
||||
Client *metricsutil.HeapsterMetricsClient
|
||||
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 (
|
||||
@ -75,6 +90,7 @@ func NewCmdTopNode(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
Aliases: []string{"nodes"},
|
||||
}
|
||||
cmd.Flags().StringVarP(&options.Selector, "selector", "l", "", "Selector (label query) to filter on")
|
||||
options.HeapsterOptions.Bind(cmd.Flags())
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -91,7 +107,7 @@ func (o *TopNodeOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
|
||||
return err
|
||||
}
|
||||
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)
|
||||
return nil
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ type TopPodOptions struct {
|
||||
AllNamespaces bool
|
||||
PrintContainers bool
|
||||
PodClient coreclient.PodsGetter
|
||||
HeapsterOptions HeapsterTopOptions
|
||||
Client *metricsutil.HeapsterMetricsClient
|
||||
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().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.")
|
||||
options.HeapsterOptions.Bind(cmd.Flags())
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -113,7 +115,7 @@ func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []s
|
||||
return err
|
||||
}
|
||||
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)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user