Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed test_031 #885

Merged
merged 2 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/e2e/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ def get_pod_names(chi_name, ns=namespace):
return pod_names[1:]


def get_obj_names(chi_name, obj_type="pods", ns=namespace):
pod_names = launch(
f"get {obj_type} -o=custom-columns=name:.metadata.name -l clickhouse.altinity.com/chi={chi_name}",
ns=ns,
).splitlines()
return pod_names[1:]


def get_pod_volumes(chi_name, pod_name="", ns=namespace):
volume_mounts = get_pod_spec(chi_name, pod_name, ns)["containers"][0]["volumeMounts"]
return volume_mounts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"
metadata:
name: "test-031"
name: "test-031-from-tpl"
spec:
useTemplates:
- name: test-031-tpl
Expand Down
36 changes: 36 additions & 0 deletions tests/e2e/manifests/chi/test-031-wo-tpl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: "clickhouse.altinity.com/v1"
kind: "ClickHouseInstallation"
metadata:
name: "test-031-wo-tpl"
annotations:
excl: excluded
incl: included
spec:
configuration:
clusters:
- name: single
templates:
volumeClaimTemplates:
- name: default
reclaimPolicy: Retain
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
serviceTemplates:
- name: default-service-template
generateName: clickhouse-{chi}
metadata:
annotations:
servicetemplate/test: "test"
servicetemplate/macro-test: "{chi}.example.com"
spec:
ports:
- name: http
port: 8123
- name: tcp
port: 9000
type: ClusterIP
clusterIP: None
44 changes: 30 additions & 14 deletions tests/e2e/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,30 +1996,46 @@ def test_031(self):
util.install_operator_if_not_exist(reinstall=True, manifest=util.get_full_path(cho_install_manifest, False))
util.restart_operator(ns=settings.operator_namespace)

with When("I apply template with annotations and chi"):
kubectl.apply(manifest=util.get_full_path("manifests/chit/tpl-test-031.yaml", False), ns=settings.test_namespace)
time.sleep(5)
kubectl.apply(ns=settings.test_namespace, manifest=util.get_full_path("manifests/chi/test-031.yaml", False))
with When("I apply chi"):
kubectl.apply(ns=settings.test_namespace, manifest=util.get_full_path("manifests/chi/test-031-wo-tpl.yaml", False))
time.sleep(5)

with Then("I check only allowed annotations are propagated"):
while not len(kubectl.get_pod_names(chi_name='test-031')):
while len(kubectl.get_pod_names(chi_name='test-031-wo-tpl')) == 0:
time.sleep(1)
chi_name = kubectl.get_pod_names(chi_name='test-031')[0]
annotations = kubectl.launch(command=f"get pod -n test {chi_name} -o jsonpath='{{.metadata.annotations}}'")
assert "incl" in annotations, error()
assert "excl" not in annotations, error()

with Finally("I restore original operator state"):
kubectl.delete_chi('test-031')
util.install_operator_if_not_exist(reinstall=True, manifest=util.get_full_path(settings.clickhouse_operator_install_manifest, False))
util.restart_operator(ns=settings.operator_namespace)
os.remove(util.get_full_path(cho_install_manifest, False))
with By("I check propagation from chi to StatefulSets, ConfigMaps, PVCs, Services"):
statefulsets_wo_tpl_name = kubectl.get_obj_names(chi_name='test-031-wo-tpl', obj_type="statefulsets")
for ss in statefulsets_wo_tpl_name:
annotations = kubectl.launch(command=f"get statefulset -n test {ss} -o jsonpath='{{.metadata.annotations}}'")
assert "incl" in annotations, error()
assert "excl" not in annotations, error()

configmaps_wo_tpl_name = kubectl.get_obj_names(chi_name='test-031-wo-tpl', obj_type="configmaps")
for cm in configmaps_wo_tpl_name:
annotations = kubectl.launch(command=f"get configmap -n test {cm} -o jsonpath='{{.metadata.annotations}}'")
assert "incl" in annotations, error()
assert "excl" not in annotations, error()

pvcs_wo_tpl_name = kubectl.get_obj_names(chi_name='test-031-wo-tpl', obj_type="pvc")
for pvc in pvcs_wo_tpl_name:
annotations = kubectl.launch(command=f"get pvc -n test {pvc} -o jsonpath='{{.metadata.annotations}}'")
assert "incl" in annotations, error()
assert "excl" not in annotations, error()

services_wo_tpl_name = kubectl.get_obj_names(chi_name='test-031-wo-tpl', obj_type="services")
for srv in services_wo_tpl_name:
annotations = kubectl.launch(command=f"get service -n test {srv} -o jsonpath='{{.metadata.annotations}}'")
assert "incl" in annotations, error()
assert "excl" not in annotations, error()


with Finally("I restore original operator state"):
kubectl.delete_chi('test-031-wo-tpl')
util.install_operator_if_not_exist(reinstall=True, manifest=util.get_full_path(settings.clickhouse_operator_install_manifest, False))
util.restart_operator(ns=settings.operator_namespace)
os.remove(util.get_full_path(cho_install_manifest, False))


@TestModule
@Name("e2e.test_operator")
Expand Down