Skip to content

Commit d7d30ac

Browse files
authored
INS-933 - pullPolicyNotAlways is crashing webhook mutations (#1115)
* Debugging * Debugging * Trying to fix * Revert * Debugging * Debugging * Debugging * Fixing issue * Fixing issue * Fixing issue * Fixing issue * Fixing issue * Fixing issue
1 parent 8fe7a94 commit d7d30ac

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

pkg/mutation/mutate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func createPathAndFindNodes(node *yaml.Node, selectors []string, create bool) ([
161161
node.Value = ""
162162
case yaml.SequenceNode:
163163
return nil, errors.Errorf("parent node is array, use /*/ or /0/../%v/ instead of .%v to access its item(s) first", len(node.Content)-1, currentSelector)
164-
165164
default:
166165
return nil, errors.Errorf("parent node is of unknown kind %v", node.Kind)
167166
}

pkg/validator/schema.go

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)