From 968185e1f7c4aee739d5abe6133a690c70e87d5e Mon Sep 17 00:00:00 2001 From: Lee Verberne Date: Tue, 13 Apr 2021 15:50:26 +0200 Subject: [PATCH] Warn user for runtime support of debug targeting Add a warning message to `kubectl debug` when using the `--target` option as many runtimes don't support it yet. --- staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 abcb2530468..4f7714f4ff3 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug.go @@ -272,8 +272,17 @@ func (o *DebugOptions) Validate(cmd *cobra.Command) error { } // TargetContainer - if len(o.TargetContainer) > 0 && len(o.CopyTo) > 0 { - return fmt.Errorf("--target is incompatible with --copy-to. Use --share-processes instead.") + if len(o.TargetContainer) > 0 { + if len(o.CopyTo) > 0 { + return fmt.Errorf("--target is incompatible with --copy-to. Use --share-processes instead.") + } + if !o.Quiet { + // If the runtime doesn't support container namespace targeting this will fail silently, which has caused + // some confusion (ex: https://issues.k8s.io/98362), so print a warning. This can be removed when + // EphemeralContainers are generally available. + fmt.Fprintf(o.Out, "Targeting container %q. If you don't see processes from this container it may be because the container runtime doesn't support this feature.\n", o.TargetContainer) + // TODO(verb): Add a list of supported container runtimes to https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/ and then link here. + } } // TTY