diff --git a/controllers/v1beta1/build_controller.go b/controllers/v1beta1/build_controller.go index db1f608c..62d84355 100644 --- a/controllers/v1beta1/build_controller.go +++ b/controllers/v1beta1/build_controller.go @@ -120,6 +120,7 @@ func (r *LagoonBuildReconciler) Reconcile(ctx context.Context, req ctrl.Request) // examine DeletionTimestamp to determine if object is under deletion if lagoonBuild.ObjectMeta.DeletionTimestamp.IsZero() { + // if the build isn't being deleted, but the status is cancelled // then clean up the undeployable build if value, ok := lagoonBuild.ObjectMeta.Labels["lagoon.sh/buildStatus"]; ok { @@ -162,10 +163,33 @@ func (r *LagoonBuildReconciler) Reconcile(ctx context.Context, req ctrl.Request) } // end check if running build is current LagoonBuild } // end loop for running builds // once running builds are processed, run the qos handler - return r.qosBuildProcessor(ctx, opLog, lagoonBuild, req) + result, err := r.qosBuildProcessor(ctx, opLog, lagoonBuild, req) + if err != nil { + return result, err + } + } else { + // if qos is not enabled, just process it as a standard build + result, err := r.standardBuildProcessor(ctx, opLog, lagoonBuild, req) + if err != nil { + return result, err + } + } + // with the introduction of v1beta2, this will let any existing pending/qeued/running builds continue through + // but once the build is completed or failed and has processed anything else it needs to do, it should delete the resource + if _, ok := lagoonBuild.Labels["lagoon.sh/buildStatus"]; ok { + if !helpers.ContainsString( + lagoonv1beta1.BuildRunningPendingStatus, + lagoonBuild.Labels["lagoon.sh/buildStatus"], + ) { + opLog.Info(fmt.Sprintf("%s found in namespace %s is no longer required, removing it. v1beta1 is deprecated in favor of v1beta2", + lagoonBuild.ObjectMeta.Name, + req.NamespacedName.Namespace, + )) + if err := r.Delete(ctx, &lagoonBuild); err != nil { + return ctrl.Result{}, err + } + } } - // if qos is not enabled, just process it as a standard build - return r.standardBuildProcessor(ctx, opLog, lagoonBuild, req) } // The object is being deleted if helpers.ContainsString(lagoonBuild.ObjectMeta.Finalizers, buildFinalizer) { diff --git a/controllers/v1beta1/task_controller.go b/controllers/v1beta1/task_controller.go index 7e34e126..a87affc5 100644 --- a/controllers/v1beta1/task_controller.go +++ b/controllers/v1beta1/task_controller.go @@ -71,11 +71,33 @@ func (r *LagoonTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) // check if the task that has been recieved is a standard or advanced task if lagoonTask.ObjectMeta.Labels["lagoon.sh/taskStatus"] == lagoonv1beta1.TaskStatusPending.String() && lagoonTask.ObjectMeta.Labels["lagoon.sh/taskType"] == lagoonv1beta1.TaskTypeStandard.String() { - return ctrl.Result{}, r.createStandardTask(ctx, &lagoonTask, opLog) + err := r.createStandardTask(ctx, &lagoonTask, opLog) + if err != nil { + return ctrl.Result{}, err + } } if lagoonTask.ObjectMeta.Labels["lagoon.sh/taskStatus"] == lagoonv1beta1.TaskStatusPending.String() && lagoonTask.ObjectMeta.Labels["lagoon.sh/taskType"] == lagoonv1beta1.TaskTypeAdvanced.String() { - return ctrl.Result{}, r.createAdvancedTask(ctx, &lagoonTask, opLog) + err := r.createAdvancedTask(ctx, &lagoonTask, opLog) + if err != nil { + return ctrl.Result{}, err + } + } + // with the introduction of v1beta2, this will let any existing tasks continue through + // but once the task is done + if _, ok := lagoonTask.Labels["lagoon.sh/taskStatus"]; ok { + if !helpers.ContainsString( + lagoonv1beta1.TaskRunningPendingStatus, + lagoonTask.Labels["lagoon.sh/taskStatus"], + ) { + opLog.Info(fmt.Sprintf("%s found in namespace %s is no longer required, removing it. v1alpha1 is deprecated in favor of v1beta1", + lagoonTask.ObjectMeta.Name, + req.NamespacedName.Namespace, + )) + if err := r.Delete(ctx, &lagoonTask); err != nil { + return ctrl.Result{}, err + } + } } } else { // The object is being deleted diff --git a/controllers/v1beta2/build_controller.go b/controllers/v1beta2/build_controller.go index a5dc9481..de1ecab6 100644 --- a/controllers/v1beta2/build_controller.go +++ b/controllers/v1beta2/build_controller.go @@ -323,6 +323,7 @@ func (r *LagoonBuildReconciler) getOrCreateBuildResource(ctx context.Context, la map[string]string{ "lagoon.sh/buildStatus": lagooncrd.BuildStatusPending.String(), "lagoon.sh/controller": r.ControllerNamespace, + "crd.lagoon.sh/version": crdVersion, }, ) err := r.Get(ctx, types.NamespacedName{