diff --git a/pkg/cluster/actions.go b/pkg/cluster/actions.go index b31fe7d7e..fdd77391d 100644 --- a/pkg/cluster/actions.go +++ b/pkg/cluster/actions.go @@ -9,6 +9,8 @@ import ( var NoActions []Action = []Action{} +type Plan = []Action + type MetaData struct { cluster *Cluster namespace string @@ -90,7 +92,8 @@ func (action UpdateSecret) Apply() error { user := cluster.getSecretUser(action.secretUsername) // if this secret belongs to the infrastructure role and the password has - // changed - replace it in the secret + // changed, we need to replace it in the secret. Otherwise synchronize the + // information what we've got in the memory with the data from the secret updateSecret := (user.Password != string(action.secret.Data["password"]) && user.Origin == spec.RoleOriginInfrastructure) @@ -107,8 +110,8 @@ func (action UpdateSecret) Apply() error { return fmt.Errorf(msg, action.secretUsername, err) } } else { - // for non-infrastructure role - update the role with the password from - // the secret + // for non-infrastructure role - sync the in-memory data. For that we + // need to update password for the role with the value from the secret user.Password = string(action.secret.Data["password"]) cluster.setSecretUser(action.secretUsername, user) } diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 0e06dc2e5..b352e8e93 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -200,7 +200,7 @@ func (c *Cluster) initUsers() error { return nil } -func (c *Cluster) PlanForCreate() (plan []Action) { +func (c *Cluster) PlanForCreate() (plan Plan) { if err := c.initUsers(); err != nil { c.logger.Errorf("Cannot init users: %v", err) return NoActions @@ -211,7 +211,7 @@ func (c *Cluster) PlanForCreate() (plan []Action) { } // TODO: mind the secrets of the deleted/new users -func (c *Cluster) PlanForSecrets() (plan []Action) { +func (c *Cluster) PlanForSecrets() (plan Plan) { var msg string secrets := c.generateUserSecrets() diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index ef891cae7..71fbff0b1 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -167,12 +167,12 @@ func getClusterName(event ClusterEvent) spec.NamespacedName { if hasNewName { return util.NameFromMeta(event.NewSpec.ObjectMeta) - } else { - return util.NameFromMeta(event.OldSpec.ObjectMeta) } + + return util.NameFromMeta(event.OldSpec.ObjectMeta) } -func (c *Controller) generatePlan(event ClusterEvent) []cluster.Action { +func (c *Controller) generatePlan(event ClusterEvent) cluster.Plan { var clusterName spec.NamespacedName log := c.logger.WithField("worker", event.WorkerID) @@ -191,7 +191,7 @@ func (c *Controller) generatePlan(event ClusterEvent) []cluster.Action { } } -func (c *Controller) validatePlan(plan []cluster.Action) (err error) { +func (c *Controller) validatePlan(plan cluster.Plan) (err error) { for _, action := range plan { err = action.Validate() @@ -203,7 +203,7 @@ func (c *Controller) validatePlan(plan []cluster.Action) (err error) { return nil } -func (c *Controller) applyPlan(plan []cluster.Action) (err error) { +func (c *Controller) applyPlan(plan cluster.Plan) (err error) { for _, action := range plan { err = action.Apply()