diff --git a/pkg/cluster/connection_pooler.go b/pkg/cluster/connection_pooler.go index 7f75ccea1..1c1ffaff9 100644 --- a/pkg/cluster/connection_pooler.go +++ b/pkg/cluster/connection_pooler.go @@ -866,7 +866,8 @@ func (c *Cluster) syncConnectionPoolerWorker(oldSpec, newSpec *acidv1.Postgresql } } - newAnnotations := c.AnnotationsToPropagate(c.ConnectionPooler[role].Deployment.Annotations) + newAnnotations := c.annotationsSet(c.ConnectionPooler[role].Deployment.Annotations) + newAnnotations = c.AnnotationsToPropagate(newAnnotations) if newAnnotations != nil { deployment, err = updateConnectionPoolerAnnotations(c.KubeClient, c.ConnectionPooler[role].Deployment, newAnnotations) if err != nil { diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index d6cba7be8..6404f554b 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -353,8 +353,9 @@ func (c *Cluster) syncStatefulSet() error { } } } - annotations := c.AnnotationsToPropagate(c.Statefulset.Annotations) - c.updateStatefulSetAnnotations(c.annotationsSet(annotations)) + annotations := c.annotationsSet(c.Statefulset.Annotations) + annotations = c.AnnotationsToPropagate(annotations) + c.updateStatefulSetAnnotations(annotations) if !podsRollingUpdateRequired && !c.OpConfig.EnableLazySpiloUpgrade { // even if desired and actual statefulsets match diff --git a/pkg/cluster/util_test.go b/pkg/cluster/util_test.go index 51d433ff6..637a442ba 100644 --- a/pkg/cluster/util_test.go +++ b/pkg/cluster/util_test.go @@ -17,13 +17,14 @@ func newFakeK8sAnnotationsClient() (k8sutil.KubernetesClient, *fake.Clientset) { clientSet := fake.NewSimpleClientset() return k8sutil.KubernetesClient{ - DeploymentsGetter: clientSet.AppsV1(), - EndpointsGetter: clientSet.CoreV1(), - PodsGetter: clientSet.CoreV1(), - PodDisruptionBudgetsGetter: clientSet.PolicyV1beta1(), - SecretsGetter: clientSet.CoreV1(), - ServicesGetter: clientSet.CoreV1(), - StatefulSetsGetter: clientSet.AppsV1(), + DeploymentsGetter: clientSet.AppsV1(), + EndpointsGetter: clientSet.CoreV1(), + PersistentVolumeClaimsGetter: clientSet.CoreV1(), + PodsGetter: clientSet.CoreV1(), + PodDisruptionBudgetsGetter: clientSet.PolicyV1beta1(), + SecretsGetter: clientSet.CoreV1(), + ServicesGetter: clientSet.CoreV1(), + StatefulSetsGetter: clientSet.AppsV1(), }, clientSet } @@ -32,13 +33,13 @@ func TestInheritedAnnotations(t *testing.T) { client, _ := newFakeK8sAnnotationsClient() clusterName := "acid-test-cluster" namespace := "default" + annotationValue := "acid" - annotationKey := "acid" pg := acidv1.Postgresql{ ObjectMeta: metav1.ObjectMeta{ Name: clusterName, Annotations: map[string]string{ - "owned-by": annotationKey, + "owned-by": annotationValue, }, }, Spec: acidv1.PostgresSpec{ @@ -94,6 +95,15 @@ func TestInheritedAnnotations(t *testing.T) { } } + // check pvc annotations + pvcList, err := cluster.KubeClient.PersistentVolumeClaims(namespace).List(context.TODO(), listOptions) + assert.NoError(t, err) + for _, pvc := range pvcList.Items { + if !(util.MapContains(pvc.ObjectMeta.Annotations, inheritedAnnotations)) { + t.Errorf("%s: PVC %v not inherited annotations %#v, got %#v", testName, pvc.ObjectMeta.Name, inheritedAnnotations, pvc.ObjectMeta.Annotations) + } + } + // check service annotations svcList, err := cluster.KubeClient.Services(namespace).List(context.TODO(), listOptions) assert.NoError(t, err)