-
Notifications
You must be signed in to change notification settings - Fork 158
Add proxy support #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proxy support #254
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| corev1 "k8s.io/client-go/informers/core/v1" | ||
| appsv1 "k8s.io/client-go/kubernetes/typed/apps/v1" | ||
| coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1" | ||
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/klog" | ||
|
|
||
| // openshift | ||
|
|
@@ -32,13 +33,15 @@ import ( | |
|
|
||
| // informers | ||
| configinformer "github.com/openshift/client-go/config/informers/externalversions" | ||
| configinformerv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1" | ||
| operatorinformerv1 "github.com/openshift/client-go/operator/informers/externalversions/operator/v1" | ||
|
|
||
| routesinformersv1 "github.com/openshift/client-go/route/informers/externalversions/route/v1" | ||
| appsinformersv1 "k8s.io/client-go/informers/apps/v1" | ||
|
|
||
| // clients | ||
| configclientv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" | ||
| configlisterv1 "github.com/openshift/client-go/config/listers/config/v1" | ||
| operatorclientv1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1" | ||
|
|
||
| // operator | ||
|
|
@@ -71,6 +74,9 @@ type consoleOperator struct { | |
| // recorder | ||
| recorder events.Recorder | ||
| resourceSyncer resourcesynccontroller.ResourceSyncer | ||
| //proxy | ||
| proxyCfgLister configlisterv1.ProxyLister | ||
| proxyCfgInformer cache.SharedIndexInformer | ||
| } | ||
|
|
||
| func NewConsoleOperator( | ||
|
|
@@ -83,6 +89,7 @@ func NewConsoleOperator( | |
| deployments appsinformersv1.DeploymentInformer, | ||
| routes routesinformersv1.RouteInformer, | ||
| oauthClients oauthinformersv1.OAuthClientInformer, | ||
| proxyCfgInformer configinformerv1.ProxyInformer, | ||
|
|
||
| // clients | ||
| operatorConfigClient operatorclientv1.OperatorV1Interface, | ||
|
|
@@ -114,6 +121,9 @@ func NewConsoleOperator( | |
| // recorder | ||
| recorder: recorder, | ||
| resourceSyncer: resourceSyncer, | ||
| // proxy | ||
| proxyCfgLister: proxyCfgInformer.Lister(), | ||
| proxyCfgInformer: proxyCfgInformer.Informer(), | ||
| } | ||
|
|
||
| secretsInformer := coreV1.Secrets() | ||
|
|
@@ -130,6 +140,7 @@ func NewConsoleOperator( | |
| operator.WithInformer(configV1Informers.Consoles(), configNameFilter), | ||
| operator.WithInformer(operatorConfigInformer, configNameFilter), | ||
| operator.WithInformer(configV1Informers.Infrastructures(), configNameFilter), | ||
| operator.WithInformer(proxyCfgInformer, configNameFilter), | ||
| // console resources | ||
| operator.WithInformer(deployments, targetNameFilter), | ||
| operator.WithInformer(routes, targetNameFilter), | ||
|
|
@@ -151,6 +162,7 @@ type configSet struct { | |
| Console *configv1.Console | ||
| Operator *operatorsv1.Console | ||
| Infrastructure *configv1.Infrastructure | ||
| Proxy *configv1.Proxy | ||
| } | ||
|
|
||
| func (c *consoleOperator) Sync(obj metav1.Object) error { | ||
|
|
@@ -175,10 +187,19 @@ func (c *consoleOperator) Sync(obj metav1.Object) error { | |
| return err | ||
| } | ||
|
|
||
| proxyConfig, err := c.proxyCfgLister.Get("cluster") | ||
| if err != nil { | ||
| if !errors.IsNotFound(err) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 The proxy config might not be there always on upgrade, and we shouldn't error. Good catch. I believe we can remove this in 4.3. |
||
| return err | ||
| } | ||
| proxyConfig = nil | ||
| } | ||
|
|
||
| configs := configSet{ | ||
| Console: consoleConfig, | ||
| Operator: operatorConfig, | ||
| Infrastructure: infrastructureConfig, | ||
| Proxy: proxyConfig, | ||
| } | ||
|
|
||
| if err := c.handleSync(configs); err != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
| "k8s.io/klog" | ||
|
|
||
| // openshift | ||
| configv1 "github.com/openshift/api/config/v1" | ||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| routev1 "github.com/openshift/api/route/v1" | ||
| "github.com/openshift/console-operator/pkg/api" | ||
|
|
@@ -54,7 +55,7 @@ type volumeConfig struct { | |
| isConfigMap bool | ||
| } | ||
|
|
||
| func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap, serviceCAConfigMap *corev1.ConfigMap, sec *corev1.Secret, rt *routev1.Route, canMountCustomLogo bool) *appsv1.Deployment { | ||
| func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap, serviceCAConfigMap *corev1.ConfigMap, sec *corev1.Secret, rt *routev1.Route, proxyConfig *configv1.Proxy, canMountCustomLogo bool) *appsv1.Deployment { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function call has gotten long enough that we should pass in a struct. Maybe add that to tech debt?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah definitely would add it as techdebt 👍 |
||
| labels := util.LabelsForConsole() | ||
| meta := util.SharedMeta() | ||
| meta.Labels = labels | ||
|
|
@@ -137,7 +138,7 @@ func DefaultDeployment(operatorConfig *operatorv1.Console, cm *corev1.ConfigMap, | |
| TerminationGracePeriodSeconds: &gracePeriod, | ||
| SecurityContext: &corev1.PodSecurityContext{}, | ||
| Containers: []corev1.Container{ | ||
| consoleContainer(operatorConfig, volumeConfig), | ||
| consoleContainer(operatorConfig, volumeConfig, proxyConfig), | ||
| }, | ||
| Volumes: consoleVolumes(volumeConfig), | ||
| }, | ||
|
|
@@ -230,7 +231,7 @@ func GetLogLevelFlag(logLevel operatorv1.LogLevel) string { | |
| return flag | ||
| } | ||
|
|
||
| func consoleContainer(cr *operatorv1.Console, volConfigList []volumeConfig) corev1.Container { | ||
| func consoleContainer(cr *operatorv1.Console, volConfigList []volumeConfig, proxyConfig *configv1.Proxy) corev1.Container { | ||
| volumeMounts := consoleVolumeMounts(volConfigList) | ||
| // Since the console-operator logging has different logging levels then the capnslog, | ||
| // that we use for console server(bridge) we need to map them to each other | ||
|
|
@@ -252,6 +253,7 @@ func consoleContainer(cr *operatorv1.Console, volConfigList []volumeConfig) core | |
| // Name: publicURLName, | ||
| // Value: consoleURL(), | ||
| //}}, | ||
| Env: setEnvironmentVariables(proxyConfig), | ||
| Ports: []corev1.ContainerPort{{ | ||
| Name: consolePortName, | ||
| Protocol: corev1.ProtocolTCP, | ||
|
|
@@ -270,6 +272,32 @@ func consoleContainer(cr *operatorv1.Console, volConfigList []volumeConfig) core | |
| } | ||
| } | ||
|
|
||
| func setEnvironmentVariables(proxyConfig *configv1.Proxy) []corev1.EnvVar { | ||
| envVars := []corev1.EnvVar{} | ||
| if proxyConfig == nil { | ||
| return envVars | ||
| } | ||
| if len(proxyConfig.Status.HTTPSProxy) != 0 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do a check on proxyConfig if it is nil, but what about proxyConfig.Status? Is that guaranteed to be there?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be needed since it's not a pointer |
||
| envVars = append(envVars, corev1.EnvVar{ | ||
| Name: "HTTPS_PROXY", | ||
| Value: proxyConfig.Status.HTTPSProxy, | ||
| }) | ||
| } | ||
| if len(proxyConfig.Status.HTTPProxy) != 0 { | ||
| envVars = append(envVars, corev1.EnvVar{ | ||
| Name: "HTTP_PROXY", | ||
| Value: proxyConfig.Status.HTTPProxy, | ||
| }) | ||
| } | ||
| if len(proxyConfig.Status.NoProxy) != 0 { | ||
| envVars = append(envVars, corev1.EnvVar{ | ||
| Name: "NO_PROXY", | ||
| Value: proxyConfig.Status.NoProxy, | ||
| }) | ||
| } | ||
| return envVars | ||
| } | ||
|
|
||
| func defaultProbe() *corev1.Probe { | ||
| return &corev1.Probe{ | ||
| Handler: corev1.Handler{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe
proxyCfgInformer: proxyCfgInformer.Informer(),is needed here. You have theWithInformer()call with theproxyCfgInformerbelow.