From 9cc7ed392964ffb41fb4e492c3817813606474db Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Wed, 29 Apr 2020 17:08:40 +0200 Subject: [PATCH] add e2e test and introduce option in configmap --- e2e/tests/test_e2e.py | 54 +++++++++++++++++++++++++++++++++++++--- manifests/configmap.yaml | 1 + 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/e2e/tests/test_e2e.py b/e2e/tests/test_e2e.py index aa6f1205d..0c6b60a2b 100644 --- a/e2e/tests/test_e2e.py +++ b/e2e/tests/test_e2e.py @@ -457,7 +457,7 @@ class EndToEndTestCase(unittest.TestCase): k8s = self.k8s patch_custom_service_annotations = { "data": { - "custom_service_annotations": "foo:bar", + "custom_service_annotatons": "foo:bar", } } k8s.update_config(patch_custom_service_annotations) @@ -477,9 +477,9 @@ class EndToEndTestCase(unittest.TestCase): "foo": "bar", } self.assertTrue(k8s.check_service_annotations( - "cluster-name=acid-service-annotations,spilo-role=master", annotations)) + "cluster-name=acid-minimal-cluster,spilo-role=master", annotations)) self.assertTrue(k8s.check_service_annotations( - "cluster-name=acid-service-annotations,spilo-role=replica", annotations)) + "cluster-name=acid-minimal-cluster,spilo-role=replica", annotations)) # clean up unpatch_custom_service_annotations = { @@ -489,6 +489,44 @@ class EndToEndTestCase(unittest.TestCase): } k8s.update_config(unpatch_custom_service_annotations) + @timeout_decorator.timeout(TEST_TIMEOUT_SEC) + def test_statefulset_annotation_propagation(self): + ''' + Inject annotation to Postgresql CRD and check it's propagation to stateful set + ''' + k8s = self.k8s + cluster_label = 'application=spilo,cluster-name=acid-minimal-cluster' + + patch_sset_propagate_annotations = { + "data": { + "statefulset_propagate_annotations": "deployment-time,downscaler/*", + } + } + k8s.update_config(patch_sset_propagate_annotations) + + pg_crd_annotations = { + "metadata": { + "annotations": [ + { + "deployment-time": "2020-04-30 12:00:00", + }, + { + "downscaler/downtime_replicas": "0", + }, + ], + } + } + k8s.api.custom_objects_api.patch_namespaced_custom_object( + "acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", pg_crd_annotations) + + k8s.delete_operator_pod() + + annotations = { + "deployment-time": "2020-04-30 12:00:00", + "downscaler/downtime_replicas": "0", + } + self.assertTrue(k8s.check_statefulset_annotations(cluster_label, annotations)) + @timeout_decorator.timeout(TEST_TIMEOUT_SEC) def test_taint_based_eviction(self): ''' @@ -701,6 +739,16 @@ class K8s: return False return True + def check_statefulset_annotations(self, sset_labels, annotations, namespace='default'): + ssets = self.api.apps_v1.list_namespaced_stateful_set(namespace, label_selector=sset_labels, limit=1).items + for sset in ssets: + if len(sset.metadata.annotations) < len(annotations): + return False + for key in sset.metadata.annotations: + if sset.metadata.annotations[key] != annotations[key]: + return False + return True + def wait_for_pg_to_scale(self, number_of_instances, namespace='default'): body = { diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 8719e76a1..525e26725 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -94,6 +94,7 @@ data: # sidecar_docker_images: "" # set_memory_request_to_limit: "false" spilo_privileged: "false" + # statefulset_propagate_annotation: "deployment-time,downscaler/*" super_username: postgres # team_admin_role: "admin" # team_api_role_configuration: "log_statement:all"