Skip to content

Commit 16e8ddb

Browse files
authored
Support debugging for init container (#15)
* Support debugging for init container Signed-off-by: Yeh-lei Wu <rayingecho@gmail.com> * Correct comments Signed-off-by: Yeh-lei Wu <rayingecho@gmail.com>
1 parent 84ba4a6 commit 16e8ddb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/plugin/cmd.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,22 @@ func (o *DebugOptions) getContainerIdByName(pod *corev1.Pod, containerName strin
304304
continue
305305
}
306306
if !containerStatus.Ready {
307-
return "", fmt.Errorf("container %s id not ready", containerName)
307+
return "", fmt.Errorf("container [%s] not ready", containerName)
308308
}
309309
return containerStatus.ContainerID, nil
310310
}
311+
312+
// #14 otherwise we should search for running init containers
313+
for _, initContainerStatus := range pod.Status.InitContainerStatuses {
314+
if initContainerStatus.Name != containerName {
315+
continue
316+
}
317+
if initContainerStatus.State.Running == nil {
318+
return "", fmt.Errorf("init container [%s] is not running", containerName)
319+
}
320+
return initContainerStatus.ContainerID, nil
321+
}
322+
311323
return "", fmt.Errorf("cannot find specified container %s", containerName)
312324
}
313325

0 commit comments

Comments
 (0)