Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: finalizer operations #23

Merged
merged 1 commit into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions internal/controller/pipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,23 @@ func (r *PipelineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return r.reconcileDelete(scope)
}

if !controllerutil.ContainsFinalizer(pipeline, captainv1.PipelineFinalizer) {
log.Info("adding Finalizer for pipeline")
if ok := controllerutil.AddFinalizer(pipeline, captainv1.PipelineFinalizer); !ok {
log.Error(nil, "failed to add finalizer to pipeline, requeing")
return ctrl.Result{Requeue: true}, nil
}

// add finalizer and update
// the update will trigger a new reconciliation
return ctrl.Result{}, r.Update(ctx, pipeline)
}
// handle pipeline reconcile
return r.reconcileNormal(scope)
}

// reconcileNormal handles normal reconciles
func (r *PipelineReconciler) reconcileNormal(scope *PipelineScope) (ctrl.Result, error) {
// add finalizer to the Pipeline
controllerutil.AddFinalizer(scope.Pipeline, captainv1.PipelineFinalizer)

// check if the Pipeline has already created a deployment
_, err := r.createOrUpdatePipeline(scope)
if err != nil {
Expand All @@ -96,8 +104,9 @@ func (r *PipelineReconciler) reconcileNormal(scope *PipelineScope) (ctrl.Result,
// reconcileNormal handles a deletion during the reconcile
func (r *PipelineReconciler) reconcileDelete(scope *PipelineScope) (ctrl.Result, error) {
// remove finalizer to allow the resource to be deleted
controllerutil.RemoveFinalizer(scope.Pipeline, captainv1.PipelineFinalizer)

if controllerutil.RemoveFinalizer(scope.Pipeline, captainv1.PipelineFinalizer) {
return reconcile.Result{}, r.Update(scope.Ctx, scope.Pipeline)
}
return reconcile.Result{}, nil
}

Expand Down
Loading