mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
allow default option values - kube top node|pod
This commit is contained in:
parent
5e0a539cf1
commit
5b8b1eb2eb
@ -47,7 +47,7 @@ func NewCmdTop(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create subcommands
|
// create subcommands
|
||||||
cmd.AddCommand(NewCmdTopNode(f, out))
|
cmd.AddCommand(NewCmdTopNode(f, nil, out))
|
||||||
cmd.AddCommand(NewCmdTopPod(f, out))
|
cmd.AddCommand(NewCmdTopPod(f, nil, out))
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,23 @@ type HeapsterTopOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *HeapsterTopOptions) Bind(flags *pflag.FlagSet) {
|
func (o *HeapsterTopOptions) Bind(flags *pflag.FlagSet) {
|
||||||
flags.StringVar(&o.Namespace, "heapster-namespace", metricsutil.DefaultHeapsterNamespace, "Namespace Heapster service is located in")
|
if len(o.Namespace) == 0 {
|
||||||
flags.StringVar(&o.Service, "heapster-service", metricsutil.DefaultHeapsterService, "Name of Heapster service")
|
o.Namespace = metricsutil.DefaultHeapsterNamespace
|
||||||
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")
|
if len(o.Service) == 0 {
|
||||||
|
o.Service = metricsutil.DefaultHeapsterService
|
||||||
|
}
|
||||||
|
if len(o.Scheme) == 0 {
|
||||||
|
o.Scheme = metricsutil.DefaultHeapsterScheme
|
||||||
|
}
|
||||||
|
if len(o.Port) == 0 {
|
||||||
|
o.Port = metricsutil.DefaultHeapsterPort
|
||||||
|
}
|
||||||
|
|
||||||
|
flags.StringVar(&o.Namespace, "heapster-namespace", o.Namespace, "Namespace Heapster service is located in")
|
||||||
|
flags.StringVar(&o.Service, "heapster-service", o.Service, "Name of Heapster service")
|
||||||
|
flags.StringVar(&o.Scheme, "heapster-scheme", o.Scheme, "Scheme (http or https) to connect to Heapster as")
|
||||||
|
flags.StringVar(&o.Port, "heapster-port", o.Port, "Port name in service to use")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -70,8 +83,10 @@ var (
|
|||||||
kubectl top node NODE_NAME`))
|
kubectl top node NODE_NAME`))
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdTopNode(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewCmdTopNode(f cmdutil.Factory, options *TopNodeOptions, out io.Writer) *cobra.Command {
|
||||||
options := &TopNodeOptions{}
|
if options == nil {
|
||||||
|
options = &TopNodeOptions{}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "node [NAME | -l label]",
|
Use: "node [NAME | -l label]",
|
||||||
|
@ -67,7 +67,7 @@ func TestTopNodeAllMetrics(t *testing.T) {
|
|||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd := NewCmdTopNode(f, buf)
|
cmd := NewCmdTopNode(f, nil, buf)
|
||||||
cmd.Run(cmd, []string{})
|
cmd.Run(cmd, []string{})
|
||||||
|
|
||||||
// Check the presence of node names in the output.
|
// Check the presence of node names in the output.
|
||||||
@ -116,7 +116,7 @@ func TestTopNodeWithNameMetrics(t *testing.T) {
|
|||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd := NewCmdTopNode(f, buf)
|
cmd := NewCmdTopNode(f, nil, buf)
|
||||||
cmd.Run(cmd, []string{expectedMetrics.Name})
|
cmd.Run(cmd, []string{expectedMetrics.Name})
|
||||||
|
|
||||||
// Check the presence of node names in the output.
|
// Check the presence of node names in the output.
|
||||||
@ -176,7 +176,7 @@ func TestTopNodeWithLabelSelectorMetrics(t *testing.T) {
|
|||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd := NewCmdTopNode(f, buf)
|
cmd := NewCmdTopNode(f, nil, buf)
|
||||||
cmd.Flags().Set("selector", label)
|
cmd.Flags().Set("selector", label)
|
||||||
cmd.Run(cmd, []string{})
|
cmd.Run(cmd, []string{})
|
||||||
|
|
||||||
|
@ -72,8 +72,10 @@ var (
|
|||||||
kubectl top pod -l name=myLabel`))
|
kubectl top pod -l name=myLabel`))
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdTopPod(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewCmdTopPod(f cmdutil.Factory, options *TopPodOptions, out io.Writer) *cobra.Command {
|
||||||
options := &TopPodOptions{}
|
if options == nil {
|
||||||
|
options = &TopPodOptions{}
|
||||||
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "pod [NAME | -l label]",
|
Use: "pod [NAME | -l label]",
|
||||||
|
@ -139,7 +139,7 @@ func TestTopPod(t *testing.T) {
|
|||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd := NewCmdTopPod(f, buf)
|
cmd := NewCmdTopPod(f, nil, buf)
|
||||||
for name, value := range testCase.flags {
|
for name, value := range testCase.flags {
|
||||||
cmd.Flags().Set(name, value)
|
cmd.Flags().Set(name, value)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user