From bf87df84b731df2300450824496a85c99d8d251c Mon Sep 17 00:00:00 2001
From: Varac <varac@varac.net>
Date: Sun, 1 Aug 2021 16:16:56 +0200
Subject: [PATCH] Query "Available" deployment condition

---
 test/pytest/test_resources.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/test/pytest/test_resources.py b/test/pytest/test_resources.py
index 7b2f15317..8ee1e36a3 100644
--- a/test/pytest/test_resources.py
+++ b/test/pytest/test_resources.py
@@ -120,6 +120,18 @@ def run_around_tests():
     config.load_kube_config(config_file=kubeconfig)
     yield
 
+def get_readiness(app_status):
+    """
+    Parses an app status's 'conditions' to find a type field called 'Ready' and
+    returns its status. Works for Kustomizations as well as Helmreleases.
+    """
+    for condition in app_status.conditions:
+        if condition.type == 'Available':
+            return condition.status
+    # If this point is reached, no condition "Ready" exists, so the application
+    # is not ready.
+    return False
+
 
 # Pytest functions
 
@@ -184,8 +196,8 @@ def test_deployments(resource, namespace):
     for deployment in deployments.items:
         resource = deployment.metadata.name
         namespace = deployment.metadata.namespace
-        status = api.read_namespaced_deployment_status(resource, namespace)
-        ready = status.status.conditions[0].status
+        deployment = api.read_namespaced_deployment_status(resource, namespace)
+        ready = get_readiness(deployment.status)
         print(f'Deployment "{resource}" in namespace "{namespace}": {ready}')
         if ready != 'True':
             failed += 1
-- 
GitLab