diff --git a/charts/postgres-operator/values.yaml b/charts/postgres-operator/values.yaml index 7ad804114..2ce26d18a 100644 --- a/charts/postgres-operator/values.yaml +++ b/charts/postgres-operator/values.yaml @@ -127,9 +127,7 @@ configKubernetes: # annotations to be ignored when comparing statefulsets, services etc. # ignored_annotations: - # - "deployment-time" - # - "k8s.v1.cni.cncf.io/network-status" - + # - k8s.v1.cni.cncf.io/network-status # namespaced name of the secret containing infrastructure roles names and passwords # infrastructure_roles_secret_name: postgresql-infrastructure-roles diff --git a/e2e/tests/test_e2e.py b/e2e/tests/test_e2e.py index 1edeb3bb4..11beccd6b 100644 --- a/e2e/tests/test_e2e.py +++ b/e2e/tests/test_e2e.py @@ -707,39 +707,45 @@ class EndToEndTestCase(unittest.TestCase): @timeout_decorator.timeout(TEST_TIMEOUT_SEC) def test_ignored_annotations(self): ''' - Test if injected annotation does not cause failover when listed under ignored_annotations + Test if injected annotation does not cause replacement of resources when listed under ignored_annotations ''' k8s = self.k8s - cluster_label = 'application=spilo,cluster-name=acid-minimal-cluster' - # get node of current master - master_node, _ = k8s.get_pg_nodes(cluster_label) - - patch_config_ignored_annotations = { - "data": { - "ignored_annotations": "deployment-time", - } - } - k8s.update_config(patch_config_ignored_annotations) - - pg_crd_annotation = { + annotation_patch = { "metadata": { "annotations": { - "deployment-time": "2022-04-01 12:00:00" + "k8s-status": "healthy" }, } } - k8s.api.custom_objects_api.patch_namespaced_custom_object( - "acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", pg_crd_annotation) - annotations = { - "deployment-time": "2022-04-01 12:00:00", - } - self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync") - self.eventuallyTrue(lambda: k8s.check_statefulset_annotations(cluster_label, annotations), "Annotations missing") + try: + sts = k8s.api.apps_v1.read_namespaced_stateful_set('acid-minimal-cluster', 'default') + old_sts_creation_timestamp = sts.metadata.creation_timestamp + k8s.api.apps_v1.patch_namespaced_stateful_set(sts.metadata.name, sts.metadata.namespace, annotation_patch) + svc = k8s.api.core_v1.read_namespaced_service('acid-minimal-cluster', 'default') + old_svc_creation_timestamp = svc.metadata.creation_timestamp + k8s.api.core_v1.patch_namespaced_service(svc.metadata.name, svc.metadata.namespace, annotation_patch) - current_master_node, _ = k8s.get_pg_nodes(cluster_label) - self.eventuallyEqual(lambda: master_node, current_master_node, "unexpected rolling update happened") + patch_config_ignored_annotations = { + "data": { + "ignored_annotations": "k8s-status", + } + } + k8s.update_config(patch_config_ignored_annotations) + self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0": "idle"}, "Operator does not get in sync") + + sts = k8s.api.apps_v1.read_namespaced_stateful_set('acid-minimal-cluster', 'default') + new_sts_creation_timestamp = sts.metadata.creation_timestamp + svc = k8s.api.core_v1.read_namespaced_service('acid-minimal-cluster', 'default') + new_svc_creation_timestamp = svc.metadata.creation_timestamp + + self.eventuallyEqual(old_sts_creation_timestamp, new_sts_creation_timestamp, "unexpected replacement of statefulset on sync") + self.eventuallyEqual(old_svc_creation_timestamp, new_svc_creation_timestamp, "unexpected replacement of master service on sync") + + except timeout_decorator.TimeoutError: + print('Operator log: {}'.format(k8s.get_operator_log())) + raise @timeout_decorator.timeout(TEST_TIMEOUT_SEC) def test_infrastructure_roles(self): diff --git a/manifests/postgresql-operator-default-configuration.yaml b/manifests/postgresql-operator-default-configuration.yaml index 1d16e51fd..a5ceb8d2a 100644 --- a/manifests/postgresql-operator-default-configuration.yaml +++ b/manifests/postgresql-operator-default-configuration.yaml @@ -60,8 +60,7 @@ configuration: enable_pod_disruption_budget: true enable_sidecars: true # ignored_annotations: - # - "deployment-time" - # - "k8s.v1.cni.cncf.io/network-status" + # - k8s.v1.cni.cncf.io/network-status # infrastructure_roles_secret_name: "postgresql-infrastructure-roles" # infrastructure_roles_secrets: # - secretname: "monitoring-roles" diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index f801aef6d..3bdbb0fe8 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -385,7 +385,7 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *appsv1.StatefulSet) *compa if changed, reason := c.compareAnnotations(c.Statefulset.Annotations, statefulSet.Annotations); changed { match = false needsReplace = true - reasons = append(reasons, "new statefulset's annotations do not match "+reason) + reasons = append(reasons, "new statefulset's annotations do not match: "+reason) } needsRollUpdate, reasons = c.compareContainers("initContainers", c.Statefulset.Spec.Template.Spec.InitContainers, statefulSet.Spec.Template.Spec.InitContainers, needsRollUpdate, reasons) @@ -734,7 +734,7 @@ func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string) continue } if _, ok := new[key]; !ok { - reason += fmt.Sprintf(" Removed '%s'.", key) + reason += fmt.Sprintf(" Removed %q.", key) } } @@ -744,9 +744,9 @@ func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string) } v, ok := old[key] if !ok { - reason += fmt.Sprintf(" Added '%s' with value '%s'.", key, new[key]) + reason += fmt.Sprintf(" Added %q with value %q.", key, new[key]) } else if v != new[key] { - reason += fmt.Sprintf(" '%s' changed from '%s' to '%s'.", key, v, new[key]) + reason += fmt.Sprintf(" %q changed from %q to %q.", key, v, new[key]) } }