-
Notifications
You must be signed in to change notification settings - Fork 95
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
MGDAPI-3467 tenant deletion support #715
Conversation
ecf96b7
to
61e0c1b
Compare
12d978c
to
47764fc
Compare
Other failed checks are related to the /lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the tenant deletion support should be done at the tenant_controller.go
on the entrypoint of reconciler.
The finalizer pattern used across other controllers we are working on is:
func (r *TenantReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
reqLogger := r.Log.WithValues("tenant", req.NamespacedName)
// Fetch the Tenant instance
tenantR := &capabilitiesv1alpha1.Tenant{}
err := r.Client.Get(context.TODO(), req.NamespacedName, tenantR)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
reqLogger.Info("Tenant resource not found")
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
return ctrl.Result{}, err
}
// Tenant has been marked for deletion
if tenantR.GetDeletionTimestamp() != nil && controllerutil.ContainsFinalizer(tenantR, tenantFinalizer) {
// your deletion handling
.....
//
//Remove finalizer and update the object.
controllerutil.RemoveFinalizer(tenantR, tenantFinalizer)
err = r.Client.Update(ctx, tenantR)
logger.Info("Removing finalizer", "error", err)
return ctrl.Result{Requeue: true}, err
}
// Ignore deleted resources, this can happen when foregroundDeletion is enabled
// https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#foreground-cascading-deletion
if tenantR.GetDeletionTimestamp() != nil {
return ctrl.Result{}, nil
}
if !controllerutil.ContainsFinalizer(tenantR, tenantFinalizer) {
controllerutil.AddFinalizer(tenantR, tenantFinalizer)
err := r.Client.Update(ctx, tenantR)
logger.Info("Adding finalizer", "error", err)
return ctrl.Result{Requeue: true}, err
}
...
79b7a20
to
71bc0bb
Compare
71bc0bb
to
6d84e21
Compare
8fb7842
to
7147ee4
Compare
7147ee4
to
569e814
Compare
@eguzki hey, sorry for all the updates, I was trying to make the codeClimate a bit happier! |
@eguzki I've addressed all your comments and explained the reasoning behind having it done in a certain way in the first place, I would appreciate a review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good
I left some comments
pkg/controller/helper/tenant.go
Outdated
- tenant | ||
- portaClient | ||
*/ | ||
func DeleteTenant(tenant *capabilitiesv1alpha1.Tenant, portaClient *porta_client_pkg.ThreeScaleClient) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: this method does not add anything, does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially it could be moved, although I was thinking it would be nice to have it in a single file, I was thinking of possibility moving the tenant create here too, but happy to remove it directly if that's what you preffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Looks good I think we should tackle the issue of cascade deletion of 3scale tenant objects (DeveloperUser, DeveloperAccount, Products, Backends, ActiveDocs) in another PR. I am aware that the code coverage in the capabilites code is near to zero, but it is prepared to have tests (https://github.com/3scale/3scale-operator/blob/62f241c29eb4136e055269cf31ab7062c16e6bfa/controllers/capabilities/suite_test.go). If you are willing to add some tests, feel free. Regarding upstream doc, I think it would be nice to have a note in the capabilities doc about the new feature. Also will be used by tech writers team for the official doc. |
Code Climate has analyzed commit fa0538e and detected 2 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
good job 🎖️ |
Verification:
For RHOAM:
quay.io/austincunningham/3scale-operator:cluster-scoped
toquay.io/mstoklus/3scale-operator:v0.12.0