Skip to content

Commit

Permalink
fix: Propagate proxy config into oauth-proxy sidecar container (#1317)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha authored Feb 3, 2022
1 parent df718e6 commit 4516e3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
26 changes: 13 additions & 13 deletions pkg/deploy/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func syncAll(deployContext *deploy.DeployContext) error {
return err
}

depl := getGatewayDeploymentSpec(instance)
depl := getGatewayDeploymentSpec(deployContext)
if _, err := deploy.Sync(deployContext, &depl, deploy.DefaultDeploymentDiffOpts); err != nil {
return err
}
Expand Down Expand Up @@ -409,10 +409,10 @@ experimental:
}
}

func getGatewayDeploymentSpec(instance *orgv1.CheCluster) appsv1.Deployment {
func getGatewayDeploymentSpec(ctx *deploy.DeployContext) appsv1.Deployment {
terminationGracePeriodSeconds := int64(10)

deployLabels, labelsSelector := deploy.GetLabelsAndSelector(instance, GatewayServiceName)
deployLabels, labelsSelector := deploy.GetLabelsAndSelector(ctx.CheCluster, GatewayServiceName)

return appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Expand All @@ -421,7 +421,7 @@ func getGatewayDeploymentSpec(instance *orgv1.CheCluster) appsv1.Deployment {
},
ObjectMeta: metav1.ObjectMeta{
Name: GatewayServiceName,
Namespace: instance.Namespace,
Namespace: ctx.CheCluster.Namespace,
Labels: deployLabels,
},
Spec: appsv1.DeploymentSpec{
Expand All @@ -439,26 +439,26 @@ func getGatewayDeploymentSpec(instance *orgv1.CheCluster) appsv1.Deployment {
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
ServiceAccountName: GatewayServiceName,
RestartPolicy: corev1.RestartPolicyAlways,
Containers: getContainersSpec(instance),
Volumes: getVolumesSpec(instance),
Containers: getContainersSpec(ctx),
Volumes: getVolumesSpec(ctx.CheCluster),
},
},
},
}
}

func getContainersSpec(instance *orgv1.CheCluster) []corev1.Container {
configLabelsMap := util.GetMapValue(instance.Spec.Server.SingleHostGatewayConfigMapLabels, deploy.DefaultSingleHostGatewayConfigMapLabels)
gatewayImage := util.GetValue(instance.Spec.Server.SingleHostGatewayImage, deploy.DefaultSingleHostGatewayImage(instance))
configSidecarImage := util.GetValue(instance.Spec.Server.SingleHostGatewayConfigSidecarImage, deploy.DefaultSingleHostGatewayConfigSidecarImage(instance))
func getContainersSpec(ctx *deploy.DeployContext) []corev1.Container {
configLabelsMap := util.GetMapValue(ctx.CheCluster.Spec.Server.SingleHostGatewayConfigMapLabels, deploy.DefaultSingleHostGatewayConfigMapLabels)
gatewayImage := util.GetValue(ctx.CheCluster.Spec.Server.SingleHostGatewayImage, deploy.DefaultSingleHostGatewayImage(ctx.CheCluster))
configSidecarImage := util.GetValue(ctx.CheCluster.Spec.Server.SingleHostGatewayConfigSidecarImage, deploy.DefaultSingleHostGatewayConfigSidecarImage(ctx.CheCluster))
configLabels := labels.FormatLabels(configLabelsMap)

containers := []corev1.Container{
{
Name: "gateway",
Image: gatewayImage,
ImagePullPolicy: corev1.PullAlways,
VolumeMounts: getTraefikContainerVolumeMounts(instance),
VolumeMounts: getTraefikContainerVolumeMounts(ctx.CheCluster),
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("4Gi"),
Expand Down Expand Up @@ -513,8 +513,8 @@ func getContainersSpec(instance *orgv1.CheCluster) []corev1.Container {
}

containers = append(containers,
getOauthProxyContainerSpec(instance),
getKubeRbacProxyContainerSpec(instance))
getOauthProxyContainerSpec(ctx),
getKubeRbacProxyContainerSpec(ctx.CheCluster))

return containers
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/deploy/gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestSyncAllToCluster(t *testing.T) {
NonCachingClient: cli,
Scheme: scheme.Scheme,
},
Proxy: &deploy.Proxy{},
}

err := SyncGatewayToCluster(deployContext)
Expand Down Expand Up @@ -90,6 +91,7 @@ func TestNativeUserGateway(t *testing.T) {
NonCachingClient: cli,
Scheme: scheme.Scheme,
},
Proxy: &deploy.Proxy{},
}

err := SyncGatewayToCluster(deployContext)
Expand Down
18 changes: 16 additions & 2 deletions pkg/deploy/gateway/oauth_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func skipAuthConfig(instance *orgv1.CheCluster) string {
return ""
}

func getOauthProxyContainerSpec(instance *orgv1.CheCluster) corev1.Container {
authnImage := util.GetValue(instance.Spec.Auth.GatewayAuthenticationSidecarImage, deploy.DefaultGatewayAuthenticationSidecarImage(instance))
func getOauthProxyContainerSpec(ctx *deploy.DeployContext) corev1.Container {
authnImage := util.GetValue(ctx.CheCluster.Spec.Auth.GatewayAuthenticationSidecarImage, deploy.DefaultGatewayAuthenticationSidecarImage(ctx.CheCluster))
return corev1.Container{
Name: "oauth-proxy",
Image: authnImage,
Expand All @@ -155,6 +155,20 @@ func getOauthProxyContainerSpec(instance *orgv1.CheCluster) corev1.Container {
Ports: []corev1.ContainerPort{
{ContainerPort: GatewayServicePort, Protocol: "TCP"},
},
Env: []corev1.EnvVar{
{
Name: "http_proxy",
Value: ctx.Proxy.HttpProxy,
},
{
Name: "https_proxy",
Value: ctx.Proxy.HttpsProxy,
},
{
Name: "no_proxy",
Value: ctx.Proxy.NoProxy,
},
},
}
}

Expand Down

0 comments on commit 4516e3b

Please sign in to comment.