Merge pull request #96138 from verb/1.20-cli-debug-unalpha

Remove alpha from kubectl debug command invocation
This commit is contained in:
Kubernetes Prow Robot 2020-11-04 14:47:07 -08:00 committed by GitHub
commit 468f9f6cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 13 deletions

View File

@ -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",

View File

@ -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),
},
},
{

View File

@ -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.

View File

@ -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

View File

@ -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:?}}}")