mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
Fix attach command for InitContainers
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user