mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Merge pull request #28012 from sttts/sttts-kubectl-attach-err-non-existing-ctr
Automatic merge from submit-queue kubectl attach: error out for non-existing containers Currently, kubectl attach falls back to the first container which is pretty confusing. Based on https://github.com/kubernetes/kubernetes/pull/27541.
This commit is contained in:
@@ -335,8 +335,12 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, pod *api.Pod, opts *A
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctrName, err := opts.GetContainerName(pod)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status == api.PodSucceeded || status == api.PodFailed {
|
||||
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: opts.GetContainerName(pod)})
|
||||
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: ctrName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -353,7 +357,7 @@ func handleAttachPod(f *cmdutil.Factory, c *client.Client, pod *api.Pod, opts *A
|
||||
opts.Namespace = pod.Namespace
|
||||
if err := opts.Run(); err != nil {
|
||||
fmt.Fprintf(opts.Out, "Error attaching, falling back to logs: %v\n", err)
|
||||
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: opts.GetContainerName(pod)})
|
||||
req, err := f.LogsForObject(pod, &api.PodLogOptions{Container: ctrName})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user