From a691d93fd81cabbdff171126245554e92ca8b5f0 Mon Sep 17 00:00:00 2001 From: 0x5457 <0x5457@protonmail.com> Date: Fri, 19 Dec 2025 00:01:10 +0800 Subject: [PATCH] Fix missing namespace flag in attach reattach message Kubernetes-commit: c7ba4bbcf86cb6d520348e02a0ac4af5d7622501 --- pkg/cmd/attach/attach.go | 4 ++-- pkg/cmd/attach/attach_test.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/attach/attach.go b/pkg/cmd/attach/attach.go index 62b1f6411..17fa740ee 100644 --- a/pkg/cmd/attach/attach.go +++ b/pkg/cmd/attach/attach.go @@ -356,9 +356,9 @@ func (o *AttachOptions) reattachMessage(containerName string, rawTTY bool) strin return "" } if _, path := podcmd.FindContainerByName(o.Pod, containerName); strings.HasPrefix(path, "spec.ephemeralContainers") { - return fmt.Sprintf("Session ended, the ephemeral container will not be restarted but may be reattached using '%s %s -c %s -i -t' if it is still running", o.CommandName, o.Pod.Name, containerName) + return fmt.Sprintf("Session ended, the ephemeral container will not be restarted but may be reattached using '%s %s -c %s -n %s -i -t' if it is still running", o.CommandName, o.Pod.Name, containerName, o.Pod.Namespace) } - return fmt.Sprintf("Session ended, resume using '%s %s -c %s -i -t' command when the pod is running", o.CommandName, o.Pod.Name, containerName) + return fmt.Sprintf("Session ended, resume using '%s %s -c %s -n %s -i -t' command when the pod is running", o.CommandName, o.Pod.Name, containerName, o.Pod.Namespace) } type terminalSizeQueueAdapter struct { diff --git a/pkg/cmd/attach/attach_test.go b/pkg/cmd/attach/attach_test.go index 6a599656e..4c3a27a34 100644 --- a/pkg/cmd/attach/attach_test.go +++ b/pkg/cmd/attach/attach_test.go @@ -510,7 +510,7 @@ func TestReattachMessage(t *testing.T) { container: "bar", rawTTY: true, stdin: true, - expected: "Session ended, resume using", + expected: "Session ended, resume using 'kubectl foo -c bar -n test -i -t' command when the pod is running", }, { name: "no stdin", @@ -549,7 +549,7 @@ func TestReattachMessage(t *testing.T) { container: "debugger", rawTTY: true, stdin: true, - expected: "Session ended, the ephemeral container will not be restarted", + expected: "Session ended, the ephemeral container will not be restarted but may be reattached using 'kubectl foo -c debugger -n test -i -t' if it is still running", }, } for _, test := range tests { @@ -558,7 +558,8 @@ func TestReattachMessage(t *testing.T) { StreamOptions: exec.StreamOptions{ Stdin: test.stdin, }, - Pod: test.pod, + CommandName: "kubectl", + Pod: test.pod, } if msg := options.reattachMessage(test.container, test.rawTTY); test.expected == "" && msg != "" { t.Errorf("reattachMessage(%v, %v) = %q, want empty string", test.container, test.rawTTY, msg)