From 449b0e2761007e790e31d4a8d498ae6c069ceccf Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 17 Jan 2025 18:22:56 +1100 Subject: [PATCH] refactor: check for lagoon-env secrets first --- .../controllers/v1beta2/build_controller.go | 12 +--- .../v1beta2/build_deletionhandlers.go | 51 ++++---------- internal/controllers/v1beta2/build_helpers.go | 58 ++-------------- .../v1beta2/podmonitor_buildhandlers.go | 63 ++++------------- .../controllers/v1beta2/task_controller.go | 68 ++++++++++++++++--- internal/helpers/helpers.go | 45 ++++++++++++ 6 files changed, 138 insertions(+), 159 deletions(-) diff --git a/internal/controllers/v1beta2/build_controller.go b/internal/controllers/v1beta2/build_controller.go index 566f763c..3ada3c05 100644 --- a/internal/controllers/v1beta2/build_controller.go +++ b/internal/controllers/v1beta2/build_controller.go @@ -241,16 +241,6 @@ func (r *LagoonBuildReconciler) createNamespaceBuild(ctx context.Context, return ctrl.Result{}, err } - // Get or create the lagoon-env configmap - lagoonEnvConfigMap := &corev1.ConfigMap{} - if r.EnableDebug { - opLog.Info("Checking `lagoon-env` configMap exists - creating if not") - } - err = r.getOrCreateConfigMap(ctx, "lagoon-env", lagoonEnvConfigMap, namespace.ObjectMeta.Name) - if err != nil { - return ctrl.Result{}, err - } - // copy the build resource into a new resource and set the status to pending // create the new resource and the controller will handle it via queue opLog.Info(fmt.Sprintf("Creating LagoonBuild in Pending status: %s", lagoonBuild.ObjectMeta.Name)) @@ -308,7 +298,7 @@ func (r *LagoonBuildReconciler) createNamespaceBuild(ctx context.Context, continue } // send the status change to lagoon - r.updateDeploymentAndEnvironmentTask(opLog, runningBuild, nil, buildCondition, "cancelled") + r.updateDeploymentAndEnvironmentTask(ctx, opLog, runningBuild, false, buildCondition, "cancelled") continue } // handle processing running but no pod/failed pod builds diff --git a/internal/controllers/v1beta2/build_deletionhandlers.go b/internal/controllers/v1beta2/build_deletionhandlers.go index 6db24156..bbacc879 100644 --- a/internal/controllers/v1beta2/build_deletionhandlers.go +++ b/internal/controllers/v1beta2/build_deletionhandlers.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "sort" - "strings" "time" "github.com/go-logr/logr" @@ -195,25 +194,10 @@ Build cancelled if err := r.Patch(ctx, &lagoonBuild, client.RawPatch(types.MergePatchType, mergePatch)); err != nil { opLog.Error(err, "unable to update build status") } - // get the configmap for lagoon-env so we can use it for updating the deployment in lagoon - var lagoonEnv corev1.ConfigMap - err := r.Get(ctx, types.NamespacedName{ - Namespace: lagoonBuild.ObjectMeta.Namespace, - Name: "lagoon-env", - }, - &lagoonEnv, - ) - if err != nil { - // if there isn't a configmap, just info it and move on - // the updatedeployment function will see it as nil and not bother doing the bits that require the configmap - if r.EnableDebug { - opLog.Info(fmt.Sprintf("There is no configmap %s in namespace %s ", "lagoon-env", lagoonBuild.ObjectMeta.Namespace)) - } - } // send any messages to lagoon message queues // update the deployment with the status of cancelled in lagoon - r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusCancelled, "cancelled") - r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusCancelled, "cancelled") + r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, lagooncrd.BuildStatusCancelled, "cancelled") + r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, true, lagooncrd.BuildStatusCancelled, "cancelled") r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagooncrd.BuildStatusCancelled) } return nil @@ -267,9 +251,10 @@ func (r *LagoonBuildReconciler) buildLogsToLagoonLogs( // updateDeploymentAndEnvironmentTask sends the status of the build and deployment to the controllerhandler message queue in lagoon, // this is for the handler in lagoon to process. func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask( + ctx context.Context, opLog logr.Logger, lagoonBuild *lagooncrd.LagoonBuild, - lagoonEnv *corev1.ConfigMap, + checkLagoonEnv bool, buildCondition lagooncrd.BuildStatusType, buildStep string, ) { @@ -331,15 +316,12 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask( msg.Meta.Services = serviceNames msg.Meta.EnvironmentServices = services } - // if we aren't being provided the lagoon config, we can skip adding the routes etc - if lagoonEnv != nil { - msg.Meta.Route = "" - if route, ok := lagoonEnv.Data["LAGOON_ROUTE"]; ok { + if checkLagoonEnv { + lagoonEnv, route, routes := helpers.GetLagoonEnvRoutes(ctx, opLog, r.Client, lagoonBuild.ObjectMeta.Namespace) + // if we aren't being provided the lagoon config, we can skip adding the routes etc + if lagoonEnv { msg.Meta.Route = route - } - msg.Meta.Routes = []string{} - if routes, ok := lagoonEnv.Data["LAGOON_ROUTES"]; ok { - msg.Meta.Routes = strings.Split(routes, ",") + msg.Meta.Routes = routes } } if buildCondition.ToLower() == "failed" || buildCondition.ToLower() == "complete" || buildCondition.ToLower() == "cancelled" { @@ -361,9 +343,9 @@ func (r *LagoonBuildReconciler) updateDeploymentAndEnvironmentTask( // buildStatusLogsToLagoonLogs sends the logs to lagoon-logs message queue, used for general messaging func (r *LagoonBuildReconciler) buildStatusLogsToLagoonLogs( + ctx context.Context, opLog logr.Logger, lagoonBuild *lagooncrd.LagoonBuild, - lagoonEnv *corev1.ConfigMap, buildCondition lagooncrd.BuildStatusType, buildStep string, ) { @@ -388,16 +370,11 @@ func (r *LagoonBuildReconciler) buildStatusLogsToLagoonLogs( buildCondition.ToLower(), ), } + lagoonEnv, route, routes := helpers.GetLagoonEnvRoutes(ctx, opLog, r.Client, lagoonBuild.ObjectMeta.Namespace) // if we aren't being provided the lagoon config, we can skip adding the routes etc - if lagoonEnv != nil { - msg.Meta.Route = "" - if route, ok := lagoonEnv.Data["LAGOON_ROUTE"]; ok { - msg.Meta.Route = route - } - msg.Meta.Routes = []string{} - if routes, ok := lagoonEnv.Data["LAGOON_ROUTES"]; ok { - msg.Meta.Routes = strings.Split(routes, ",") - } + if lagoonEnv { + msg.Meta.Route = route + msg.Meta.Routes = routes } msgBytes, err := json.Marshal(msg) if err != nil { diff --git a/internal/controllers/v1beta2/build_helpers.go b/internal/controllers/v1beta2/build_helpers.go index ce8b6929..6758b208 100644 --- a/internal/controllers/v1beta2/build_helpers.go +++ b/internal/controllers/v1beta2/build_helpers.go @@ -279,22 +279,6 @@ func (r *LagoonBuildReconciler) getCreateOrUpdateSSHKeySecret(ctx context.Contex return nil } -func (r *LagoonBuildReconciler) getOrCreateConfigMap(ctx context.Context, cmName string, configMap *corev1.ConfigMap, ns string) error { - err := r.Get(ctx, types.NamespacedName{ - Namespace: ns, - Name: cmName, - }, configMap) - if err != nil { - configMap.SetNamespace(ns) - configMap.SetName(cmName) - //we create it - if err = r.Create(ctx, configMap); err != nil { - return fmt.Errorf("there was an error creating the configmap '%v'. Error was: %v", cmName, err) - } - } - return nil -} - // processBuild will actually process the build. func (r *LagoonBuildReconciler) processBuild(ctx context.Context, opLog logr.Logger, lagoonBuild lagooncrd.LagoonBuild) error { // we run these steps again just to be sure that it gets updated/created if it hasn't already @@ -905,30 +889,15 @@ func (r *LagoonBuildReconciler) updateQueuedBuild( %s ======================================== `, fmt.Sprintf("This build is currently queued in position %v/%v", queuePosition, queueLength))) - // get the configmap for lagoon-env so we can use it for updating the deployment in lagoon - var lagoonEnv corev1.ConfigMap - err := r.Get(ctx, types.NamespacedName{ - Namespace: lagoonBuild.ObjectMeta.Namespace, - Name: "lagoon-env", - }, - &lagoonEnv, - ) - if err != nil { - // if there isn't a configmap, just info it and move on - // the updatedeployment function will see it as nil and not bother doing the bits that require the configmap - if r.EnableDebug { - opLog.Info(fmt.Sprintf("There is no configmap %s in namespace %s ", "lagoon-env", lagoonBuild.ObjectMeta.Namespace)) - } - } // send any messages to lagoon message queues // update the deployment with the status, lagoon v2.12.0 supports queued status, otherwise use pending if lagooncrd.CheckLagoonVersion(&lagoonBuild, "2.12.0") { - r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) - r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) + r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, lagooncrd.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) + r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, true, lagooncrd.BuildStatusQueued, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagooncrd.BuildStatusQueued) } else { - r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) - r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) + r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, lagooncrd.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) + r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, true, lagooncrd.BuildStatusPending, fmt.Sprintf("queued %v/%v", queuePosition, queueLength)) r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagooncrd.BuildStatusPending) } return nil @@ -964,25 +933,10 @@ Build cancelled opLog.Error(err, "Unable to update build status") } } - // get the configmap for lagoon-env so we can use it for updating the deployment in lagoon - var lagoonEnv corev1.ConfigMap - err := r.Get(ctx, types.NamespacedName{ - Namespace: lagoonBuild.ObjectMeta.Namespace, - Name: "lagoon-env", - }, - &lagoonEnv, - ) - if err != nil { - // if there isn't a configmap, just info it and move on - // the updatedeployment function will see it as nil and not bother doing the bits that require the configmap - if r.EnableDebug { - opLog.Info(fmt.Sprintf("There is no configmap %s in namespace %s ", "lagoon-env", lagoonBuild.ObjectMeta.Namespace)) - } - } // send any messages to lagoon message queues // update the deployment with the status of cancelled in lagoon - r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusCancelled, "cancelled") - r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &lagoonEnv, lagooncrd.BuildStatusCancelled, "cancelled") + r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, lagooncrd.BuildStatusCancelled, "cancelled") + r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, true, lagooncrd.BuildStatusCancelled, "cancelled") if cancelled { r.buildLogsToLagoonLogs(opLog, &lagoonBuild, allContainerLogs, lagooncrd.BuildStatusCancelled) } diff --git a/internal/controllers/v1beta2/podmonitor_buildhandlers.go b/internal/controllers/v1beta2/podmonitor_buildhandlers.go index 51fb6698..224b2626 100644 --- a/internal/controllers/v1beta2/podmonitor_buildhandlers.go +++ b/internal/controllers/v1beta2/podmonitor_buildhandlers.go @@ -88,16 +88,6 @@ func (r *LagoonMonitorReconciler) handleBuildMonitor(ctx context.Context, } jobPod.Status.ContainerStatuses[0] = state - // get the configmap for lagoon-env so we can use it for updating the deployment in lagoon - var lagoonEnv corev1.ConfigMap - err := r.Get(ctx, types.NamespacedName{Namespace: jobPod.ObjectMeta.Namespace, Name: "lagoon-env"}, &lagoonEnv) - if err != nil { - // if there isn't a configmap, just info it and move on - // the updatedeployment function will see it as nil and not bother doing the bits that require the configmap - if r.EnableDebug { - opLog.Info(fmt.Sprintf("There is no configmap %s in namespace %s ", "lagoon-env", jobPod.ObjectMeta.Namespace)) - } - } // send any messages to lagoon message queues logMsg := fmt.Sprintf("%v: %v", container.State.Waiting.Reason, container.State.Waiting.Message) return r.updateDeploymentWithLogs(ctx, req, lagoonBuild, jobPod, []byte(logMsg), false) @@ -230,10 +220,10 @@ Logs on pod %s, assigned to cluster %s // updateDeploymentAndEnvironmentTask sends the status of the build and deployment to the controllerhandler message queue in lagoon, // this is for the handler in lagoon to process. func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask( + ctx context.Context, opLog logr.Logger, lagoonBuild *lagooncrd.LagoonBuild, jobPod *corev1.Pod, - lagoonEnv *corev1.ConfigMap, namespace *corev1.Namespace, condition string, ) error { @@ -323,16 +313,11 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask( msg.Meta.Services = serviceNames msg.Meta.EnvironmentServices = services } + lagoonEnv, route, routes := helpers.GetLagoonEnvRoutes(ctx, opLog, r.Client, lagoonBuild.ObjectMeta.Namespace) // if we aren't being provided the lagoon config, we can skip adding the routes etc - if lagoonEnv != nil { - msg.Meta.Route = "" - if route, ok := lagoonEnv.Data["LAGOON_ROUTE"]; ok { - msg.Meta.Route = route - } - msg.Meta.Routes = []string{} - if routes, ok := lagoonEnv.Data["LAGOON_ROUTES"]; ok { - msg.Meta.Routes = strings.Split(routes, ",") - } + if lagoonEnv { + msg.Meta.Route = route + msg.Meta.Routes = routes } // we can add the build start time here if jobPod.Status.StartTime != nil { @@ -375,10 +360,10 @@ func (r *LagoonMonitorReconciler) updateDeploymentAndEnvironmentTask( // buildStatusLogsToLagoonLogs sends the logs to lagoon-logs message queue, used for general messaging func (r *LagoonMonitorReconciler) buildStatusLogsToLagoonLogs( + ctx context.Context, opLog logr.Logger, lagoonBuild *lagooncrd.LagoonBuild, jobPod *corev1.Pod, - lagoonEnv *corev1.ConfigMap, namespace *corev1.Namespace, condition string, ) error { @@ -422,17 +407,13 @@ func (r *LagoonMonitorReconciler) buildStatusLogsToLagoonLogs( } // if we aren't being provided the lagoon config, we can skip adding the routes etc var addRoute, addRoutes string - if lagoonEnv != nil { - msg.Meta.Route = "" - if route, ok := lagoonEnv.Data["LAGOON_ROUTE"]; ok { - msg.Meta.Route = route - addRoute = fmt.Sprintf("\n%s", route) - } - msg.Meta.Routes = []string{} - if routes, ok := lagoonEnv.Data["LAGOON_ROUTES"]; ok { - msg.Meta.Routes = strings.Split(routes, ",") - addRoutes = fmt.Sprintf("\n%s", strings.Join(strings.Split(routes, ","), "\n")) - } + lagoonEnv, route, routes := helpers.GetLagoonEnvRoutes(ctx, opLog, r.Client, lagoonBuild.ObjectMeta.Namespace) + // if we aren't being provided the lagoon config, we can skip adding the routes etc + if lagoonEnv { + msg.Meta.Route = route + addRoute = fmt.Sprintf("\n%s", route) + msg.Meta.Routes = routes + addRoutes = fmt.Sprintf("\n%s", strings.Join(routes, "\n")) } msg.Message = fmt.Sprintf("*[%s]* `%s` Build `%s` %s <%s|Logs>%s%s", projectName, @@ -560,26 +541,12 @@ Build %s "conditions": lagoonBuild.Status.Conditions, "phase": buildCondition.String(), } - // get the configmap for lagoon-env so we can use it for updating the deployment in lagoon - var lagoonEnv corev1.ConfigMap - if err := r.Get(ctx, types.NamespacedName{ - Namespace: jobPod.ObjectMeta.Namespace, - Name: "lagoon-env", - }, - &lagoonEnv, - ); err != nil { - // if there isn't a configmap, just info it and move on - // the updatedeployment function will see it as nil and not bother doing the bits that require the configmap - if r.EnableDebug { - opLog.Info(fmt.Sprintf("There is no configmap %s in namespace %s ", "lagoon-env", jobPod.ObjectMeta.Namespace)) - } - } // do any message publishing here, and update any pending messages if needed - if err = r.buildStatusLogsToLagoonLogs(opLog, &lagoonBuild, &jobPod, &lagoonEnv, namespace, buildCondition.ToLower()); err != nil { + if err = r.buildStatusLogsToLagoonLogs(ctx, opLog, &lagoonBuild, &jobPod, namespace, buildCondition.ToLower()); err != nil { opLog.Error(err, "unable to publish build status logs") } - if err = r.updateDeploymentAndEnvironmentTask(opLog, &lagoonBuild, &jobPod, &lagoonEnv, namespace, buildCondition.ToLower()); err != nil { + if err = r.updateDeploymentAndEnvironmentTask(ctx, opLog, &lagoonBuild, &jobPod, namespace, buildCondition.ToLower()); err != nil { opLog.Error(err, "unable to publish build update") } // if the container logs can't be retrieved, we don't want to send any build logs back, as this will nuke diff --git a/internal/controllers/v1beta2/task_controller.go b/internal/controllers/v1beta2/task_controller.go index 6eea9829..8bd05909 100644 --- a/internal/controllers/v1beta2/task_controller.go +++ b/internal/controllers/v1beta2/task_controller.go @@ -568,21 +568,67 @@ func (r *LagoonTaskReconciler) createAdvancedTask(ctx context.Context, lagoonTas Name: "lagoon-task", Image: lagoonTask.Spec.AdvancedTask.RunnerImage, ImagePullPolicy: "Always", - EnvFrom: []corev1.EnvFromSource{ - { - ConfigMapRef: &corev1.ConfigMapEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "lagoon-env", - }, - }, - }, - }, - Env: podEnvs, - VolumeMounts: volumeMounts, + Env: podEnvs, + VolumeMounts: volumeMounts, }, }, }, } + // check if the lagoon-env secret(s) exist and mount them to the pod as required, or fall back to the configmap + lagoonEnvSecret := &corev1.Secret{} + err := r.Get(ctx, types.NamespacedName{ + Namespace: lagoonTask.ObjectMeta.Namespace, + Name: "lagoon-env", + }, lagoonEnvSecret) + if err != nil { + // fall back to check if the lagoon-env configmap exists + lagoonEnvConfigMap := &corev1.ConfigMap{} + err := r.Get(ctx, types.NamespacedName{ + Namespace: lagoonTask.ObjectMeta.Namespace, + Name: "lagoon-env", + }, lagoonEnvConfigMap) + if err != nil { + // just log the warning + opLog.Info(fmt.Sprintf("no lagoon-env secret or configmap %s", lagoonTask.ObjectMeta.Namespace)) + } else { + // add the lagoon-env configmap to the storage-calculator pod + newPod.Spec.Containers[0].EnvFrom = append(newPod.Spec.Containers[0].EnvFrom, corev1.EnvFromSource{ + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-env", + }, + }, + }) + } + } else { + // else check the platform env secret exists + lagoonPlatformEnvSecret := &corev1.Secret{} + err := r.Get(ctx, types.NamespacedName{ + Namespace: lagoonTask.ObjectMeta.Namespace, + Name: "lagoon-platform-env", + }, lagoonPlatformEnvSecret) + if err != nil { + // just log the warning + opLog.Info(fmt.Sprintf("no lagoon-platform-env secret %s", lagoonTask.ObjectMeta.Namespace)) + } else { + // add the lagoon-platform-env secret to the storage-calculator pod + newPod.Spec.Containers[0].EnvFrom = append(newPod.Spec.Containers[0].EnvFrom, corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-platform-env", + }, + }, + }) + } + // add the lagoon-env secret to the storage-calculator pod + newPod.Spec.Containers[0].EnvFrom = append(newPod.Spec.Containers[0].EnvFrom, corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "lagoon-env", + }, + }, + }) + } if lagoonTask.Spec.Project.Organization != nil { newPod.ObjectMeta.Labels["organization.lagoon.sh/id"] = fmt.Sprintf("%d", *lagoonTask.Spec.Project.Organization.ID) newPod.ObjectMeta.Labels["organization.lagoon.sh/name"] = lagoonTask.Spec.Project.Organization.Name diff --git a/internal/helpers/helpers.go b/internal/helpers/helpers.go index 9a57f6a7..f4f4f19f 100644 --- a/internal/helpers/helpers.go +++ b/internal/helpers/helpers.go @@ -1,6 +1,7 @@ package helpers import ( + "context" "crypto/sha1" "crypto/sha256" "encoding/base32" @@ -12,12 +13,16 @@ import ( "strings" "time" + "github.com/go-logr/logr" "golang.org/x/text/cases" "golang.org/x/text/language" + corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/validation/field" + "sigs.k8s.io/controller-runtime/pkg/client" ) const ( @@ -318,3 +323,43 @@ func TaskStepToStatusCondition(c string, t time.Time) metav1.Condition { LastTransitionTime: metav1.NewTime(t), } } + +// there is currently no reason to check the `lagoon-platform-env` secret, just the lagoon-env configmap or lagoon-env secret +// as it contains values that are provided back to the API at the completion of a build/buildstep +func GetLagoonEnvRoutes(ctx context.Context, opLog logr.Logger, c client.Client, namespace string) (bool, string, []string) { + var route string + var routes []string + lagoonEnvSecret := &corev1.Secret{} + err := c.Get(ctx, types.NamespacedName{ + Namespace: namespace, + Name: "lagoon-env", + }, lagoonEnvSecret) + if err != nil { + // fall back to check if the lagoon-env configmap exists + lagoonEnvConfigMap := &corev1.ConfigMap{} + err := c.Get(ctx, types.NamespacedName{ + Namespace: namespace, + Name: "lagoon-env", + }, lagoonEnvConfigMap) + if err != nil { + // just log the warning + opLog.Info(fmt.Sprintf("no lagoon-env secret or configmap in namespace %s", namespace)) + return false, "", nil + } else { + if r, ok := lagoonEnvConfigMap.Data["LAGOON_ROUTE"]; ok { + route = r + } + if rs, ok := lagoonEnvConfigMap.Data["LAGOON_ROUTES"]; ok { + routes = strings.Split(rs, ",") + } + return true, route, routes + } + } + if r, ok := lagoonEnvSecret.Data["LAGOON_ROUTE"]; ok { + route = string(r) + } + if rs, ok := lagoonEnvSecret.Data["LAGOON_ROUTES"]; ok { + routes = strings.Split(string(rs), ",") + } + return true, route, routes +}