diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go index 31873fff47f..ce0cfcac5d3 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go @@ -211,7 +211,7 @@ func (o *DebugOptions) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVar(&o.TargetContainer, "target", "", i18n.T("When using an ephemeral container, target processes in this container name.")) cmd.Flags().BoolVarP(&o.TTY, "tty", "t", o.TTY, i18n.T("Allocate a TTY for the debugging container.")) cmd.Flags().StringVar(&o.Profile, "profile", ProfileLegacy, i18n.T(`Options are "legacy", "general", "baseline", "netadmin", "restricted" or "sysadmin".`)) - if cmdutil.DebugCustomProfile.IsEnabled() { + if !cmdutil.DebugCustomProfile.IsDisabled() { cmd.Flags().StringVar(&o.CustomProfileFile, "custom", o.CustomProfileFile, i18n.T("Path to a JSON file containing a partial container spec to customize built-in debug profiles.")) } } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go index b9690e6efb1..4fbfbaeada0 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go @@ -22,8 +22,6 @@ import ( "testing" "time" - cmdutil "k8s.io/kubectl/pkg/cmd/util" - "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/spf13/cobra" @@ -2088,31 +2086,29 @@ func TestGenerateNodeDebugPodCustomProfile(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { - cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) { - var err error - kflags := KeepFlags{ - Labels: tc.opts.KeepLabels, - Annotations: tc.opts.KeepAnnotations, - Liveness: tc.opts.KeepLiveness, - Readiness: tc.opts.KeepReadiness, - Startup: tc.opts.KeepStartup, - InitContainers: tc.opts.KeepInitContainers, - } - tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags) - if err != nil { - t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) - } - tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard() + var err error + kflags := KeepFlags{ + Labels: tc.opts.KeepLabels, + Annotations: tc.opts.KeepAnnotations, + Liveness: tc.opts.KeepLiveness, + Readiness: tc.opts.KeepReadiness, + Startup: tc.opts.KeepStartup, + InitContainers: tc.opts.KeepInitContainers, + } + tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags) + if err != nil { + t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) + } + tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard() - pod, err := tc.opts.generateNodeDebugPod(tc.node) - if err != nil { - t.Fatalf("Fail to generate node debug pod: %v", err) - } - tc.expected.Name = pod.Name - if diff := cmp.Diff(tc.expected, pod); diff != "" { - t.Error("unexpected diff in generated object: (-want +got):\n", diff) - } - }) + pod, err := tc.opts.generateNodeDebugPod(tc.node) + if err != nil { + t.Fatalf("Fail to generate node debug pod: %v", err) + } + tc.expected.Name = pod.Name + if diff := cmp.Diff(tc.expected, pod); diff != "" { + t.Error("unexpected diff in generated object: (-want +got):\n", diff) + } }) } } @@ -2296,31 +2292,29 @@ func TestGenerateCopyDebugPodCustomProfile(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { - cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) { - var err error - kflags := KeepFlags{ - Labels: tc.opts.KeepLabels, - Annotations: tc.opts.KeepAnnotations, - Liveness: tc.opts.KeepLiveness, - Readiness: tc.opts.KeepReadiness, - Startup: tc.opts.KeepStartup, - InitContainers: tc.opts.KeepInitContainers, - } - tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags) - if err != nil { - t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) - } - tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard() + var err error + kflags := KeepFlags{ + Labels: tc.opts.KeepLabels, + Annotations: tc.opts.KeepAnnotations, + Liveness: tc.opts.KeepLiveness, + Readiness: tc.opts.KeepReadiness, + Startup: tc.opts.KeepStartup, + InitContainers: tc.opts.KeepInitContainers, + } + tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags) + if err != nil { + t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) + } + tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard() - pod, dc, err := tc.opts.generatePodCopyWithDebugContainer(tc.copyPod) - if err != nil { - t.Fatalf("Fail to generate node debug pod: %v", err) - } - tc.expected.Spec.Containers[0].Name = dc - if diff := cmp.Diff(tc.expected, pod); diff != "" { - t.Error("unexpected diff in generated object: (-want +got):\n", diff) - } - }) + pod, dc, err := tc.opts.generatePodCopyWithDebugContainer(tc.copyPod) + if err != nil { + t.Fatalf("Fail to generate node debug pod: %v", err) + } + tc.expected.Spec.Containers[0].Name = dc + if diff := cmp.Diff(tc.expected, pod); diff != "" { + t.Error("unexpected diff in generated object: (-want +got):\n", diff) + } }) } } @@ -2510,31 +2504,29 @@ func TestGenerateEphemeralDebugPodCustomProfile(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { - cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) { - var err error - kflags := KeepFlags{ - Labels: tc.opts.KeepLabels, - Annotations: tc.opts.KeepAnnotations, - Liveness: tc.opts.KeepLiveness, - Readiness: tc.opts.KeepReadiness, - Startup: tc.opts.KeepStartup, - InitContainers: tc.opts.KeepInitContainers, - } - tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags) - if err != nil { - t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) - } - tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard() + var err error + kflags := KeepFlags{ + Labels: tc.opts.KeepLabels, + Annotations: tc.opts.KeepAnnotations, + Liveness: tc.opts.KeepLiveness, + Readiness: tc.opts.KeepReadiness, + Startup: tc.opts.KeepStartup, + InitContainers: tc.opts.KeepInitContainers, + } + tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags) + if err != nil { + t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err) + } + tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard() - pod, ec, err := tc.opts.generateDebugContainer(tc.copyPod) - if err != nil { - t.Fatalf("Fail to generate node debug pod: %v", err) - } - tc.expected.Spec.EphemeralContainers[0].Name = ec.Name - if diff := cmp.Diff(tc.expected, pod); diff != "" { - t.Error("unexpected diff in generated object: (-want +got):\n", diff) - } - }) + pod, ec, err := tc.opts.generateDebugContainer(tc.copyPod) + if err != nil { + t.Fatalf("Fail to generate node debug pod: %v", err) + } + tc.expected.Spec.EphemeralContainers[0].Name = ec.Name + if diff := cmp.Diff(tc.expected, pod); diff != "" { + t.Error("unexpected diff in generated object: (-want +got):\n", diff) + } }) } }