Skip to content

Commit 294ec3c

Browse files
committed
ocm deployment: Add POD_NAME
Also had to align deployment env generation to fix tests.
1 parent 0ab3099 commit 294ec3c

File tree

3 files changed

+201
-131
lines changed

3 files changed

+201
-131
lines changed

bindata/assets/openshift-controller-manager/deploy.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ spec:
6363
ports:
6464
- containerPort: 8443
6565
terminationMessagePolicy: FallbackToLogsOnError
66+
env:
67+
- name: POD_NAME
68+
valueFrom:
69+
fieldRef:
70+
fieldPath: metadata.name
6671
livenessProbe:
6772
initialDelaySeconds: 30
6873
httpGet:

pkg/operator/sync_openshiftcontrollermanager_v311_00.go

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func syncOpenShiftControllerManager_v311_00_to_latest(
131131
// our configmaps and secrets are in order, now it is time to create the Deployment
132132
var progressingMessages []string
133133
actualDeployment, _, openshiftControllerManagerError := manageOpenShiftControllerManagerDeployment_v311_00_to_latest(
134+
bindata.MustAsset,
134135
c.kubeClient.AppsV1(),
135136
countNodes,
136137
ensureAtMostOnePodPerNodeFn,
@@ -438,6 +439,7 @@ func manageOpenShiftGlobalCAConfigMap_v311_00_to_latest(kubeClient kubernetes.In
438439
}
439440

440441
func manageOpenShiftControllerManagerDeployment_v311_00_to_latest(
442+
mustLoadAsset func(string) []byte,
441443
client appsclientv1.DeploymentsGetter,
442444
countNodes nodeCountFunc,
443445
ensureAtMostOnePodPerNodeFn ensureAtMostOnePodPerNodeFunc,
@@ -448,7 +450,7 @@ func manageOpenShiftControllerManagerDeployment_v311_00_to_latest(
448450
proxyLister proxyvclient1.ProxyLister,
449451
specAnnotations map[string]string,
450452
) (*appsv1.Deployment, bool, error) {
451-
required := resourceread.ReadDeploymentV1OrDie(bindata.MustAsset("assets/openshift-controller-manager/deploy.yaml"))
453+
required := resourceread.ReadDeploymentV1OrDie(mustLoadAsset("assets/openshift-controller-manager/deploy.yaml"))
452454

453455
if len(imagePullSpec) > 0 {
454456
required.Spec.Template.Spec.Containers[0].Image = imagePullSpec
@@ -493,44 +495,27 @@ func manageOpenShiftControllerManagerDeployment_v311_00_to_latest(
493495
}
494496
} else {
495497
for i, c := range required.Spec.Template.Spec.Containers {
496-
newEnvs := []corev1.EnvVar{}
497-
498-
if len(c.Env) == 0 {
499-
if len(proxyCfg.Status.NoProxy) > 0 {
500-
newEnvs = append(newEnvs, corev1.EnvVar{Name: "NO_PROXY", Value: proxyCfg.Status.NoProxy})
501-
}
502-
if len(proxyCfg.Status.HTTPProxy) > 0 {
503-
newEnvs = append(newEnvs, corev1.EnvVar{Name: "HTTP_PROXY", Value: proxyCfg.Status.HTTPProxy})
504-
}
505-
if len(proxyCfg.Status.HTTPSProxy) > 0 {
506-
newEnvs = append(newEnvs, corev1.EnvVar{Name: "HTTPS_PROXY", Value: proxyCfg.Status.HTTPSProxy})
498+
// Remove the relevant variables from the spec.
499+
newEnvs := make([]corev1.EnvVar, 0, len(c.Env))
500+
for _, env := range c.Env {
501+
switch strings.TrimSpace(env.Name) {
502+
case "HTTPS_PROXY", "HTTP_PROXY", "NO_PROXY":
503+
default:
504+
newEnvs = append(newEnvs, env)
507505
}
508506
}
509507

510-
for _, env := range c.Env {
511-
name := strings.TrimSpace(env.Name)
512-
switch name {
513-
case "HTTPS_PROXY":
514-
if len(proxyCfg.Status.HTTPSProxy) == 0 {
515-
continue
516-
}
517-
env.Value = proxyCfg.Status.HTTPSProxy
518-
519-
case "HTTP_PROXY":
520-
if len(proxyCfg.Status.HTTPProxy) == 0 {
521-
continue
522-
}
523-
env.Value = proxyCfg.Status.HTTPProxy
524-
525-
case "NO_PROXY":
526-
if len(proxyCfg.Status.NoProxy) == 0 {
527-
continue
528-
}
529-
env.Value = proxyCfg.Status.NoProxy
530-
531-
}
532-
newEnvs = append(newEnvs, env)
508+
// Add back the values that are available in the proxy config.
509+
if len(proxyCfg.Status.HTTPSProxy) > 0 {
510+
newEnvs = append(newEnvs, corev1.EnvVar{Name: "HTTPS_PROXY", Value: proxyCfg.Status.HTTPSProxy})
511+
}
512+
if len(proxyCfg.Status.HTTPProxy) > 0 {
513+
newEnvs = append(newEnvs, corev1.EnvVar{Name: "HTTP_PROXY", Value: proxyCfg.Status.HTTPProxy})
533514
}
515+
if len(proxyCfg.Status.NoProxy) > 0 {
516+
newEnvs = append(newEnvs, corev1.EnvVar{Name: "NO_PROXY", Value: proxyCfg.Status.NoProxy})
517+
}
518+
534519
required.Spec.Template.Spec.Containers[i].Env = newEnvs
535520
}
536521
}

0 commit comments

Comments
 (0)