mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
Remove unnecessary return parameter from NewCmdTopPod
This commit is contained in:
parent
f084311326
commit
4d7d153a12
@ -52,9 +52,8 @@ func NewCmdTop(f cmdutil.Factory, out, errOut io.Writer) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create subcommands
|
// create subcommands
|
||||||
topPod, _ := NewCmdTopPod(f, nil, out)
|
|
||||||
cmd.AddCommand(NewCmdTopNode(f, nil, out))
|
cmd.AddCommand(NewCmdTopNode(f, nil, out))
|
||||||
cmd.AddCommand(topPod)
|
cmd.AddCommand(NewCmdTopPod(f, nil, out))
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ var (
|
|||||||
kubectl top pod -l name=myLabel`))
|
kubectl top pod -l name=myLabel`))
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdTopPod(f cmdutil.Factory, options *TopPodOptions, out io.Writer) (*cobra.Command, *TopPodOptions) {
|
func NewCmdTopPod(f cmdutil.Factory, options *TopPodOptions, out io.Writer) *cobra.Command {
|
||||||
if options == nil {
|
if options == nil {
|
||||||
options = &TopPodOptions{}
|
options = &TopPodOptions{}
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ func NewCmdTopPod(f cmdutil.Factory, options *TopPodOptions, out io.Writer) (*co
|
|||||||
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())
|
options.HeapsterOptions.Bind(cmd.Flags())
|
||||||
return cmd, options
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
|
func (o *TopPodOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
|
||||||
|
@ -190,7 +190,7 @@ func TestTopPod(t *testing.T) {
|
|||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd, _ := NewCmdTopPod(f, nil, 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)
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ func TestTopPodWithMetricsServer(t *testing.T) {
|
|||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
namespace string
|
namespace string
|
||||||
flags map[string]string
|
options *TopPodOptions
|
||||||
args []string
|
args []string
|
||||||
expectedPath string
|
expectedPath string
|
||||||
expectedQuery string
|
expectedQuery string
|
||||||
@ -236,7 +236,7 @@ func TestTopPodWithMetricsServer(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "all namespaces",
|
name: "all namespaces",
|
||||||
flags: map[string]string{"all-namespaces": "true"},
|
options: &TopPodOptions{AllNamespaces: true},
|
||||||
expectedPath: topMetricsAPIPathPrefix + "/pods",
|
expectedPath: topMetricsAPIPathPrefix + "/pods",
|
||||||
namespaces: []string{testNS, "secondtestns", "thirdtestns"},
|
namespaces: []string{testNS, "secondtestns", "thirdtestns"},
|
||||||
listsNamespaces: true,
|
listsNamespaces: true,
|
||||||
@ -254,14 +254,14 @@ func TestTopPodWithMetricsServer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pod with label selector",
|
name: "pod with label selector",
|
||||||
flags: map[string]string{"selector": "key=value"},
|
options: &TopPodOptions{Selector: "key=value"},
|
||||||
expectedPath: topMetricsAPIPathPrefix + "/namespaces/" + testNS + "/pods",
|
expectedPath: topMetricsAPIPathPrefix + "/namespaces/" + testNS + "/pods",
|
||||||
expectedQuery: "labelSelector=" + url.QueryEscape("key=value"),
|
expectedQuery: "labelSelector=" + url.QueryEscape("key=value"),
|
||||||
namespaces: []string{testNS, testNS},
|
namespaces: []string{testNS, testNS},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "pod with container metrics",
|
name: "pod with container metrics",
|
||||||
flags: map[string]string{"containers": "true"},
|
options: &TopPodOptions{PrintContainers: true},
|
||||||
args: []string{"pod1"},
|
args: []string{"pod1"},
|
||||||
expectedPath: topMetricsAPIPathPrefix + "/namespaces/" + testNS + "/pods/pod1",
|
expectedPath: topMetricsAPIPathPrefix + "/namespaces/" + testNS + "/pods/pod1",
|
||||||
namespaces: []string{testNS},
|
namespaces: []string{testNS},
|
||||||
@ -326,9 +326,12 @@ func TestTopPodWithMetricsServer(t *testing.T) {
|
|||||||
tf.ClientConfig = defaultClientConfig()
|
tf.ClientConfig = defaultClientConfig()
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd, cmdOptions := NewCmdTopPod(f, nil, buf)
|
cmd := NewCmdTopPod(f, nil, buf)
|
||||||
for name, value := range testCase.flags {
|
var cmdOptions *TopPodOptions
|
||||||
cmd.Flags().Set(name, value)
|
if testCase.options != nil {
|
||||||
|
cmdOptions = testCase.options
|
||||||
|
} else {
|
||||||
|
cmdOptions = &TopPodOptions{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO in the long run, we want to test most of our commands like this. Wire the options struct with specific mocks
|
// TODO in the long run, we want to test most of our commands like this. Wire the options struct with specific mocks
|
||||||
@ -532,7 +535,7 @@ func TestTopPodCustomDefaults(t *testing.T) {
|
|||||||
},
|
},
|
||||||
DiscoveryClient: &fakeDiscovery{},
|
DiscoveryClient: &fakeDiscovery{},
|
||||||
}
|
}
|
||||||
cmd, _ := NewCmdTopPod(f, opts, buf)
|
cmd := NewCmdTopPod(f, opts, 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