Skip to content

Commit

Permalink
add finalizer to shim resource
Browse files Browse the repository at this point in the history
  • Loading branch information
voigt committed Feb 2, 2024
1 parent 6f9997b commit f51a451
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/controller/shim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func (sr *ShimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
log.Info().Msg("No nodes found")
}

return ctrl.Result{}, nil
err = sr.ensureFinalizer(ctx, &shimResource)
return ctrl.Result{}, client.IgnoreNotFound(err)
}

// findShimsToReconcile finds all Shims that need to be reconciled.
Expand Down Expand Up @@ -557,6 +558,17 @@ func (sr *ShimReconciler) removeFinalizer(ctx context.Context, shim *kwasmv1.Shi
return nil
}

// ensureFinalizer ensures the finalizer is present on a Shim resource.
func (sr *ShimReconciler) ensureFinalizer(ctx context.Context, shim *kwasmv1.Shim) error {
if !controllerutil.ContainsFinalizer(shim, KwasmOperatorFinalizer) {
controllerutil.AddFinalizer(shim, KwasmOperatorFinalizer)
if err := sr.Client.Update(ctx, shim); err != nil {
return err
}
}
return nil
}

func ptr[T any](v T) *T {
return &v
}

0 comments on commit f51a451

Please sign in to comment.