diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 99e659795f6c058a9d2900d15c827ffbf1917411..2ba2d99057b9783f60cb96416c03155f67f1a684 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -170,7 +170,7 @@ stages: - base-helm-release - install-apps - apps-helm-release - - apps-deployment + - apps-ready - certs - health-test - integration-test @@ -579,13 +579,13 @@ wordpress-helm-release: - .wordpress_rules -# Stage: apps-deployment +# Stage: apps-ready # ====================== # # Tests apps for readiness state .apps-deployment: - stage: apps-deployment + stage: apps-ready script: - *debug_information - cd ansible/ @@ -595,6 +595,17 @@ wordpress-helm-release: - .ssh_setup interruptible: true +.apps-statefulset: + stage: apps-ready + script: + - *debug_information + - cd ansible/ + - export KUBECONFIG="${PWD}/../clusters/${HOSTNAME}/kube_config_cluster.yml" + - pytest -v -s -m 'statefulsets' --resource="$RESOURCE" --namespace="$NAMESPACE" --connection=ansible --ansible-inventory=${CLUSTER_DIR}/inventory.yml --hosts='ansible://*' --reruns 120 --reruns-delay 10 + extends: + - .ssh_setup + interruptible: true + cert-manager-deployment: variables: RESOURCE: "cert-manager" @@ -628,7 +639,7 @@ local-path-provisioner-deployment: - .apps-deployment - .local_path_provisioner_rules -loki-deployment: +loki-statefulset: variables: RESOURCE: "loki" NAMESPACE: "oas" @@ -636,7 +647,7 @@ loki-deployment: - job: loki-helm-release - job: setup-openappstack extends: - - .apps-deployment + - .apps-statefulset - .loki_rules promtail-deployment: diff --git a/test/pytest.ini b/test/pytest.ini index 7a503f6d6283b0521bbd101fe0e8a0f03c5027bf..426182772da890bfb5d250e3da945b4fe67745ca 100644 --- a/test/pytest.ini +++ b/test/pytest.ini @@ -8,6 +8,7 @@ markers = helmreleases: Test deployed helmreleases installed by flux kustomizations: Test that flux kustomizations are ready deployments: Test if all deployments are ready + statefulsets: Test if all statefulsets are ready dns: Check if cluster domain resolves at all nameservers # https://docs.pytest.org/en/latest/warnings.html diff --git a/test/pytest/test_resources.py b/test/pytest/test_resources.py index f70a70e2bf9b451902086f8b3e771811fa19cf43..f46a101623ed8ecb88ecc3f41855b098f69a636f 100644 --- a/test/pytest/test_resources.py +++ b/test/pytest/test_resources.py @@ -192,3 +192,35 @@ def test_deployments(resource, namespace): failed_resources.append(resource) assert failed == 0, f"Error: {failed} resources not ready ({failed_resources})!" + +@pytest.mark.resource +@pytest.mark.statefulsets +def test_statefulsets(resource, namespace): + """ + Check if statefulsets are ready + """ + + failed = 0 + failed_resources = [] + api = client.AppsV1Api() + print('\n') + + if resource != 'all': + statefulsets = api.list_namespaced_stateful_set( + namespace=namespace, + label_selector=f'helm.toolkit.fluxcd.io/name={resource}') + else: + statefulsets = api.list_stateful_set_for_all_namespaces() + + assert statefulsets.items, 'No statefulsets found !!' + for statefulset in statefulsets.items: + resource = statefulset.metadata.name + namespace = statefulset.metadata.namespace + status = api.read_namespaced_stateful_set_status(resource, namespace) + ready = status.status.replicas == status.status.ready_replicas + print(f'statefulset "{resource}" in namespace "{namespace}": {ready}') + if not ready: + failed += 1 + failed_resources.append(resource) + + assert failed == 0, f"Error: {failed} resources not ready ({failed_resources})!"