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)