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
This commit is contained in:
jdesouza
2025-04-21 17:07:12 -03:00
committed by GitHub
parent 8fe7a94260
commit d7d30ac611
2 changed files with 30 additions and 9 deletions

View File

@@ -161,7 +161,6 @@ func createPathAndFindNodes(node *yaml.Node, selectors []string, create bool) ([
node.Value = ""
case yaml.SequenceNode:
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)
default:
return nil, errors.Errorf("parent node is of unknown kind %v", node.Kind)
}

View File

@@ -341,12 +341,23 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
podCopy := *test.Resource.PodSpec
podCopy.InitContainers = []corev1.Container{}
podCopy.Containers = []corev1.Container{*test.Container}
containerIndex := funk.IndexOf(test.Resource.PodSpec.Containers, func(value corev1.Container) bool {
return value.Name == test.Container.Name
})
containerIndex := -1
if !test.IsInitContainer {
containerIndex = funk.IndexOf(test.Resource.PodSpec.Containers, func(value corev1.Container) bool {
return value.Name == test.Container.Name
})
} else {
containerIndex = funk.IndexOf(test.Resource.PodSpec.InitContainers, func(value corev1.Container) bool {
return value.Name == test.Container.Name
})
}
prefix = getJSONSchemaPrefix(test.Resource.Kind)
if prefix != "" {
prefix += "/containers/" + strconv.Itoa(containerIndex)
if test.IsInitContainer {
prefix += "/initContainers/" + strconv.Itoa(containerIndex)
} else {
prefix += "/containers/" + strconv.Itoa(containerIndex)
}
}
passes, issues, err = check.CheckPodSpec(&podCopy)
} else {
@@ -359,12 +370,23 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
passes, issues, err = check.CheckPodTemplate(test.Resource.PodTemplate)
prefix = getJSONSchemaPrefix(test.Resource.Kind)
} else if check.Target == config.TargetContainer {
containerIndex := funk.IndexOf(test.Resource.PodSpec.Containers, func(value corev1.Container) bool {
return value.Name == test.Container.Name
})
containerIndex := -1
if !test.IsInitContainer {
containerIndex = funk.IndexOf(test.Resource.PodSpec.Containers, func(value corev1.Container) bool {
return value.Name == test.Container.Name
})
} else {
containerIndex = funk.IndexOf(test.Resource.PodSpec.InitContainers, func(value corev1.Container) bool {
return value.Name == test.Container.Name
})
}
prefix = getJSONSchemaPrefix(test.Resource.Kind)
if prefix != "" {
prefix += "/containers/" + strconv.Itoa(containerIndex)
if test.IsInitContainer {
prefix += "/initContainers/" + strconv.Itoa(containerIndex)
} else {
prefix += "/containers/" + strconv.Itoa(containerIndex)
}
}
passes, issues, err = check.CheckContainer(test.Container)
} else if check.Validator.SchemaURI != "" {