Error out on non-existing container in kubectl attach

This commit is contained in:
Dr. Stefan Schimanski
2016-06-24 13:05:59 +02:00
parent f3359fe134
commit 0acca44dc1
3 changed files with 70 additions and 38 deletions

View File

@@ -332,8 +332,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
}
@@ -350,7 +354,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
}