Improvements per review
This commit is contained in:
parent
903902933f
commit
43a0449c8f
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) generatePlan(event ClusterEvent) []cluster.Action {
|
||||
return util.NameFromMeta(event.OldSpec.ObjectMeta)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue