Minor fixes around PDB (pod-distruption-budget) syncing: (#147)

- Call comparison function in the case of the sync as well as for update
- Include full cluster name in PDB name
- Assign cluster labels to the PDB object
This commit is contained in:
Oleksii Kliukin 2017-10-23 12:26:59 +02:00 committed by Murat Kabilov
parent c17aabb642
commit 7a76be7d3e
3 changed files with 15 additions and 16 deletions

View File

@ -536,14 +536,10 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error {
c.logger.Infof("volumes have been updated successfully")
}
newPDB := c.generatePodDisruptionBudget()
if match, reason := c.samePDBWith(newPDB); !match {
c.logPDBChanges(c.PodDisruptionBudget, newPDB, true, reason)
if err := c.updatePodDisruptionBudget(newPDB); err != nil {
if err := c.syncPodDisruptionBudget(true); err != nil {
c.setStatus(spec.ClusterStatusUpdateFailed)
return fmt.Errorf("could not update pod disruption budget: %v", err)
}
}
c.setStatus(spec.ClusterStatusRunning)

View File

@ -69,7 +69,7 @@ func (c *Cluster) serviceName(role PostgresRole) string {
}
func (c *Cluster) podDisruptionBudgetName() string {
return c.OpConfig.PDBNameFormat.Format("cluster", c.Spec.ClusterName)
return c.OpConfig.PDBNameFormat.Format("cluster", c.Name)
}
func (c *Cluster) resourceRequirements(resources spec.Resources) (*v1.ResourceRequirements, error) {
@ -605,6 +605,7 @@ func (c *Cluster) generatePodDisruptionBudget() *policybeta1.PodDisruptionBudget
ObjectMeta: metav1.ObjectMeta{
Name: c.podDisruptionBudgetName(),
Namespace: c.Namespace,
Labels: c.labelsSet(),
},
Spec: policybeta1.PodDisruptionBudgetSpec{
MinAvailable: &minAvailable,

View File

@ -99,7 +99,7 @@ func (c *Cluster) Sync(newSpec *spec.Postgresql) (err error) {
}
c.logger.Debug("syncing pod disruption budgets")
if err = c.syncPodDisruptionBudget(); err != nil {
if err = c.syncPodDisruptionBudget(false); err != nil {
err = fmt.Errorf("could not sync pod disruption budget: %v", err)
return
}
@ -149,7 +149,7 @@ func (c *Cluster) syncEndpoint() error {
return nil
}
func (c *Cluster) syncPodDisruptionBudget() error {
func (c *Cluster) syncPodDisruptionBudget(isUpdate bool) error {
if c.PodDisruptionBudget == nil {
c.logger.Infof("could not find the cluster's pod disruption budget")
pdb, err := c.createPodDisruptionBudget()
@ -158,8 +158,15 @@ func (c *Cluster) syncPodDisruptionBudget() error {
}
c.logger.Infof("created missing pod disruption budget %q", util.NameFromMeta(pdb.ObjectMeta))
return nil
} else {
newPDB := c.generatePodDisruptionBudget()
if match, reason := c.samePDBWith(newPDB); !match {
c.logPDBChanges(c.PodDisruptionBudget, newPDB, isUpdate, reason)
if err := c.updatePodDisruptionBudget(newPDB); err != nil {
return err
}
}
}
return nil
}
@ -278,11 +285,6 @@ func (c *Cluster) syncVolumes() error {
}
func (c *Cluster) samePDBWith(pdb *policybeta1.PodDisruptionBudget) (match bool, reason string) {
if c.PodDisruptionBudget == nil {
match = false
reason = "pdb does not exist"
return
}
match = reflect.DeepEqual(pdb.Spec, c.PodDisruptionBudget.Spec)
if !match {
reason = "new service spec doesn't match the current one"