Fix attach command for InitContainers

This commit is contained in:
Sylwester Brzeczkowski
2016-06-24 14:35:02 +02:00
parent eedc438da9
commit a558cadedd
2 changed files with 22 additions and 2 deletions

View File

@@ -167,9 +167,11 @@ func (p *AttachOptions) Run() error {
if err != nil {
return err
}
if pod.Status.Phase != api.PodRunning {
return fmt.Errorf("pod %s is not running and cannot be attached to; current phase is %s", p.PodName, pod.Status.Phase)
if pod.Status.Phase == api.PodSucceeded || pod.Status.Phase == api.PodFailed {
return fmt.Errorf("cannot attach a container in a completed pod; current phase is %s", pod.Status.Phase)
}
p.Pod = pod
// TODO: convert this to a clean "wait" behavior
}
@@ -233,6 +235,11 @@ func (p *AttachOptions) GetContainer(pod *api.Pod) api.Container {
return container
}
}
for _, container := range pod.Spec.InitContainers {
if container.Name == p.ContainerName {
return container
}
}
}
glog.V(4).Infof("defaulting container name to %s", pod.Spec.Containers[0].Name)