@@ -341,12 +341,23 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
341341 podCopy := * test .Resource .PodSpec
342342 podCopy .InitContainers = []corev1.Container {}
343343 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+ }
347354 prefix = getJSONSchemaPrefix (test .Resource .Kind )
348355 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+ }
350361 }
351362 passes , issues , err = check .CheckPodSpec (& podCopy )
352363 } else {
@@ -359,12 +370,23 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
359370 passes , issues , err = check .CheckPodTemplate (test .Resource .PodTemplate )
360371 prefix = getJSONSchemaPrefix (test .Resource .Kind )
361372 } 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+ }
365383 prefix = getJSONSchemaPrefix (test .Resource .Kind )
366384 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+ }
368390 }
369391 passes , issues , err = check .CheckContainer (test .Container )
370392 } else if check .Validator .SchemaURI != "" {
0 commit comments