Skip to content

Commit 4e650a9

Browse files
committed
Enable custom profiling in kubectl debug as default
1 parent e6d6416 commit 4e650a9

File tree

2 files changed

+67
-75
lines changed

2 files changed

+67
-75
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (o *DebugOptions) AddFlags(cmd *cobra.Command) {
211211
cmd.Flags().StringVar(&o.TargetContainer, "target", "", i18n.T("When using an ephemeral container, target processes in this container name."))
212212
cmd.Flags().BoolVarP(&o.TTY, "tty", "t", o.TTY, i18n.T("Allocate a TTY for the debugging container."))
213213
cmd.Flags().StringVar(&o.Profile, "profile", ProfileLegacy, i18n.T(`Options are "legacy", "general", "baseline", "netadmin", "restricted" or "sysadmin".`))
214-
if cmdutil.DebugCustomProfile.IsEnabled() {
214+
if !cmdutil.DebugCustomProfile.IsDisabled() {
215215
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."))
216216
}
217217
}

staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go

Lines changed: 66 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"testing"
2323
"time"
2424

25-
cmdutil "k8s.io/kubectl/pkg/cmd/util"
26-
2725
"github.com/google/go-cmp/cmp"
2826
"github.com/google/go-cmp/cmp/cmpopts"
2927
"github.com/spf13/cobra"
@@ -2088,31 +2086,29 @@ func TestGenerateNodeDebugPodCustomProfile(t *testing.T) {
20882086
} {
20892087

20902088
t.Run(tc.name, func(t *testing.T) {
2091-
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) {
2092-
var err error
2093-
kflags := KeepFlags{
2094-
Labels: tc.opts.KeepLabels,
2095-
Annotations: tc.opts.KeepAnnotations,
2096-
Liveness: tc.opts.KeepLiveness,
2097-
Readiness: tc.opts.KeepReadiness,
2098-
Startup: tc.opts.KeepStartup,
2099-
InitContainers: tc.opts.KeepInitContainers,
2100-
}
2101-
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
2102-
if err != nil {
2103-
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
2104-
}
2105-
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
2089+
var err error
2090+
kflags := KeepFlags{
2091+
Labels: tc.opts.KeepLabels,
2092+
Annotations: tc.opts.KeepAnnotations,
2093+
Liveness: tc.opts.KeepLiveness,
2094+
Readiness: tc.opts.KeepReadiness,
2095+
Startup: tc.opts.KeepStartup,
2096+
InitContainers: tc.opts.KeepInitContainers,
2097+
}
2098+
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
2099+
if err != nil {
2100+
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
2101+
}
2102+
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
21062103

2107-
pod, err := tc.opts.generateNodeDebugPod(tc.node)
2108-
if err != nil {
2109-
t.Fatalf("Fail to generate node debug pod: %v", err)
2110-
}
2111-
tc.expected.Name = pod.Name
2112-
if diff := cmp.Diff(tc.expected, pod); diff != "" {
2113-
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
2114-
}
2115-
})
2104+
pod, err := tc.opts.generateNodeDebugPod(tc.node)
2105+
if err != nil {
2106+
t.Fatalf("Fail to generate node debug pod: %v", err)
2107+
}
2108+
tc.expected.Name = pod.Name
2109+
if diff := cmp.Diff(tc.expected, pod); diff != "" {
2110+
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
2111+
}
21162112
})
21172113
}
21182114
}
@@ -2296,31 +2292,29 @@ func TestGenerateCopyDebugPodCustomProfile(t *testing.T) {
22962292
} {
22972293

22982294
t.Run(tc.name, func(t *testing.T) {
2299-
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) {
2300-
var err error
2301-
kflags := KeepFlags{
2302-
Labels: tc.opts.KeepLabels,
2303-
Annotations: tc.opts.KeepAnnotations,
2304-
Liveness: tc.opts.KeepLiveness,
2305-
Readiness: tc.opts.KeepReadiness,
2306-
Startup: tc.opts.KeepStartup,
2307-
InitContainers: tc.opts.KeepInitContainers,
2308-
}
2309-
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
2310-
if err != nil {
2311-
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
2312-
}
2313-
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
2295+
var err error
2296+
kflags := KeepFlags{
2297+
Labels: tc.opts.KeepLabels,
2298+
Annotations: tc.opts.KeepAnnotations,
2299+
Liveness: tc.opts.KeepLiveness,
2300+
Readiness: tc.opts.KeepReadiness,
2301+
Startup: tc.opts.KeepStartup,
2302+
InitContainers: tc.opts.KeepInitContainers,
2303+
}
2304+
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
2305+
if err != nil {
2306+
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
2307+
}
2308+
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
23142309

2315-
pod, dc, err := tc.opts.generatePodCopyWithDebugContainer(tc.copyPod)
2316-
if err != nil {
2317-
t.Fatalf("Fail to generate node debug pod: %v", err)
2318-
}
2319-
tc.expected.Spec.Containers[0].Name = dc
2320-
if diff := cmp.Diff(tc.expected, pod); diff != "" {
2321-
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
2322-
}
2323-
})
2310+
pod, dc, err := tc.opts.generatePodCopyWithDebugContainer(tc.copyPod)
2311+
if err != nil {
2312+
t.Fatalf("Fail to generate node debug pod: %v", err)
2313+
}
2314+
tc.expected.Spec.Containers[0].Name = dc
2315+
if diff := cmp.Diff(tc.expected, pod); diff != "" {
2316+
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
2317+
}
23242318
})
23252319
}
23262320
}
@@ -2510,31 +2504,29 @@ func TestGenerateEphemeralDebugPodCustomProfile(t *testing.T) {
25102504
} {
25112505

25122506
t.Run(tc.name, func(t *testing.T) {
2513-
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) {
2514-
var err error
2515-
kflags := KeepFlags{
2516-
Labels: tc.opts.KeepLabels,
2517-
Annotations: tc.opts.KeepAnnotations,
2518-
Liveness: tc.opts.KeepLiveness,
2519-
Readiness: tc.opts.KeepReadiness,
2520-
Startup: tc.opts.KeepStartup,
2521-
InitContainers: tc.opts.KeepInitContainers,
2522-
}
2523-
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
2524-
if err != nil {
2525-
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
2526-
}
2527-
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
2507+
var err error
2508+
kflags := KeepFlags{
2509+
Labels: tc.opts.KeepLabels,
2510+
Annotations: tc.opts.KeepAnnotations,
2511+
Liveness: tc.opts.KeepLiveness,
2512+
Readiness: tc.opts.KeepReadiness,
2513+
Startup: tc.opts.KeepStartup,
2514+
InitContainers: tc.opts.KeepInitContainers,
2515+
}
2516+
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
2517+
if err != nil {
2518+
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
2519+
}
2520+
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
25282521

2529-
pod, ec, err := tc.opts.generateDebugContainer(tc.copyPod)
2530-
if err != nil {
2531-
t.Fatalf("Fail to generate node debug pod: %v", err)
2532-
}
2533-
tc.expected.Spec.EphemeralContainers[0].Name = ec.Name
2534-
if diff := cmp.Diff(tc.expected, pod); diff != "" {
2535-
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
2536-
}
2537-
})
2522+
pod, ec, err := tc.opts.generateDebugContainer(tc.copyPod)
2523+
if err != nil {
2524+
t.Fatalf("Fail to generate node debug pod: %v", err)
2525+
}
2526+
tc.expected.Spec.EphemeralContainers[0].Name = ec.Name
2527+
if diff := cmp.Diff(tc.expected, pod); diff != "" {
2528+
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
2529+
}
25382530
})
25392531
}
25402532
}

0 commit comments

Comments
 (0)