Adding exists requirement to avoid pruning tenant owner resources (#29)

* Adding exists requirement to avoid pruning tenant owner resources

* Restoring useful Makefile commands (fixing 5d20d51)
This commit is contained in:
Dario Tranchitella
2020-08-04 16:45:44 +02:00
committed by GitHub
parent 5d20d515a7
commit ee0a238b7f
2 changed files with 18 additions and 4 deletions
+10
View File
@@ -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
+8 -4
View File
@@ -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{},