From 197a52a797d79d840ba4aa633857ee260f49e18c Mon Sep 17 00:00:00 2001 From: Francisco Barros <francisco.borges.aurindo.barros@cern.ch> Date: Tue, 5 Dec 2023 17:43:58 +0100 Subject: [PATCH] Implemented some comments/suggestions --- controllers/drupalsite_controller.go | 6 +-- controllers/drupalsite_resources.go | 66 ++++++++++------------------ 2 files changed, 27 insertions(+), 45 deletions(-) diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go index c7fec93a..715687b9 100644 --- a/controllers/drupalsite_controller.go +++ b/controllers/drupalsite_controller.go @@ -50,7 +50,7 @@ const ( adminPauseAnnotation = "admin-pause-reconcile" oidcSecretName = "oidc-client-secret" - SSOProxyLabel = "drupal.okd.cern.ch/full-sso" + ssoProxyLabel = "drupal.okd.cern.ch/full-sso" ) var ( @@ -245,8 +245,8 @@ func (r *DrupalSiteReconciler) Reconcile(ctx context.Context, req ctrl.Request) if drupalSite.Labels == nil { drupalSite.Labels = map[string]string{} } - if namespace.Labels[SSOProxyLabel] == "true" && drupalSite.Labels[SSOProxyLabel] != "true" { - drupalSite.Labels[SSOProxyLabel] = "true" + if namespace.Labels[ssoProxyLabel] == "true" && drupalSite.Labels[ssoProxyLabel] != "true" { + drupalSite.Labels[ssoProxyLabel] = "true" return r.updateCRorFailReconcile(ctx, log, drupalSite) } diff --git a/controllers/drupalsite_resources.go b/controllers/drupalsite_resources.go index 5808d79f..b4f25a24 100644 --- a/controllers/drupalsite_resources.go +++ b/controllers/drupalsite_resources.go @@ -745,7 +745,7 @@ func deploymentForDrupalSite(currentobject *appsv1.Deployment, databaseSecret st currentobject.Annotations["alpha.image.policy.openshift.io/resolve-names"] = "*" ssoProxyEnabled := false - if d.Labels[SSOProxyLabel] == "true" { + if d.Labels[ssoProxyLabel] == "true" { ssoProxyEnabled = true } @@ -1403,35 +1403,25 @@ func serviceForDrupalSite(currentobject *corev1.Service, d *webservicesv1a1.Drup addOwnerRefToObject(currentobject, asOwner(d)) currentobject.Spec.Selector = ls - if d.Labels[SSOProxyLabel] == "true" { - currentobject.Spec.Ports = []corev1.ServicePort{ - { - TargetPort: intstr.FromInt(ssoProxyPort), - Name: "sso-proxy", - Port: 80, - Protocol: "TCP", - }, - { - TargetPort: intstr.FromInt(9253), - Name: "php-fpm-exporter", - Port: 9253, - Protocol: "TCP", - }} - } else { - currentobject.Spec.Ports = []corev1.ServicePort{ - { - TargetPort: intstr.FromInt(8080), - Name: "nginx", - Port: 80, - Protocol: "TCP", - }, - { - TargetPort: intstr.FromInt(9253), - Name: "php-fpm-exporter", - Port: 9253, - Protocol: "TCP", - }} + serverName := "nginx" + serverPort := 8080 + if d.Labels[ssoProxyLabel] == "true" { + serverName = "sso-proxy" + serverPort = ssoProxyPort } + currentobject.Spec.Ports = []corev1.ServicePort{ + { + TargetPort: intstr.FromInt(serverPort), + Name: serverName, + Port: 80, + Protocol: "TCP", + }, + { + TargetPort: intstr.FromInt(9253), + Name: "php-fpm-exporter", + Port: 9253, + Protocol: "TCP", + }} return nil } @@ -1447,21 +1437,13 @@ func routeForDrupalSite(currentobject *routev1.Route, d *webservicesv1a1.DrupalS Name: d.Name, Weight: pointer.Int32Ptr(100), } - ssoProxyEnabled := false - if d.Labels[SSOProxyLabel] == "true" { - ssoProxyEnabled = true + port := 8080 + if d.Labels[ssoProxyLabel] == "true" { + port = ssoProxyPort } - - if ssoProxyEnabled == true { - currentobject.Spec.Port = &routev1.RoutePort{ - TargetPort: intstr.FromInt(ssoProxyPort), - } - } else { - currentobject.Spec.Port = &routev1.RoutePort{ - TargetPort: intstr.FromInt(8080), - } + currentobject.Spec.Port = &routev1.RoutePort{ + TargetPort: intstr.FromInt(port), } - if currentobject.Annotations == nil { currentobject.Annotations = map[string]string{} } -- GitLab