@@ -341,12 +341,23 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
341
341
podCopy := * test .Resource .PodSpec
342
342
podCopy .InitContainers = []corev1.Container {}
343
343
podCopy .Containers = []corev1.Container {* test .Container }
344
- containerIndex := funk .IndexOf (test .Resource .PodSpec .Containers , func (value corev1.Container ) bool {
345
- return value .Name == test .Container .Name
346
- })
344
+ containerIndex := - 1
345
+ if ! test .IsInitContainer {
346
+ containerIndex = funk .IndexOf (test .Resource .PodSpec .Containers , func (value corev1.Container ) bool {
347
+ return value .Name == test .Container .Name
348
+ })
349
+ } else {
350
+ containerIndex = funk .IndexOf (test .Resource .PodSpec .InitContainers , func (value corev1.Container ) bool {
351
+ return value .Name == test .Container .Name
352
+ })
353
+ }
347
354
prefix = getJSONSchemaPrefix (test .Resource .Kind )
348
355
if prefix != "" {
349
- prefix += "/containers/" + strconv .Itoa (containerIndex )
356
+ if test .IsInitContainer {
357
+ prefix += "/initContainers/" + strconv .Itoa (containerIndex )
358
+ } else {
359
+ prefix += "/containers/" + strconv .Itoa (containerIndex )
360
+ }
350
361
}
351
362
passes , issues , err = check .CheckPodSpec (& podCopy )
352
363
} else {
@@ -359,12 +370,23 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
359
370
passes , issues , err = check .CheckPodTemplate (test .Resource .PodTemplate )
360
371
prefix = getJSONSchemaPrefix (test .Resource .Kind )
361
372
} else if check .Target == config .TargetContainer {
362
- containerIndex := funk .IndexOf (test .Resource .PodSpec .Containers , func (value corev1.Container ) bool {
363
- return value .Name == test .Container .Name
364
- })
373
+ containerIndex := - 1
374
+ if ! test .IsInitContainer {
375
+ containerIndex = funk .IndexOf (test .Resource .PodSpec .Containers , func (value corev1.Container ) bool {
376
+ return value .Name == test .Container .Name
377
+ })
378
+ } else {
379
+ containerIndex = funk .IndexOf (test .Resource .PodSpec .InitContainers , func (value corev1.Container ) bool {
380
+ return value .Name == test .Container .Name
381
+ })
382
+ }
365
383
prefix = getJSONSchemaPrefix (test .Resource .Kind )
366
384
if prefix != "" {
367
- prefix += "/containers/" + strconv .Itoa (containerIndex )
385
+ if test .IsInitContainer {
386
+ prefix += "/initContainers/" + strconv .Itoa (containerIndex )
387
+ } else {
388
+ prefix += "/containers/" + strconv .Itoa (containerIndex )
389
+ }
368
390
}
369
391
passes , issues , err = check .CheckContainer (test .Container )
370
392
} else if check .Validator .SchemaURI != "" {
0 commit comments