Skip to content

Commit

Permalink
lib/resourcemerge: sync daemonset container env vars
Browse files Browse the repository at this point in the history
Sync env var changes in the daemonset definition, so injected proxy
env var updates will get applied upon an upgrade.

Signed-off-by: Yu Qi Zhang <jerzhang@redhat.com>
  • Loading branch information
yuqi-zhang committed Sep 1, 2020
1 parent ea0f893 commit 197db25
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/resourcemerge/core.go
Expand Up @@ -99,6 +99,23 @@ func ensureContainer(modified *bool, existing *corev1.Container, required corev1

setStringIfSet(modified, &existing.WorkingDir, required.WorkingDir)

// also sync the env vars here, added to handle proxy
for _, required := range required.Env {
var existingCurr *corev1.EnvVar
for j, curr := range existing.Env {
if curr.Name == required.Name {
existingCurr = &existing.Env[j]
break
}
}
if existingCurr == nil {
*modified = true
existing.Env = append(existing.Env, corev1.EnvVar{})
existingCurr = &existing.Env[len(existing.Env)-1]
}
ensureEnvVar(modified, existingCurr, required)
}

// any port we specify, we require
for _, required := range required.Ports {
var existingCurr *corev1.ContainerPort
Expand Down Expand Up @@ -177,6 +194,13 @@ func ensureContainerPort(modified *bool, existing *corev1.ContainerPort, require
}
}

func ensureEnvVar(modified *bool, existing *corev1.EnvVar, required corev1.EnvVar) {
if !equality.Semantic.DeepEqual(required, *existing) {
*modified = true
*existing = required
}
}

func ensureVolumeMount(modified *bool, existing *corev1.VolumeMount, required corev1.VolumeMount) {
if !equality.Semantic.DeepEqual(required, *existing) {
*modified = true
Expand Down

0 comments on commit 197db25

Please sign in to comment.