Skip to content

Commit 67da852

Browse files
committed
deployment: add env vars from the Proxy object
The Proxy object specifies certain http-proxy related environmnent variables that we need setting for the operand's cotainer.
1 parent 7a385e7 commit 67da852

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

pkg/operator2/deployment.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func defaultDeployment(
2222
operatorConfig *operatorv1.Authentication,
2323
syncData *configSyncData,
2424
routerSecret *corev1.Secret,
25+
proxyConfig *configv1.Proxy,
2526
operatorDeployment *appsv1.Deployment,
2627
resourceVersions ...string,
2728
) *appsv1.Deployment {
@@ -121,6 +122,7 @@ func defaultDeployment(
121122
},
122123
},
123124
VolumeMounts: mounts,
125+
Env: proxyConfigToEnvVars(proxyConfig),
124126
ReadinessProbe: defaultProbe(),
125127
LivenessProbe: livenessProbe(),
126128
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
@@ -236,6 +238,24 @@ func getImagePullPolicy(operatorDeployment *appsv1.Deployment) corev1.PullPolicy
236238
return containers[0].ImagePullPolicy
237239
}
238240

241+
func proxyConfigToEnvVars(proxy *configv1.Proxy) []corev1.EnvVar {
242+
envVars := []corev1.EnvVar{}
243+
244+
envVars = appendEnvVar(envVars, "NO_PROXY", proxy.Spec.NoProxy)
245+
envVars = appendEnvVar(envVars, "HTTP_PROXY", proxy.Spec.HTTPProxy)
246+
envVars = appendEnvVar(envVars, "HTTPS_PROXY", proxy.Spec.HTTPSProxy)
247+
248+
return envVars
249+
}
250+
251+
func appendEnvVar(envVars []corev1.EnvVar, envName, envVal string) []corev1.EnvVar {
252+
if len(envVal) > 0 {
253+
return append(envVars, corev1.EnvVar{Name: envName, Value: envVal})
254+
}
255+
256+
return envVars
257+
}
258+
239259
type volume struct {
240260
name string
241261
configmap bool

pkg/operator2/operator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ type authOperator struct {
173173
infrastructure configv1client.InfrastructureInterface
174174
ingress configv1client.IngressInterface
175175
apiserver configv1client.APIServerInterface
176+
proxy configv1client.ProxyInterface
176177

177178
resourceSyncer resourcesynccontroller.ResourceSyncer
178179
}
@@ -212,6 +213,7 @@ func NewAuthenticationOperator(
212213
infrastructure: configClient.ConfigV1().Infrastructures(),
213214
ingress: configClient.ConfigV1().Ingresses(),
214215
apiserver: configClient.ConfigV1().APIServers(),
216+
proxy: configClient.ConfigV1().Proxies(),
215217

216218
resourceSyncer: resourceSyncer,
217219
}
@@ -238,6 +240,7 @@ func NewAuthenticationOperator(
238240
operator.WithInformer(configV1Informers.Infrastructures(), configNameFilter, controller.WithNoSync()),
239241
operator.WithInformer(configV1Informers.Ingresses(), configNameFilter, controller.WithNoSync()),
240242
operator.WithInformer(configV1Informers.APIServers(), configNameFilter, controller.WithNoSync()),
243+
operator.WithInformer(configV1Informers.Proxies(), configNameFilter, controller.WithNoSync()),
241244
)
242245
}
243246

@@ -400,6 +403,9 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
400403
return err
401404
}
402405

406+
proxyConfig := c.handleProxyConfig()
407+
resourceVersions = append(resourceVersions, proxyConfig.ResourceVersion)
408+
403409
operatorDeployment, err := c.deployments.Deployments(targetNamespaceOperator).Get(targetNameOperator, metav1.GetOptions{})
404410
if err != nil {
405411
return err
@@ -411,6 +417,7 @@ func (c *authOperator) handleSync(operatorConfig *operatorv1.Authentication) err
411417
operatorConfig,
412418
syncData,
413419
routerSecret,
420+
proxyConfig,
414421
operatorDeployment,
415422
resourceVersions...,
416423
)

pkg/operator2/proxy.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package operator2
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/klog"
6+
7+
configv1 "github.com/openshift/api/config/v1"
8+
)
9+
10+
func (c *authOperator) handleProxyConfig() *configv1.Proxy {
11+
proxyConfig, err := c.proxy.Get(globalConfigName, metav1.GetOptions{})
12+
if err != nil {
13+
klog.Infof("error getting proxy config: %v", err)
14+
return &configv1.Proxy{}
15+
}
16+
return proxyConfig
17+
}

0 commit comments

Comments
 (0)