Skip to content

Commit 3cf3702

Browse files
authored
Merge pull request kubernetes#119346 from chendave/clean_testcases
kubeadm: Remove the usage to print the default component configs for `reset` and `join`
2 parents 370c85f + 879dad9 commit 3cf3702

File tree

2 files changed

+12
-48
lines changed

2 files changed

+12
-48
lines changed

cmd/kubeadm/app/cmd/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ func newCmdConfigPrintActionDefaults(out io.Writer, action string, configBytesPr
133133
},
134134
Args: cobra.NoArgs,
135135
}
136-
cmd.Flags().StringSliceVar(&kinds, "component-configs", kinds,
137-
fmt.Sprintf("A comma-separated list for component config API objects to print the default values for. Available values: %v. If this flag is not set, no component configs will be printed.", getSupportedComponentConfigKinds()))
136+
if action == "init" {
137+
cmd.Flags().StringSliceVar(&kinds, "component-configs", kinds,
138+
fmt.Sprintf("A comma-separated list for component config API objects to print the default values for. Available values: %v. If this flag is not set, no component configs will be printed.", getSupportedComponentConfigKinds()))
139+
}
138140
return cmd
139141
}
140142

cmd/kubeadm/app/cmd/config_test.go

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -426,56 +426,16 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
426426
cmdProc: newCmdConfigPrintInitDefaults,
427427
},
428428
{
429-
name: "JoinConfiguration: No component configs",
429+
name: "JoinConfiguration",
430430
expectedKinds: []string{
431431
constants.JoinConfigurationKind,
432432
},
433433
cmdProc: newCmdConfigPrintJoinDefaults,
434434
},
435435
{
436-
name: "JoinConfiguration: KubeProxyConfiguration",
437-
expectedKinds: []string{
438-
constants.JoinConfigurationKind,
439-
"KubeProxyConfiguration",
440-
},
441-
componentConfigs: "KubeProxyConfiguration",
442-
cmdProc: newCmdConfigPrintJoinDefaults,
443-
},
444-
{
445-
name: "JoinConfiguration: KubeProxyConfiguration and KubeletConfiguration",
446-
expectedKinds: []string{
447-
constants.JoinConfigurationKind,
448-
"KubeProxyConfiguration",
449-
"KubeletConfiguration",
450-
},
451-
componentConfigs: "KubeProxyConfiguration,KubeletConfiguration",
452-
cmdProc: newCmdConfigPrintJoinDefaults,
453-
},
454-
{
455-
name: "ResetConfiguration: No component configs",
456-
expectedKinds: []string{
457-
constants.ResetConfigurationKind,
458-
},
459-
cmdProc: newCmdConfigPrintResetDefaults,
460-
},
461-
{
462-
name: "JoinConfiguration: KubeProxyConfiguration",
463-
expectedKinds: []string{
464-
"KubeProxyConfiguration",
465-
constants.ResetConfigurationKind,
466-
},
467-
componentConfigs: "KubeProxyConfiguration",
468-
cmdProc: newCmdConfigPrintResetDefaults,
469-
},
470-
{
471-
name: "JoinConfiguration: KubeProxyConfiguration and KubeletConfiguration",
472-
expectedKinds: []string{
473-
"KubeProxyConfiguration",
474-
"KubeletConfiguration",
475-
constants.ResetConfigurationKind,
476-
},
477-
componentConfigs: "KubeProxyConfiguration,KubeletConfiguration",
478-
cmdProc: newCmdConfigPrintResetDefaults,
436+
name: "ResetConfiguration",
437+
expectedKinds: []string{constants.ResetConfigurationKind},
438+
cmdProc: newCmdConfigPrintResetDefaults,
479439
},
480440
}
481441

@@ -484,8 +444,10 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
484444
var output bytes.Buffer
485445

486446
command := test.cmdProc(&output)
487-
if err := command.Flags().Set("component-configs", test.componentConfigs); err != nil {
488-
t.Fatalf("failed to set component-configs flag")
447+
if test.componentConfigs != "" {
448+
if err := command.Flags().Set("component-configs", test.componentConfigs); err != nil {
449+
t.Fatalf("failed to set component-configs flag")
450+
}
489451
}
490452
if err := command.RunE(nil, nil); err != nil {
491453
t.Fatalf("Error from running the print command: %v", err)

0 commit comments

Comments
 (0)