From 30262e9b14e2369528fd27241adb16fae02f684d Mon Sep 17 00:00:00 2001 From: Lee Verberne Date: Wed, 4 Nov 2020 16:30:49 +0100 Subject: [PATCH] Remove alpha from kubectl debug --- pkg/kubectl/cmd/BUILD | 1 + pkg/kubectl/cmd/cmd.go | 2 ++ staging/src/k8s.io/kubectl/pkg/cmd/alpha.go | 2 +- .../src/k8s.io/kubectl/pkg/cmd/debug/debug.go | 30 ++++++++++++++----- test/cmd/debug.sh | 8 ++--- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/pkg/kubectl/cmd/BUILD b/pkg/kubectl/cmd/BUILD index e41c04662df..6689b6bb040 100644 --- a/pkg/kubectl/cmd/BUILD +++ b/pkg/kubectl/cmd/BUILD @@ -27,6 +27,7 @@ go_library( "//staging/src/k8s.io/kubectl/pkg/cmd/config:go_default_library", "//staging/src/k8s.io/kubectl/pkg/cmd/cp:go_default_library", "//staging/src/k8s.io/kubectl/pkg/cmd/create:go_default_library", + "//staging/src/k8s.io/kubectl/pkg/cmd/debug:go_default_library", "//staging/src/k8s.io/kubectl/pkg/cmd/delete:go_default_library", "//staging/src/k8s.io/kubectl/pkg/cmd/describe:go_default_library", "//staging/src/k8s.io/kubectl/pkg/cmd/diff:go_default_library", diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index 2e8dc6f84b8..234c5c6bab5 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -44,6 +44,7 @@ import ( cmdconfig "k8s.io/kubectl/pkg/cmd/config" "k8s.io/kubectl/pkg/cmd/cp" "k8s.io/kubectl/pkg/cmd/create" + "k8s.io/kubectl/pkg/cmd/debug" "k8s.io/kubectl/pkg/cmd/delete" "k8s.io/kubectl/pkg/cmd/describe" "k8s.io/kubectl/pkg/cmd/diff" @@ -555,6 +556,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command { proxy.NewCmdProxy(f, ioStreams), cp.NewCmdCp(f, ioStreams), auth.NewCmdAuth(f, ioStreams), + debug.NewCmdDebug(f, ioStreams, false), }, }, { diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/alpha.go b/staging/src/k8s.io/kubectl/pkg/cmd/alpha.go index 38f7fd4dd86..b5ec27bc346 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/alpha.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/alpha.go @@ -36,7 +36,7 @@ func NewCmdAlpha(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra. // Alpha commands should be added here. As features graduate from alpha they should move // from here to the CommandGroups defined by NewKubeletCommand() in cmd.go. - cmd.AddCommand(debug.NewCmdDebug(f, streams)) + cmd.AddCommand(debug.NewCmdDebug(f, streams, true)) // NewKubeletCommand() will hide the alpha command if it has no subcommands. Overriding // the help function ensures a reasonable message if someone types the hidden command anyway. 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 d6009c9084a..4f5d66de9f1 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go @@ -71,28 +71,31 @@ var ( debugExample = templates.Examples(i18n.T(` # Create an interactive debugging session in pod mypod and immediately attach to it. # (requires the EphemeralContainers feature to be enabled in the cluster) - kubectl alpha debug mypod -it --image=busybox + kubectl debug mypod -it --image=busybox # Create a debug container named debugger using a custom automated debugging image. # (requires the EphemeralContainers feature to be enabled in the cluster) - kubectl alpha debug --image=myproj/debug-tools -c debugger mypod + kubectl debug --image=myproj/debug-tools -c debugger mypod # Create a copy of mypod adding a debug container and attach to it - kubectl alpha debug mypod -it --image=busybox --copy-to=my-debugger + kubectl debug mypod -it --image=busybox --copy-to=my-debugger # Create a copy of mypod changing the command of mycontainer - kubectl alpha debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh + kubectl debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh # Create a copy of mypod changing all container images to busybox - kubectl alpha debug mypod --copy-to=my-debugger --set-image=*=busybox + kubectl debug mypod --copy-to=my-debugger --set-image=*=busybox # Create a copy of mypod adding a debug container and changing container images - kubectl alpha debug mypod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,sidecar=sidecar:debug + kubectl debug mypod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,sidecar=sidecar:debug # Create an interactive debugging session on a node and immediately attach to it. # The container will run in the host namespaces and the host's filesystem will be mounted at /host - kubectl alpha debug node/mynode -it --image=busybox + kubectl debug node/mynode -it --image=busybox `)) + + // TODO(verb): Remove deprecated alpha invocation in 1.21 + deprecationNotice = i18n.T(`NOTE: "kubectl alpha debug" is deprecated and will be removed in release 1.21. Please use "kubectl debug" instead.`) ) var nameSuffixFunc = utilrand.String @@ -118,6 +121,7 @@ type DebugOptions struct { TargetContainer string TTY bool + deprecatedInvocation bool shareProcessedChanged bool podClient corev1client.PodsGetter @@ -136,7 +140,7 @@ func NewDebugOptions(streams genericclioptions.IOStreams) *DebugOptions { } // NewCmdDebug returns a cobra command that runs kubectl debug. -func NewCmdDebug(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { +func NewCmdDebug(f cmdutil.Factory, streams genericclioptions.IOStreams, deprecatedInvocation bool) *cobra.Command { o := NewDebugOptions(streams) cmd := &cobra.Command{ @@ -150,6 +154,12 @@ func NewCmdDebug(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra. cmdutil.CheckErr(o.Validate(cmd)) cmdutil.CheckErr(o.Run(f, cmd)) }, + Hidden: deprecatedInvocation, + } + + o.deprecatedInvocation = deprecatedInvocation + if deprecatedInvocation { + cmd.Long = fmt.Sprintf("%s\n\n%s", deprecationNotice, debugLong) } addDebugFlags(cmd, o) @@ -178,6 +188,10 @@ func addDebugFlags(cmd *cobra.Command, opt *DebugOptions) { func (o *DebugOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error { var err error + if o.deprecatedInvocation { + cmd.Printf("%s\n\n", deprecationNotice) + } + o.PullPolicy = corev1.PullPolicy(cmdutil.GetFlagString(cmd, "image-pull-policy")) // Arguments diff --git a/test/cmd/debug.sh b/test/cmd/debug.sh index a30f62aea51..61300603784 100755 --- a/test/cmd/debug.sh +++ b/test/cmd/debug.sh @@ -31,7 +31,7 @@ run_kubectl_debug_pod_tests() { kubectl run target "--image=${IMAGE_NGINX:?}" "${kube_flags[@]:?}" kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:' # Command: create a copy of target with a new debug container - kubectl alpha debug target -it --copy-to=target-copy --image=busybox --container=debug-container --attach=false "${kube_flags[@]:?}" + kubectl debug target -it --copy-to=target-copy --image=busybox --container=debug-container --attach=false "${kube_flags[@]:?}" # Post-Conditions kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:target-copy:' kube::test::get_object_assert pod/target-copy '{{range.spec.containers}}{{.name}}:{{end}}' 'target:debug-container:' @@ -43,7 +43,7 @@ run_kubectl_debug_pod_tests() { kubectl run target "--image=${IMAGE_NGINX:?}" "${kube_flags[@]:?}" kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:' # Command: create a copy of target with a new debug container replacing the previous pod - kubectl alpha debug target -it --copy-to=target-copy --image=busybox --container=debug-container --attach=false --replace "${kube_flags[@]:?}" + kubectl debug target -it --copy-to=target-copy --image=busybox --container=debug-container --attach=false --replace "${kube_flags[@]:?}" # Post-Conditions kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target-copy:' kube::test::get_object_assert pod/target-copy '{{range.spec.containers}}{{.name}}:{{end}}' 'target:debug-container:' @@ -56,7 +56,7 @@ run_kubectl_debug_pod_tests() { kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:' kube::test::get_object_assert pod/target '{{(index .spec.containers 0).name}}' 'target' # Command: copy the pod and replace the image of an existing container - kubectl alpha debug target --image=busybox --container=target --copy-to=target-copy "${kube_flags[@]:?}" -- sleep 1m + kubectl debug target --image=busybox --container=target --copy-to=target-copy "${kube_flags[@]:?}" -- sleep 1m # Post-Conditions kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:target-copy:' kube::test::get_object_assert pod/target-copy "{{(len .spec.containers)}}:{{${image_field:?}}}" '1:busybox' @@ -79,7 +79,7 @@ run_kubectl_debug_node_tests() { # Pre-Condition: Pod "nginx" is created kube::test::get_object_assert nodes "{{range.items}}{{${id_field:?}}}:{{end}}" '127.0.0.1:' # Command: create a new node debugger pod - output_message=$(kubectl alpha debug node/127.0.0.1 --image=busybox --attach=false "${kube_flags[@]:?}" -- true) + output_message=$(kubectl debug node/127.0.0.1 --image=busybox --attach=false "${kube_flags[@]:?}" -- true) # Post-Conditions kube::test::get_object_assert pod "{{(len .items)}}" '1' debugger=$(kubectl get pod -o go-template="{{(index .items 0)${id_field:?}}}")