Skip to content

Commit

Permalink
Test for #1582
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-zaitsev committed Dec 5, 2024
1 parent 96375fc commit 6378766
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/e2e/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def wait_jsonpath(kind, name, field, value, ns=None, retries=max_retries):


def get_field(kind, name, field, ns=None, shell=None):
out = launch(f"get {kind} {name} -o=custom-columns=field:{field}", ns=ns, ok_to_fail=True, shell=shell).splitlines()
out = launch(f"get {kind} {name} -o=custom-columns=field:\"{field}\"", ns=ns, ok_to_fail=True, shell=shell).splitlines()
if len(out) > 1:
return out[1]
else:
Expand Down
72 changes: 72 additions & 0 deletions tests/e2e/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5083,6 +5083,78 @@ def check_replication(chi, replicas, token, table = ''):
out = clickhouse.query(chi, f"SELECT a from {table} where a={token}", host=f"chi-{chi}-{cluster}-0-{replica}-0")
assert out == f"{token}", error()

@TestScenario
@Name("test_053. Check that stadnard Kubernetes annotations are ignored if set to statefulset externally")
@Tags("NO_PARALLEL")
def test_053(self):
version_from = "0.23.7"
version_to = current().context.operator_version
with Given(f"clickhouse-operator from {version_from}"):
current().context.operator_version = version_from
create_shell_namespace_clickhouse_template()

manifest="manifests/chi/test-001.yaml"
chi = yaml_manifest.get_name(util.get_full_path(manifest))
sts = f"chi-{chi}-single-0-0"
pod = f"{sts}-0"

kubectl.create_and_check(
manifest=manifest,
check={
"object_counts": {
"statefulset": 1,
"pod": 1,
"service": 2,
},
"do_not_delete": 1
},
)

with When("Run rollout restart"):
kubectl.launch(f"rollout restart statefulset {sts}")
time.sleep(10)

with Then("Pod annotation kubectl.kubernetes.io/restartedAt should be populated"):
assert kubectl.get_field("pod", pod, ".metadata.annotations.kubectl\.kubernetes\.io/restartedAt") != "<none>"
with And("PodTemplate annotation kubectl.kubernetes.io/restartedAt should be populated"):
assert kubectl.get_field("statefulset", sts, ".spec.template.metadata.annotations.kubectl\.kubernetes\.io/restartedAt") != "<none>"

start_time = kubectl.get_field("pod", pod, ".status.startTime")
def check_restart():
with Then("ClickHouse pods should not be restarted during operator's restart"):
new_start_time = kubectl.get_field("pod", pod, ".status.startTime")
# print(f"pod start_time old: {start_time}")
# print(f"pod start_time new: {new_start_time}")
assert start_time == new_start_time

with Then("Trigger reconcile"):
start_time = kubectl.get_field("pod", pod, ".status.startTime")

cmd = f'patch chi {chi} --type=\'json\' --patch=\'[{{"op":"add","path":"/spec/taskID","value":"Reconcile"}}]\''
kubectl.launch(cmd)
kubectl.wait_chi_status(chi, "InProgress")
kubectl.wait_chi_status(chi, "Completed")

check_restart()

with When("Restart operator"):
util.restart_operator()
kubectl.wait_chi_status(chi, "InProgress")
kubectl.wait_chi_status(chi, "Completed")

check_restart()

with When(f"upgrade operator to {version_to}"):
util.install_operator_version(version_to)
kubectl.wait_chi_status(chi, "InProgress")
kubectl.wait_chi_status(chi, "Completed")

check_restart()


with Finally("I clean up"):
delete_test_namespace()


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

0 comments on commit 6378766

Please sign in to comment.