Skip to content

Commit

Permalink
Fix delete deployment when crd is deleted
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Milleri <[email protected]>
  • Loading branch information
lmilleri committed May 23, 2024
1 parent 2e15a63 commit 605fb31
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/controller/kbsconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ func (r *KbsConfigReconciler) deployOrUpdateKbsDeployment(ctx context.Context) e
} else {
// Deployment created successfully
r.log.Info("Created a new deployment", "Deployment.Namespace", r.namespace, "Deployment.Name", KbsDeploymentName)
return nil
// Add the kbsFinalizer to the KbsConfig if it doesn't already exist
return r.addKbsConfigFinalizer(ctx)
}
} else if err != nil {
// Unknown error
Expand All @@ -294,6 +295,10 @@ func (r *KbsConfigReconciler) deployOrUpdateKbsDeployment(ctx context.Context) e
}

// Add the kbsFinalizer to the KbsConfig if it doesn't already exist
return r.addKbsConfigFinalizer(ctx)
}

func (r *KbsConfigReconciler) addKbsConfigFinalizer(ctx context.Context) error {
if !contains(r.kbsConfig.GetFinalizers(), KbsFinalizerName) {
r.log.Info("Adding kbsFinalizer to KbsConfig")
r.kbsConfig.SetFinalizers(append(r.kbsConfig.GetFinalizers(), KbsFinalizerName))
Expand All @@ -303,9 +308,7 @@ func (r *KbsConfigReconciler) deployOrUpdateKbsDeployment(ctx context.Context) e
return err
}
}

return nil

}

// newKbsDeployment returns a new deployment for the KBS instance
Expand Down

0 comments on commit 605fb31

Please sign in to comment.