diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 3157132b2..1055b795d 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -1143,7 +1143,7 @@ func (c *Cluster) initHumanUsers() error { var clusterIsOwnedBySuperuserTeam bool superuserTeams := []string{} - if c.OpConfig.EnablePostgresTeamCRDSuperusers { + if c.OpConfig.EnablePostgresTeamCRD && c.OpConfig.EnablePostgresTeamCRDSuperusers && c.Config.PgTeamMap != nil { superuserTeams = c.Config.PgTeamMap.GetAdditionalSuperuserTeams(c.Spec.TeamID, true) } @@ -1163,7 +1163,7 @@ func (c *Cluster) initHumanUsers() error { } } - if c.Config.PgTeamMap != nil { + if c.OpConfig.EnablePostgresTeamCRD && c.Config.PgTeamMap != nil { additionalTeams := c.Config.PgTeamMap.GetAdditionalTeams(c.Spec.TeamID, true) for _, additionalTeam := range additionalTeams { if !(util.SliceContains(superuserTeams, additionalTeam)) { diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 0c29275e6..f992ff782 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -329,10 +329,9 @@ func (c *Controller) initController() { c.initSharedInformers() + c.pgTeamMap = teams.PostgresTeamMap{} if c.opConfig.EnablePostgresTeamCRD { c.loadPostgresTeams() - } else { - c.pgTeamMap = teams.PostgresTeamMap{} } if c.opConfig.DebugLogging { diff --git a/pkg/controller/util.go b/pkg/controller/util.go index 8c8fcf223..8aa891c09 100644 --- a/pkg/controller/util.go +++ b/pkg/controller/util.go @@ -15,7 +15,6 @@ import ( acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1" "github.com/zalando/postgres-operator/pkg/cluster" "github.com/zalando/postgres-operator/pkg/spec" - "github.com/zalando/postgres-operator/pkg/teams" "github.com/zalando/postgres-operator/pkg/util" "github.com/zalando/postgres-operator/pkg/util/config" "github.com/zalando/postgres-operator/pkg/util/k8sutil" @@ -395,9 +394,6 @@ func (c *Controller) getInfrastructureRole( } func (c *Controller) loadPostgresTeams() { - // reset team map - c.pgTeamMap = teams.PostgresTeamMap{} - pgTeams, err := c.KubeClient.PostgresTeamsGetter.PostgresTeams(c.opConfig.WatchedNamespace).List(context.TODO(), metav1.ListOptions{}) if err != nil { c.logger.Errorf("could not list postgres team objects: %v", err) diff --git a/pkg/teams/postgres_team.go b/pkg/teams/postgres_team.go index 3ebbc55aa..b0a7b3027 100644 --- a/pkg/teams/postgres_team.go +++ b/pkg/teams/postgres_team.go @@ -8,8 +8,6 @@ import ( // PostgresTeamMap is the operator's internal representation of all PostgresTeam CRDs type PostgresTeamMap map[string]*postgresTeamMembership -var emptyTeamMap = make(PostgresTeamMap, 0) - type postgresTeamMembership struct { AdditionalSuperuserTeams []string AdditionalTeams []string @@ -96,9 +94,8 @@ func (ptm *PostgresTeamMap) GetAdditionalSuperuserTeams(team string, transitive // Load function to import data from PostgresTeam CRD func (ptm *PostgresTeamMap) Load(pgTeams *acidv1.PostgresTeamList) { - if ptm == nil { - ptm = &emptyTeamMap - } + var emptyTeamMap = make(PostgresTeamMap, 0) + *ptm = emptyTeamMap superuserTeamSet := teamHashSet{} teamSet := teamHashSet{}