mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Merge pull request #96138 from verb/1.20-cli-debug-unalpha
Remove alpha from kubectl debug command invocation
This commit is contained in:
commit
468f9f6cac
@ -27,6 +27,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/kubectl/pkg/cmd/config:go_default_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/cp:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/cmd/create: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/delete:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/cmd/describe: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",
|
"//staging/src/k8s.io/kubectl/pkg/cmd/diff:go_default_library",
|
||||||
|
@ -44,6 +44,7 @@ import (
|
|||||||
cmdconfig "k8s.io/kubectl/pkg/cmd/config"
|
cmdconfig "k8s.io/kubectl/pkg/cmd/config"
|
||||||
"k8s.io/kubectl/pkg/cmd/cp"
|
"k8s.io/kubectl/pkg/cmd/cp"
|
||||||
"k8s.io/kubectl/pkg/cmd/create"
|
"k8s.io/kubectl/pkg/cmd/create"
|
||||||
|
"k8s.io/kubectl/pkg/cmd/debug"
|
||||||
"k8s.io/kubectl/pkg/cmd/delete"
|
"k8s.io/kubectl/pkg/cmd/delete"
|
||||||
"k8s.io/kubectl/pkg/cmd/describe"
|
"k8s.io/kubectl/pkg/cmd/describe"
|
||||||
"k8s.io/kubectl/pkg/cmd/diff"
|
"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),
|
proxy.NewCmdProxy(f, ioStreams),
|
||||||
cp.NewCmdCp(f, ioStreams),
|
cp.NewCmdCp(f, ioStreams),
|
||||||
auth.NewCmdAuth(f, ioStreams),
|
auth.NewCmdAuth(f, ioStreams),
|
||||||
|
debug.NewCmdDebug(f, ioStreams, false),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -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
|
// 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.
|
// 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
|
// 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.
|
// the help function ensures a reasonable message if someone types the hidden command anyway.
|
||||||
|
@ -71,28 +71,31 @@ var (
|
|||||||
debugExample = templates.Examples(i18n.T(`
|
debugExample = templates.Examples(i18n.T(`
|
||||||
# Create an interactive debugging session in pod mypod and immediately attach to it.
|
# Create an interactive debugging session in pod mypod and immediately attach to it.
|
||||||
# (requires the EphemeralContainers feature to be enabled in the cluster)
|
# (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.
|
# Create a debug container named debugger using a custom automated debugging image.
|
||||||
# (requires the EphemeralContainers feature to be enabled in the cluster)
|
# (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
|
# 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
|
# 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
|
# 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
|
# 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.
|
# 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
|
# 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
|
var nameSuffixFunc = utilrand.String
|
||||||
@ -118,6 +121,7 @@ type DebugOptions struct {
|
|||||||
TargetContainer string
|
TargetContainer string
|
||||||
TTY bool
|
TTY bool
|
||||||
|
|
||||||
|
deprecatedInvocation bool
|
||||||
shareProcessedChanged bool
|
shareProcessedChanged bool
|
||||||
|
|
||||||
podClient corev1client.PodsGetter
|
podClient corev1client.PodsGetter
|
||||||
@ -136,7 +140,7 @@ func NewDebugOptions(streams genericclioptions.IOStreams) *DebugOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdDebug returns a cobra command that runs kubectl debug.
|
// 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)
|
o := NewDebugOptions(streams)
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -150,6 +154,12 @@ func NewCmdDebug(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.
|
|||||||
cmdutil.CheckErr(o.Validate(cmd))
|
cmdutil.CheckErr(o.Validate(cmd))
|
||||||
cmdutil.CheckErr(o.Run(f, 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)
|
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 {
|
func (o *DebugOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
if o.deprecatedInvocation {
|
||||||
|
cmd.Printf("%s\n\n", deprecationNotice)
|
||||||
|
}
|
||||||
|
|
||||||
o.PullPolicy = corev1.PullPolicy(cmdutil.GetFlagString(cmd, "image-pull-policy"))
|
o.PullPolicy = corev1.PullPolicy(cmdutil.GetFlagString(cmd, "image-pull-policy"))
|
||||||
|
|
||||||
// Arguments
|
// Arguments
|
||||||
|
@ -31,7 +31,7 @@ run_kubectl_debug_pod_tests() {
|
|||||||
kubectl run target "--image=${IMAGE_NGINX:?}" "${kube_flags[@]:?}"
|
kubectl run target "--image=${IMAGE_NGINX:?}" "${kube_flags[@]:?}"
|
||||||
kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:'
|
kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:'
|
||||||
# Command: create a copy of target with a new debug container
|
# 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
|
# Post-Conditions
|
||||||
kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:target-copy:'
|
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:'
|
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[@]:?}"
|
kubectl run target "--image=${IMAGE_NGINX:?}" "${kube_flags[@]:?}"
|
||||||
kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:'
|
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
|
# 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
|
# Post-Conditions
|
||||||
kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target-copy:'
|
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:'
|
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 "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:'
|
||||||
kube::test::get_object_assert pod/target '{{(index .spec.containers 0).name}}' '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
|
# 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
|
# Post-Conditions
|
||||||
kube::test::get_object_assert pod "{{range.items}}{{${id_field:?}}}:{{end}}" 'target:target-copy:'
|
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'
|
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
|
# Pre-Condition: Pod "nginx" is created
|
||||||
kube::test::get_object_assert nodes "{{range.items}}{{${id_field:?}}}:{{end}}" '127.0.0.1:'
|
kube::test::get_object_assert nodes "{{range.items}}{{${id_field:?}}}:{{end}}" '127.0.0.1:'
|
||||||
# Command: create a new node debugger pod
|
# 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
|
# Post-Conditions
|
||||||
kube::test::get_object_assert pod "{{(len .items)}}" '1'
|
kube::test::get_object_assert pod "{{(len .items)}}" '1'
|
||||||
debugger=$(kubectl get pod -o go-template="{{(index .items 0)${id_field:?}}}")
|
debugger=$(kubectl get pod -o go-template="{{(index .items 0)${id_field:?}}}")
|
||||||
|
Loading…
Reference in New Issue
Block a user