diff --git a/controllers/v1beta1/build_controller.go b/controllers/v1beta1/build_controller.go index db1f608c..736c9e84 100644 --- a/controllers/v1beta1/build_controller.go +++ b/controllers/v1beta1/build_controller.go @@ -135,6 +135,24 @@ func (r *LagoonBuildReconciler) Reconcile(ctx context.Context, req ctrl.Request) } } } + + // 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.BuildCompletedCancelledFailedStatus, + 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 r.LFFQoSEnabled { // handle QoS builds here // if we do have a `lagoon.sh/buildStatus` set as running, then process it diff --git a/controllers/v1beta1/task_controller.go b/controllers/v1beta1/task_controller.go index 7e34e126..bcb0eb41 100644 --- a/controllers/v1beta1/task_controller.go +++ b/controllers/v1beta1/task_controller.go @@ -68,6 +68,22 @@ func (r *LagoonTaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) // examine DeletionTimestamp to determine if object is under deletion if lagoonTask.ObjectMeta.DeletionTimestamp.IsZero() { + // 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.TaskCompletedCancelledFailedStatus, + 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 + } + } + } // 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() { 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{