Skip to content

Commit 7f7beba

Browse files
authored
Improving e2e more (zalando#1185)
* Add curl to operator image. * Wait for idle operator in delete.
1 parent c694a72 commit 7f7beba

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM alpine
22
MAINTAINER Team ACID @ Zalando <[email protected]>
33

44
# We need root certificates to deal with teams api over https
5+
RUN apk --no-cache add curl
56
RUN apk --no-cache add ca-certificates
67

78
COPY build/* /

e2e/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ tools:
5151

5252
e2etest: tools copy clean
5353
./run.sh main
54+
55+
cleanup: clean
56+
./run.sh cleanup

e2e/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ runtime.
3333
In the e2e folder you can invoke tests either with `make test` or with:
3434

3535
```bash
36-
./run.sh
36+
./run.sh main
3737
```
3838

3939
To run both the build and test step you can invoke `make e2e` from the parent
4040
directory.
4141

4242
To run the end 2 end test and keep the kind state execute:
4343
```bash
44-
NOCLEANUP=True ./run.sh
44+
NOCLEANUP=True ./run.sh main
4545
```
4646

4747
## Run indidual test

e2e/scripts/watch_objects.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ kubectl get statefulsets
1313
echo
1414
kubectl get deployments
1515
echo
16+
echo
17+
echo 'Step from operator deployment'
1618
kubectl get pods -l name=postgres-operator -o jsonpath='{.items..metadata.annotations.step}'
1719
echo
20+
echo
21+
echo 'Spilo Image in statefulset'
1822
kubectl get pods -l application=spilo -o jsonpath='{.items..spec.containers..image}'
19-
"
23+
echo
24+
echo
25+
echo 'Queue Status'
26+
kubectl exec -it \$(kubectl get pods -l name=postgres-operator -o jsonpath='{.items..metadata.name}') -- curl localhost:8080/workers/all/status/
27+
echo"

e2e/tests/k8s_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ def get_patroni_state(self, pod):
239239
return []
240240
return json.loads(r.stdout.decode())
241241

242+
def get_operator_state(self):
243+
pod = self.get_operator_pod()
244+
if pod == None:
245+
return None
246+
pod = pod.metadata.name
247+
248+
r = self.exec_with_kubectl(pod, "curl localhost:8080/workers/all/status/")
249+
if not r.returncode == 0 or not r.stdout.decode()[0:1]=="{":
250+
return None
251+
252+
return json.loads(r.stdout.decode())
253+
254+
242255
def get_patroni_running_members(self, pod="acid-minimal-cluster-0"):
243256
result = self.get_patroni_state(pod)
244257
return list(filter(lambda x: "State" in x and x["State"] == "running", result))

e2e/tests/test_e2e.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,18 @@ def setUpClass(cls):
109109
with open("manifests/postgres-operator.yaml", 'w') as f:
110110
yaml.dump(operator_deployment, f, Dumper=yaml.Dumper)
111111

112+
with open("manifests/configmap.yaml", 'r+') as f:
113+
configmap = yaml.safe_load(f)
114+
configmap["data"]["workers"] = "1"
115+
116+
with open("manifests/configmap.yaml", 'w') as f:
117+
yaml.dump(configmap, f, Dumper=yaml.Dumper)
118+
112119
for filename in ["operator-service-account-rbac.yaml",
120+
"postgresteam.crd.yaml",
113121
"configmap.yaml",
114122
"postgres-operator.yaml",
123+
"api-service.yaml",
115124
"infrastructure-roles.yaml",
116125
"infrastructure-roles-new.yaml",
117126
"e2e-storage-class.yaml"]:
@@ -338,6 +347,7 @@ def test_infrastructure_roles(self):
338347
},
339348
}
340349
k8s.update_config(patch_infrastructure_roles)
350+
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0":"idle"}, "Operator does not get in sync")
341351

342352
try:
343353
# check that new roles are represented in the config by requesting the
@@ -447,6 +457,7 @@ def test_lazy_spilo_upgrade(self):
447457
# so we additonally test if disabling the lazy upgrade - forcing the normal rolling upgrade - works
448458
self.eventuallyEqual(lambda: k8s.get_effective_pod_image(pod0), conf_image, "Rolling upgrade was not executed", 50, 3)
449459
self.eventuallyEqual(lambda: k8s.get_effective_pod_image(pod1), conf_image, "Rolling upgrade was not executed", 50, 3)
460+
self.eventuallyEqual(lambda: len(k8s.get_patroni_running_members(pod0)), 2, "Postgres status did not enter running")
450461

451462
except timeout_decorator.TimeoutError:
452463
print('Operator log: {}'.format(k8s.get_operator_log()))
@@ -519,6 +530,9 @@ def get_docker_image():
519530
print('Operator log: {}'.format(k8s.get_operator_log()))
520531
raise
521532

533+
# ensure cluster is healthy after tests
534+
self.eventuallyEqual(lambda: len(k8s.get_patroni_running_members("acid-minimal-cluster-0")), 2, "Postgres status did not enter running")
535+
522536
@timeout_decorator.timeout(TEST_TIMEOUT_SEC)
523537
def test_min_resource_limits(self):
524538
'''
@@ -809,12 +823,14 @@ def test_zzzz_cluster_deletion(self):
809823
}
810824
}
811825
k8s.update_config(patch_delete_annotations)
826+
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0":"idle"}, "Operator does not get in sync")
812827

813828
try:
814829
# this delete attempt should be omitted because of missing annotations
815830
k8s.api.custom_objects_api.delete_namespaced_custom_object(
816831
"acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster")
817832
time.sleep(5)
833+
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0":"idle"}, "Operator does not get in sync")
818834

819835
# check that pods and services are still there
820836
k8s.wait_for_running_pods(cluster_label, 2)
@@ -825,6 +841,7 @@ def test_zzzz_cluster_deletion(self):
825841

826842
# wait a little before proceeding
827843
time.sleep(10)
844+
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0":"idle"}, "Operator does not get in sync")
828845

829846
# add annotations to manifest
830847
delete_date = datetime.today().strftime('%Y-%m-%d')
@@ -838,6 +855,7 @@ def test_zzzz_cluster_deletion(self):
838855
}
839856
k8s.api.custom_objects_api.patch_namespaced_custom_object(
840857
"acid.zalan.do", "v1", "default", "postgresqls", "acid-minimal-cluster", pg_patch_delete_annotations)
858+
self.eventuallyEqual(lambda: k8s.get_operator_state(), {"0":"idle"}, "Operator does not get in sync")
841859

842860
# wait a little before proceeding
843861
time.sleep(20)

0 commit comments

Comments
 (0)