Skip to content

Commit 647a4d3

Browse files
authored
Remove service accounts cache (zalando#685)
For optimization purposes operator was creating a cache map to remember if service accounts and role binding was deployed to a namespace. This could lead to a problem, when a namespace was deleted, since this cache was not synchronized. For the sake of correctness remove the cache, and check every time if required service account and rbac is present. In the normal case this introduces an overhead of two API calls per an event (one to get a service accounts, one to get a role binding), which should not be a problem, unless proven otherwise.
1 parent e3b39a5 commit 647a4d3

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

pkg/controller/controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ type Controller struct {
5858

5959
PodServiceAccount *v1.ServiceAccount
6060
PodServiceAccountRoleBinding *rbacv1beta1.RoleBinding
61-
namespacesWithDefinedRBAC sync.Map
6261
}
6362

6463
// NewController creates a new controller

pkg/controller/postgresql.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,16 @@ func (c *Controller) postgresqlDelete(obj interface{}) {
493493
}
494494

495495
/*
496-
Ensures the pod service account and role bindings exists in a namespace before a PG cluster is created there so that a user does not have to deploy these credentials manually.
497-
StatefulSets require the service account to create pods; Patroni requires relevant RBAC bindings to access endpoints.
496+
Ensures the pod service account and role bindings exists in a namespace
497+
before a PG cluster is created there so that a user does not have to deploy
498+
these credentials manually. StatefulSets require the service account to
499+
create pods; Patroni requires relevant RBAC bindings to access endpoints.
498500
499501
The operator does not sync accounts/role bindings after creation.
500502
*/
501503
func (c *Controller) submitRBACCredentials(event ClusterEvent) error {
502504

503505
namespace := event.NewSpec.GetNamespace()
504-
if _, ok := c.namespacesWithDefinedRBAC.Load(namespace); ok {
505-
return nil
506-
}
507506

508507
if err := c.createPodServiceAccount(namespace); err != nil {
509508
return fmt.Errorf("could not create pod service account %v : %v", c.opConfig.PodServiceAccountName, err)
@@ -512,7 +511,6 @@ func (c *Controller) submitRBACCredentials(event ClusterEvent) error {
512511
if err := c.createRoleBindings(namespace); err != nil {
513512
return fmt.Errorf("could not create role binding %v : %v", c.PodServiceAccountRoleBinding.Name, err)
514513
}
515-
c.namespacesWithDefinedRBAC.Store(namespace, true)
516514
return nil
517515
}
518516

0 commit comments

Comments
 (0)