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:
parent
c17aabb642
commit
7a76be7d3e
|
|
@ -536,13 +536,9 @@ func (c *Cluster) Update(newSpec *spec.Postgresql) error {
|
||||||
c.logger.Infof("volumes have been updated successfully")
|
c.logger.Infof("volumes have been updated successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
newPDB := c.generatePodDisruptionBudget()
|
if err := c.syncPodDisruptionBudget(true); err != nil {
|
||||||
if match, reason := c.samePDBWith(newPDB); !match {
|
c.setStatus(spec.ClusterStatusUpdateFailed)
|
||||||
c.logPDBChanges(c.PodDisruptionBudget, newPDB, true, reason)
|
return fmt.Errorf("could not update pod disruption budget: %v", err)
|
||||||
if err := c.updatePodDisruptionBudget(newPDB); err != nil {
|
|
||||||
c.setStatus(spec.ClusterStatusUpdateFailed)
|
|
||||||
return fmt.Errorf("could not update pod disruption budget: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setStatus(spec.ClusterStatusRunning)
|
c.setStatus(spec.ClusterStatusRunning)
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func (c *Cluster) serviceName(role PostgresRole) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) podDisruptionBudgetName() 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) {
|
func (c *Cluster) resourceRequirements(resources spec.Resources) (*v1.ResourceRequirements, error) {
|
||||||
|
|
@ -605,6 +605,7 @@ func (c *Cluster) generatePodDisruptionBudget() *policybeta1.PodDisruptionBudget
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: c.podDisruptionBudgetName(),
|
Name: c.podDisruptionBudgetName(),
|
||||||
Namespace: c.Namespace,
|
Namespace: c.Namespace,
|
||||||
|
Labels: c.labelsSet(),
|
||||||
},
|
},
|
||||||
Spec: policybeta1.PodDisruptionBudgetSpec{
|
Spec: policybeta1.PodDisruptionBudgetSpec{
|
||||||
MinAvailable: &minAvailable,
|
MinAvailable: &minAvailable,
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ func (c *Cluster) Sync(newSpec *spec.Postgresql) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.logger.Debug("syncing pod disruption budgets")
|
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)
|
err = fmt.Errorf("could not sync pod disruption budget: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +149,7 @@ func (c *Cluster) syncEndpoint() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) syncPodDisruptionBudget() error {
|
func (c *Cluster) syncPodDisruptionBudget(isUpdate bool) error {
|
||||||
if c.PodDisruptionBudget == nil {
|
if c.PodDisruptionBudget == nil {
|
||||||
c.logger.Infof("could not find the cluster's pod disruption budget")
|
c.logger.Infof("could not find the cluster's pod disruption budget")
|
||||||
pdb, err := c.createPodDisruptionBudget()
|
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))
|
c.logger.Infof("created missing pod disruption budget %q", util.NameFromMeta(pdb.ObjectMeta))
|
||||||
return nil
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,11 +285,6 @@ func (c *Cluster) syncVolumes() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) samePDBWith(pdb *policybeta1.PodDisruptionBudget) (match bool, reason string) {
|
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)
|
match = reflect.DeepEqual(pdb.Spec, c.PodDisruptionBudget.Spec)
|
||||||
if !match {
|
if !match {
|
||||||
reason = "new service spec doesn't match the current one"
|
reason = "new service spec doesn't match the current one"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue