add e2e test and introduce option in configmap

This commit is contained in:
Felix Kunde 2020-04-29 17:08:40 +02:00
parent 36e67f77c9
commit 9cc7ed3929
2 changed files with 52 additions and 3 deletions

View File

@ -457,7 +457,7 @@ class EndToEndTestCase(unittest.TestCase):
k8s = self.k8s k8s = self.k8s
patch_custom_service_annotations = { patch_custom_service_annotations = {
"data": { "data": {
"custom_service_annotations": "foo:bar", "custom_service_annotatons": "foo:bar",
} }
} }
k8s.update_config(patch_custom_service_annotations) k8s.update_config(patch_custom_service_annotations)
@ -477,9 +477,9 @@ class EndToEndTestCase(unittest.TestCase):
"foo": "bar", "foo": "bar",
} }
self.assertTrue(k8s.check_service_annotations( 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( 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 # clean up
unpatch_custom_service_annotations = { unpatch_custom_service_annotations = {
@ -489,6 +489,44 @@ class EndToEndTestCase(unittest.TestCase):
} }
k8s.update_config(unpatch_custom_service_annotations) 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) @timeout_decorator.timeout(TEST_TIMEOUT_SEC)
def test_taint_based_eviction(self): def test_taint_based_eviction(self):
''' '''
@ -701,6 +739,16 @@ class K8s:
return False return False
return True 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'): def wait_for_pg_to_scale(self, number_of_instances, namespace='default'):
body = { body = {

View File

@ -94,6 +94,7 @@ data:
# sidecar_docker_images: "" # sidecar_docker_images: ""
# set_memory_request_to_limit: "false" # set_memory_request_to_limit: "false"
spilo_privileged: "false" spilo_privileged: "false"
# statefulset_propagate_annotation: "deployment-time,downscaler/*"
super_username: postgres super_username: postgres
# team_admin_role: "admin" # team_admin_role: "admin"
# team_api_role_configuration: "log_statement:all" # team_api_role_configuration: "log_statement:all"