Skip to content

Commit 02bb9ba

Browse files
committed
lib/resourcemerge/core: Clear env and envFrom if unset in manifest
Even if the manifest authors state no opinions, these are not properties that we want to allow cluster admins to manipulate. For example, a customer cluster recently stuck a Deployment by inserting a reference to a non-existent secret [1]: $ yaml2json <namespaces/openshift-marketplace/apps/deployments.yaml | jq -r '.items[].spec.template.spec.containers[].envFrom[]' { "secretRef": { "name": "openshift-reg" } } $ yaml2json <namespaces/openshift-marketplace/pods/marketplace-operator-f7cc88d59-hhh75/marketplace-operator-f7cc88d59-hhh75.yaml | jq -r '.status.containerStatuses[].state' { "waiting": { "message": "secret \"openshift-reg\" not found", "reason": "CreateContainerConfigError" } } The outgoing logic dates back to the beginning of reconciling these properties in 14fab0b (add generic 2-way merge handler for random types, 2018-09-27, openshift#26), and this commit's tightening follows on a number of reconciliation tightenings like 29b92d2 (lib/resourcemerge/core: Clear livenessProbe and readinessProbe if nil in required, 2020-01-16, openshift#298). [1]: https://bugzilla.redhat.com/show_bug.cgi?id=1951339#c0
1 parent 8132d6a commit 02bb9ba

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

lib/resourcemerge/core.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,13 @@ func ensureContainer(modified *bool, existing *corev1.Container, required corev1
141141
}
142142

143143
func ensureEnvVar(modified *bool, existing *[]corev1.EnvVar, required []corev1.EnvVar) {
144-
if required == nil {
145-
return
146-
}
147144
if !equality.Semantic.DeepEqual(required, *existing) {
148145
*existing = required
149146
*modified = true
150147
}
151148
}
152149

153150
func ensureEnvFromSource(modified *bool, existing *[]corev1.EnvFromSource, required []corev1.EnvFromSource) {
154-
if required == nil {
155-
return
156-
}
157151
if !equality.Semantic.DeepEqual(required, *existing) {
158152
*existing = required
159153
*modified = true

0 commit comments

Comments
 (0)