fix e2e test

This commit is contained in:
Felix Kunde 2022-03-24 11:24:12 +01:00
parent 80d4eb3c0d
commit 6a3645aeec
4 changed files with 35 additions and 32 deletions

View File

@ -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

View File

@ -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):

View File

@ -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"

View File

@ -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])
}
}