Skip to content
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

fix: Propagate proxy config into oauth-proxy sidecar container #1317

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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