Skip to content

Commit 1cbfcec

Browse files
authored
Don't reconcile RBAC for namespaces in deletion (#100)
1 parent 62921b6 commit 1cbfcec

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

controllers/org_rbac_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (r *OrganizationRBACReconciler) Reconcile(ctx context.Context, req ctrl.Req
5555
return ctrl.Result{}, client.IgnoreNotFound(err)
5656
}
5757

58+
if ns.DeletionTimestamp != nil {
59+
l.Info("namespace is being deleted, skipping reconciliation")
60+
return ctrl.Result{}, nil
61+
}
62+
5863
org := r.getOrganization(ns)
5964
if org == "" {
6065
return ctrl.Result{}, nil

controllers/org_rbac_controller_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"strings"
7+
"time"
78

89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
@@ -50,8 +51,9 @@ func TestOrganizationRBACReconciler(t *testing.T) {
5051
fail bool
5152
events int
5253

53-
namespace string
54-
nsLabels map[string]string
54+
namespace string
55+
nsLabels map[string]string
56+
nsDeleting bool
5557

5658
roleBindings []rb
5759
expected []rb
@@ -82,6 +84,14 @@ func TestOrganizationRBACReconciler(t *testing.T) {
8284
orgLabel: "foo",
8385
},
8486
},
87+
"NamespaceInDeletion_Noop": {
88+
clusterRoles: defaultCRs,
89+
namespace: "buzz",
90+
nsDeleting: true,
91+
nsLabels: map[string]string{
92+
orgLabel: "foo",
93+
},
94+
},
8595
"NoRbacCreationFalseOrgNs_CreateRole": {
8696
clusterRoles: defaultCRs,
8797
namespace: "buzz",
@@ -282,12 +292,18 @@ func TestOrganizationRBACReconciler(t *testing.T) {
282292
for name, tc := range tcs {
283293

284294
obj := []client.Object{}
285-
obj = append(obj, &corev1.Namespace{
295+
ns := &corev1.Namespace{
286296
ObjectMeta: metav1.ObjectMeta{
287297
Name: tc.namespace,
288298
Labels: tc.nsLabels,
289299
},
290-
})
300+
}
301+
if tc.nsDeleting {
302+
t := metav1.NewTime(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC))
303+
ns.DeletionTimestamp = &t
304+
ns.Finalizers = append(ns.Finalizers, "test.appuio.io")
305+
}
306+
obj = append(obj, ns)
291307

292308
for _, rb := range tc.roleBindings {
293309
subs := []rbacv1.Subject{}

0 commit comments

Comments
 (0)