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** * **inherited_annotations**
list of annotation keys that can be inherited from the cluster manifest, and list of annotation keys that can be inherited from the cluster manifest, and
added to each child objects (`Deployment`, `StatefulSet`, `Pod`, `PVCs`, added to each child objects (`Deployment`, `StatefulSet`, `Pod`, `PDB` and
`PDB`, `Service`, `Endpoints` and `Secrets`) created by the operator. `Services`) created by the operator incl. the ones from the connection
The default is empty. pooler deployment. The default is empty.
* **pod_role_label** * **pod_role_label**
name of the label assigned to the Postgres pods (and services/endpoints) by 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 return nil, err
} }
annotations := c.annotationsSet(nil)
annotations = c.AnnotationsToPropagate(annotations)
deployment := &appsv1.Deployment{ deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: connectionPooler.Name, Name: connectionPooler.Name,
Namespace: connectionPooler.Namespace, Namespace: connectionPooler.Namespace,
Labels: c.connectionPoolerLabels(connectionPooler.Role, true).MatchLabels, Labels: c.connectionPoolerLabels(connectionPooler.Role, true).MatchLabels,
Annotations: annotations, Annotations: c.AnnotationsToPropagate(c.annotationsSet(nil)),
// make StatefulSet object its owner to represent the dependency. // make StatefulSet object its owner to represent the dependency.
// By itself StatefulSet is being deleted with "Orphaned" // By itself StatefulSet is being deleted with "Orphaned"
// propagation policy, which means that it's deletion will not // 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(c.annotationsSet(c.ConnectionPooler[role].Deployment.Annotations))
newAnnotations = c.AnnotationsToPropagate(newAnnotations)
if newAnnotations != nil && len(newAnnotations) > 0 { if newAnnotations != nil && len(newAnnotations) > 0 {
deployment, err = updateConnectionPoolerAnnotations(c.KubeClient, c.ConnectionPooler[role].Deployment, newAnnotations) deployment, err = updateConnectionPoolerAnnotations(c.KubeClient, c.ConnectionPooler[role].Deployment, newAnnotations)
if err != nil { 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) return nil, fmt.Errorf("could not set the pod management policy to the unknown value: %v", c.OpConfig.PodManagementPolicy)
} }
stsAnnotations := c.annotationsSet(nil) stsAnnotations := make(map[string]string)
stsAnnotations = c.AnnotationsToPropagate(stsAnnotations)
stsAnnotations[rollingUpdateStatefulsetAnnotationKey] = strconv.FormatBool(false) stsAnnotations[rollingUpdateStatefulsetAnnotationKey] = strconv.FormatBool(false)
stsAnnotations = c.AnnotationsToPropagate(c.annotationsSet(nil))
statefulSet := &appsv1.StatefulSet{ statefulSet := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{ 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(c.AnnotationsToPropagate(c.annotationsSet(c.Statefulset.Annotations)))
c.updateStatefulSetAnnotations(annotations)
if !podsRollingUpdateRequired && !c.OpConfig.EnableLazySpiloUpgrade { if !podsRollingUpdateRequired && !c.OpConfig.EnableLazySpiloUpgrade {
// even if desired and actual statefulsets match // 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 // checkAndSetGlobalPostgreSQLConfiguration checks whether cluster-wide API parameters