diff --git a/Makefile b/Makefile index 301ea071..f8e61ab7 100644 --- a/Makefile +++ b/Makefile @@ -116,3 +116,13 @@ bundle: manifests # Build the bundle image. bundle-build: docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . + +# Sorting imports +.PHONY: goimports +goimports: + goimports -w -l -local "github.com/clastix/capsule" . + +# Linting code as PR is expecting +.PHONY: golint +golint: + golangci-lint run diff --git a/controllers/tenant_controller.go b/controllers/tenant_controller.go index 3f4e7fdc..9e60c1c4 100644 --- a/controllers/tenant_controller.go +++ b/controllers/tenant_controller.go @@ -110,21 +110,25 @@ func (r TenantReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { } // pruningResources is taking care of removing the no more requested sub-resources as LimitRange, ResourceQuota or -// NetworkPolicy using the "notin" LabelSelector to perform an outer-join removal. +// NetworkPolicy using the "exists" and "notin" LabelSelector to perform an outer-join removal. func (r *TenantReconciler) pruningResources(ns string, keys []string, obj runtime.Object) error { capsuleLabel, err := capsulev1alpha1.GetTypeLabel(obj) if err != nil { return err } - req, err := labels.NewRequirement(capsuleLabel, selection.NotIn, keys) + exists, err := labels.NewRequirement(capsuleLabel, selection.Exists, []string{}) if err != nil { return err } - r.Log.Info("Pruning objects with label selector " + req.String()) + notIn, err := labels.NewRequirement(capsuleLabel, selection.NotIn, keys) + if err != nil { + return err + } + r.Log.Info("Pruning objects with label selector " + notIn.String()) err = retry.RetryOnConflict(retry.DefaultBackoff, func() error { return r.DeleteAllOf(context.TODO(), obj, &client.DeleteAllOfOptions{ ListOptions: client.ListOptions{ - LabelSelector: labels.NewSelector().Add(*req), + LabelSelector: labels.NewSelector().Add(*exists, *notIn), Namespace: ns, }, DeleteOptions: client.DeleteOptions{},