Skip to content

Commit

Permalink
refactor: remove resources after theyve completed reconciling
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jan 24, 2024
1 parent e7e1823 commit f7e12fd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions controllers/v1beta1/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions controllers/v1beta1/task_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions controllers/v1beta2/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f7e12fd

Please sign in to comment.