Merge pull request #135790 from 0x5457/fix/attach-reattach-message-missing-namespace

Fix missing namespace flag in attach reattach message

Kubernetes-commit: c04907b02556add29458563b181d66aed6a11a51
This commit is contained in:
Kubernetes Publisher 2026-01-30 23:36:31 +05:30
commit 3c2d5800e1
2 changed files with 6 additions and 5 deletions

View file

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

View file

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