Skip to content

Commit 6254dc2

Browse files
committed
(feat) empty proxy env var should result in unset
- If an env variable specified in pod configuration is empty, it will override the target PodSpec. For example, if 'foo=""' in pod configuration, olm will reset the 'foo' env variable in the target PodSpec to 'foo=""' - However, proxy env var is an exception to the above. An empty proxy env var means that it should not be set or it should be unset if it is already set in the target PodSpec.
1 parent bb4e018 commit 6254dc2

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

pkg/controller/operators/olm/envvar/initializer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (d *DeploymentInitializer) initialize(ownerCSV ownerutil.Owner, deployment
5656
err = fmt.Errorf("failed to query cluster proxy configuration - %v", err)
5757
return err
5858
}
59+
60+
proxyEnvVar = dropEmptyProxyEnv(proxyEnvVar)
5961
}
6062

6163
merged = append(podConfigEnvVar, proxyEnvVar...)
@@ -71,3 +73,16 @@ func (d *DeploymentInitializer) initialize(ownerCSV ownerutil.Owner, deployment
7173

7274
return nil
7375
}
76+
77+
func dropEmptyProxyEnv(in []corev1.EnvVar) (out []corev1.EnvVar) {
78+
out = make([]corev1.EnvVar, 0)
79+
for i := range in {
80+
if in[i].Value == "" {
81+
continue
82+
}
83+
84+
out = append(out, in[i])
85+
}
86+
87+
return
88+
}

pkg/controller/operators/olm/envvar/inject.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@ func merge(containerEnvVars []corev1.EnvVar, newEnvVars []corev1.EnvVar) (merged
2929

3030
for _, newEnvVar := range newEnvVars {
3131
existing, found := find(containerEnvVars, newEnvVar.Name)
32-
if !found {
33-
if newEnvVar.Value != "" {
34-
merged = append(merged, corev1.EnvVar{
35-
Name: newEnvVar.Name,
36-
Value: newEnvVar.Value,
37-
})
38-
}
39-
32+
if found {
33+
existing.Value = newEnvVar.Value
4034
continue
4135
}
4236

43-
existing.Value = newEnvVar.Value
37+
merged = append(merged, corev1.EnvVar{
38+
Name: newEnvVar.Name,
39+
Value: newEnvVar.Value,
40+
})
4441
}
4542

4643
return

test/e2e/subscription_e2e_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,19 +1141,27 @@ func TestCreateNewSubscriptionWithPodConfig(t *testing.T) {
11411141
}
11421142

11431143
require.NotNil(t, proxy)
1144-
proxyEnv := []corev1.EnvVar{
1145-
corev1.EnvVar{
1144+
proxyEnv := []corev1.EnvVar{}
1145+
1146+
if proxy.Status.HTTPProxy !="" {
1147+
proxyEnv = append(proxyEnv, corev1.EnvVar{
11461148
Name: "HTTP_PROXY",
11471149
Value: proxy.Status.HTTPProxy,
1148-
},
1149-
corev1.EnvVar{
1150+
})
1151+
}
1152+
1153+
if proxy.Status.HTTPSProxy !="" {
1154+
proxyEnv = append(proxyEnv, corev1.EnvVar{
11501155
Name: "HTTPS_PROXY",
11511156
Value: proxy.Status.HTTPSProxy,
1152-
},
1153-
corev1.EnvVar{
1157+
})
1158+
}
1159+
1160+
if proxy.Status.NoProxy !="" {
1161+
proxyEnv = append(proxyEnv, corev1.EnvVar{
11541162
Name: "NO_PROXY",
11551163
Value: proxy.Status.NoProxy,
1156-
},
1164+
})
11571165
}
11581166

11591167
return proxyEnv

0 commit comments

Comments
 (0)