Fix race condition in kubectl run --attach

This commit is contained in:
Tim St. Clair
2015-09-29 12:43:15 -07:00
parent c317020922
commit 4dc9df91d8
2 changed files with 17 additions and 9 deletions

View File

@@ -291,12 +291,16 @@ func handleAttachPod(c *client.Client, pod *api.Pod, opts *AttachOptions) error
return err
}
if status == api.PodSucceeded || status == api.PodFailed {
return handleLog(c, pod.Namespace, pod.Name, &api.PodLogOptions{Container: pod.Spec.Containers[0].Name}, opts.Out)
return handleLog(c, pod.Namespace, pod.Name, &api.PodLogOptions{Container: opts.GetContainerName(pod)}, opts.Out)
}
opts.Client = c
opts.PodName = pod.Name
opts.Namespace = pod.Namespace
return opts.Run()
if err := opts.Run(); err != nil {
fmt.Fprintf(opts.Out, "Error attaching, falling back to logs: %v\n", err)
return handleLog(c, pod.Namespace, pod.Name, &api.PodLogOptions{Container: opts.GetContainerName(pod)}, opts.Out)
}
return nil
}
func getRestartPolicy(cmd *cobra.Command, interactive bool) (api.RestartPolicy, error) {