@@ -42,19 +42,20 @@ type DebugOptions struct {
42
42
Filename string
43
43
Timeout time.Duration
44
44
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
58
59
}
59
60
60
61
const (
@@ -146,6 +147,7 @@ func NewCmdDebug(fullName string, f *clientcmd.Factory, in io.Reader, out, errou
146
147
cmd .Flags ().StringVarP (& options .Attach .ContainerName , "container" , "c" , "" , "Container name; defaults to first container" )
147
148
cmd .Flags ().BoolVar (& options .KeepAnnotations , "keep-annotations" , false , "Keep the original pod annotations" )
148
149
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." )
149
151
cmd .Flags ().BoolVar (& options .KeepReadiness , "keep-readiness" , false , "Keep the original pod readiness probes" )
150
152
cmd .Flags ().BoolVar (& options .OneContainer , "one-container" , false , "Run only the selected container, remove all others" )
151
153
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 {
379
381
func (o * DebugOptions ) transformPodForDebug (annotations map [string ]string ) (* kapi.Pod , []string ) {
380
382
pod := o .Attach .Pod
381
383
384
+ if ! o .KeepInitContainers {
385
+ pod .Spec .InitContainers = nil
386
+ }
387
+
382
388
// reset the container
383
389
container := containerForName (pod , o .Attach .ContainerName )
384
390
0 commit comments