mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Enable custom profiling in kubectl debug as default
This commit is contained in:
parent
e6d641651a
commit
4e650a9954
@ -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().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().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".`))
|
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."))
|
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."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -2088,31 +2086,29 @@ func TestGenerateNodeDebugPodCustomProfile(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
|
|
||||||
t.Run(tc.name, func(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
|
||||||
var err error
|
kflags := KeepFlags{
|
||||||
kflags := KeepFlags{
|
Labels: tc.opts.KeepLabels,
|
||||||
Labels: tc.opts.KeepLabels,
|
Annotations: tc.opts.KeepAnnotations,
|
||||||
Annotations: tc.opts.KeepAnnotations,
|
Liveness: tc.opts.KeepLiveness,
|
||||||
Liveness: tc.opts.KeepLiveness,
|
Readiness: tc.opts.KeepReadiness,
|
||||||
Readiness: tc.opts.KeepReadiness,
|
Startup: tc.opts.KeepStartup,
|
||||||
Startup: tc.opts.KeepStartup,
|
InitContainers: tc.opts.KeepInitContainers,
|
||||||
InitContainers: tc.opts.KeepInitContainers,
|
}
|
||||||
}
|
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
|
||||||
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
|
if err != nil {
|
||||||
if err != nil {
|
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
|
||||||
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
|
}
|
||||||
}
|
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
|
||||||
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
|
|
||||||
|
|
||||||
pod, err := tc.opts.generateNodeDebugPod(tc.node)
|
pod, err := tc.opts.generateNodeDebugPod(tc.node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Fail to generate node debug pod: %v", err)
|
t.Fatalf("Fail to generate node debug pod: %v", err)
|
||||||
}
|
}
|
||||||
tc.expected.Name = pod.Name
|
tc.expected.Name = pod.Name
|
||||||
if diff := cmp.Diff(tc.expected, pod); diff != "" {
|
if diff := cmp.Diff(tc.expected, pod); diff != "" {
|
||||||
t.Error("unexpected diff in generated object: (-want +got):\n", 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) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) {
|
var err error
|
||||||
var err error
|
kflags := KeepFlags{
|
||||||
kflags := KeepFlags{
|
Labels: tc.opts.KeepLabels,
|
||||||
Labels: tc.opts.KeepLabels,
|
Annotations: tc.opts.KeepAnnotations,
|
||||||
Annotations: tc.opts.KeepAnnotations,
|
Liveness: tc.opts.KeepLiveness,
|
||||||
Liveness: tc.opts.KeepLiveness,
|
Readiness: tc.opts.KeepReadiness,
|
||||||
Readiness: tc.opts.KeepReadiness,
|
Startup: tc.opts.KeepStartup,
|
||||||
Startup: tc.opts.KeepStartup,
|
InitContainers: tc.opts.KeepInitContainers,
|
||||||
InitContainers: tc.opts.KeepInitContainers,
|
}
|
||||||
}
|
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
|
||||||
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
|
if err != nil {
|
||||||
if err != nil {
|
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
|
||||||
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
|
}
|
||||||
}
|
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
|
||||||
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
|
|
||||||
|
|
||||||
pod, dc, err := tc.opts.generatePodCopyWithDebugContainer(tc.copyPod)
|
pod, dc, err := tc.opts.generatePodCopyWithDebugContainer(tc.copyPod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Fail to generate node debug pod: %v", err)
|
t.Fatalf("Fail to generate node debug pod: %v", err)
|
||||||
}
|
}
|
||||||
tc.expected.Spec.Containers[0].Name = dc
|
tc.expected.Spec.Containers[0].Name = dc
|
||||||
if diff := cmp.Diff(tc.expected, pod); diff != "" {
|
if diff := cmp.Diff(tc.expected, pod); diff != "" {
|
||||||
t.Error("unexpected diff in generated object: (-want +got):\n", 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) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
cmdtesting.WithAlphaEnvs([]cmdutil.FeatureGate{cmdutil.DebugCustomProfile}, t, func(t *testing.T) {
|
var err error
|
||||||
var err error
|
kflags := KeepFlags{
|
||||||
kflags := KeepFlags{
|
Labels: tc.opts.KeepLabels,
|
||||||
Labels: tc.opts.KeepLabels,
|
Annotations: tc.opts.KeepAnnotations,
|
||||||
Annotations: tc.opts.KeepAnnotations,
|
Liveness: tc.opts.KeepLiveness,
|
||||||
Liveness: tc.opts.KeepLiveness,
|
Readiness: tc.opts.KeepReadiness,
|
||||||
Readiness: tc.opts.KeepReadiness,
|
Startup: tc.opts.KeepStartup,
|
||||||
Startup: tc.opts.KeepStartup,
|
InitContainers: tc.opts.KeepInitContainers,
|
||||||
InitContainers: tc.opts.KeepInitContainers,
|
}
|
||||||
}
|
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
|
||||||
tc.opts.Applier, err = NewProfileApplier(tc.opts.Profile, kflags)
|
if err != nil {
|
||||||
if err != nil {
|
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
|
||||||
t.Fatalf("Fail to create profile applier: %s: %v", tc.opts.Profile, err)
|
}
|
||||||
}
|
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
|
||||||
tc.opts.IOStreams = genericiooptions.NewTestIOStreamsDiscard()
|
|
||||||
|
|
||||||
pod, ec, err := tc.opts.generateDebugContainer(tc.copyPod)
|
pod, ec, err := tc.opts.generateDebugContainer(tc.copyPod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Fail to generate node debug pod: %v", err)
|
t.Fatalf("Fail to generate node debug pod: %v", err)
|
||||||
}
|
}
|
||||||
tc.expected.Spec.EphemeralContainers[0].Name = ec.Name
|
tc.expected.Spec.EphemeralContainers[0].Name = ec.Name
|
||||||
if diff := cmp.Diff(tc.expected, pod); diff != "" {
|
if diff := cmp.Diff(tc.expected, pod); diff != "" {
|
||||||
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
|
t.Error("unexpected diff in generated object: (-want +got):\n", diff)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user