Skip to content

Commit

Permalink
Split Management reconcile into Update and Delete
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Pavlov <[email protected]>
  • Loading branch information
Kshatrix committed Aug 8, 2024
1 parent 56b844c commit 7675a90
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions internal/controller/management_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,29 @@ type ManagementReconciler struct {

func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
l := log.FromContext(ctx).WithValues("ManagementController", req.NamespacedName)
log.IntoContext(ctx, l)
l.Info("Reconciling Management")

management := &hmc.Management{}
if err := r.Get(ctx, req.NamespacedName, management); err != nil {
if apierrors.IsNotFound(err) {
l.Info("Management config not found, ignoring since object must be deleted")
l.Info("Management not found, ignoring since object must be deleted")
return ctrl.Result{}, nil
}
l.Error(err, "Failed to get Management")
return ctrl.Result{}, err
}

if !management.DeletionTimestamp.IsZero() {
l.Info("Deleting Management")
return r.Delete(ctx, management)
}

return r.Update(ctx, management)
}

func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Management) (ctrl.Result, error) {
l := log.FromContext(ctx)

finalizersUpdated := controllerutil.AddFinalizer(management, hmc.ManagementFinalizer)
if finalizersUpdated {
if err := r.Client.Update(ctx, management); err != nil {
Expand Down Expand Up @@ -132,6 +143,10 @@ func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, nil
}

func (r *ManagementReconciler) Delete(_ context.Context, _ *hmc.Management) (ctrl.Result, error) {
return ctrl.Result{}, nil
}

type component struct {
hmc.Component
// helm release dependencies
Expand Down

0 comments on commit 7675a90

Please sign in to comment.