Skip to content

Commit 198a4d8

Browse files
Debug should be able to skip init containers
1 parent f33cbc6 commit 198a4d8

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

pkg/cmd/cli/cmd/debug.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ type DebugOptions struct {
4242
Filename string
4343
Timeout time.Duration
4444

45-
Command []string
46-
Annotations map[string]string
47-
AsRoot bool
48-
AsNonRoot bool
49-
AsUser int64
50-
KeepLabels bool // TODO: evaluate selecting the right labels automatically
51-
KeepAnnotations bool
52-
KeepLiveness bool
53-
KeepReadiness bool
54-
OneContainer bool
55-
NodeName string
56-
AddEnv []kapi.EnvVar
57-
RemoveEnv []string
45+
Command []string
46+
Annotations map[string]string
47+
AsRoot bool
48+
AsNonRoot bool
49+
AsUser int64
50+
KeepLabels bool // TODO: evaluate selecting the right labels automatically
51+
KeepAnnotations bool
52+
KeepLiveness bool
53+
KeepReadiness bool
54+
KeepInitContainers bool
55+
OneContainer bool
56+
NodeName string
57+
AddEnv []kapi.EnvVar
58+
RemoveEnv []string
5859
}
5960

6061
const (
@@ -146,6 +147,7 @@ func NewCmdDebug(fullName string, f *clientcmd.Factory, in io.Reader, out, errou
146147
cmd.Flags().StringVarP(&options.Attach.ContainerName, "container", "c", "", "Container name; defaults to first container")
147148
cmd.Flags().BoolVar(&options.KeepAnnotations, "keep-annotations", false, "Keep the original pod annotations")
148149
cmd.Flags().BoolVar(&options.KeepLiveness, "keep-liveness", false, "Keep the original pod liveness probes")
150+
cmd.Flags().BoolVar(&options.KeepInitContainers, "keep-init-containers", true, "Run the init containers for the pod. Defaults to true.")
149151
cmd.Flags().BoolVar(&options.KeepReadiness, "keep-readiness", false, "Keep the original pod readiness probes")
150152
cmd.Flags().BoolVar(&options.OneContainer, "one-container", false, "Run only the selected container, remove all others")
151153
cmd.Flags().StringVar(&options.NodeName, "node-name", "", "Set a specific node to run on - by default the pod will run on any valid node")
@@ -379,6 +381,10 @@ func (o *DebugOptions) Debug() error {
379381
func (o *DebugOptions) transformPodForDebug(annotations map[string]string) (*kapi.Pod, []string) {
380382
pod := o.Attach.Pod
381383

384+
if !o.KeepInitContainers {
385+
pod.Spec.InitContainers = nil
386+
}
387+
382388
// reset the container
383389
container := containerForName(pod, o.Attach.ContainerName)
384390

0 commit comments

Comments
 (0)