make annotations setter one liners

This commit is contained in:
Felix Kunde 2020-12-10 15:41:07 +01:00
parent 5a0d97d3d9
commit 4d18f788d2
4 changed files with 14 additions and 15 deletions

View File

@ -273,9 +273,9 @@ configuration they are grouped under the `kubernetes` key.
* **inherited_annotations**
list of annotation keys that can be inherited from the cluster manifest, and
added to each child objects (`Deployment`, `StatefulSet`, `Pod`, `PVCs`,
`PDB`, `Service`, `Endpoints` and `Secrets`) created by the operator.
The default is empty.
added to each child objects (`Deployment`, `StatefulSet`, `Pod`, `PDB` and
`Services`) created by the operator incl. the ones from the connection
pooler deployment. The default is empty.
* **pod_role_label**
name of the label assigned to the Postgres pods (and services/endpoints) by

View File

@ -334,15 +334,12 @@ func (c *Cluster) generateConnectionPoolerDeployment(connectionPooler *Connectio
return nil, err
}
annotations := c.annotationsSet(nil)
annotations = c.AnnotationsToPropagate(annotations)
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: connectionPooler.Name,
Namespace: connectionPooler.Namespace,
Labels: c.connectionPoolerLabels(connectionPooler.Role, true).MatchLabels,
Annotations: annotations,
Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
// make StatefulSet object its owner to represent the dependency.
// By itself StatefulSet is being deleted with "Orphaned"
// propagation policy, which means that it's deletion will not
@ -869,8 +866,7 @@ func (c *Cluster) syncConnectionPoolerWorker(oldSpec, newSpec *acidv1.Postgresql
}
}
newAnnotations := c.annotationsSet(c.ConnectionPooler[role].Deployment.Annotations)
newAnnotations = c.AnnotationsToPropagate(newAnnotations)
newAnnotations := c.AnnotationsToPropagate(c.annotationsSet(c.ConnectionPooler[role].Deployment.Annotations))
if newAnnotations != nil && len(newAnnotations) > 0 {
deployment, err = updateConnectionPoolerAnnotations(c.KubeClient, c.ConnectionPooler[role].Deployment, newAnnotations)
if err != nil {

View File

@ -1226,9 +1226,9 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
return nil, fmt.Errorf("could not set the pod management policy to the unknown value: %v", c.OpConfig.PodManagementPolicy)
}
stsAnnotations := c.annotationsSet(nil)
stsAnnotations = c.AnnotationsToPropagate(stsAnnotations)
stsAnnotations := make(map[string]string)
stsAnnotations[rollingUpdateStatefulsetAnnotationKey] = strconv.FormatBool(false)
stsAnnotations = c.AnnotationsToPropagate(c.annotationsSet(nil))
statefulSet := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{

View File

@ -353,9 +353,8 @@ func (c *Cluster) syncStatefulSet() error {
}
}
}
annotations := c.annotationsSet(c.Statefulset.Annotations)
annotations = c.AnnotationsToPropagate(annotations)
c.updateStatefulSetAnnotations(annotations)
c.updateStatefulSetAnnotations(c.AnnotationsToPropagate(c.annotationsSet(c.Statefulset.Annotations)))
if !podsRollingUpdateRequired && !c.OpConfig.EnableLazySpiloUpgrade {
// even if desired and actual statefulsets match
@ -420,7 +419,11 @@ func (c *Cluster) AnnotationsToPropagate(annotations map[string]string) map[stri
}
}
return annotations
if len(annotations) > 0 {
return annotations
}
return nil
}
// checkAndSetGlobalPostgreSQLConfiguration checks whether cluster-wide API parameters