From 4b390f2d4059ad368d0ee5d6d56c4ddcdc08f405 Mon Sep 17 00:00:00 2001 From: okozachenko Date: Wed, 27 May 2020 21:36:56 +0300 Subject: [PATCH] Add the namespace in wait-for-pods role Specify the namespace for waiting, so no need to change the context Change-Id: I4b961bdc8c740e20d6b72200f0161d2f5c5c2c19 --- roles/wait-for-pods/README.rst | 7 ++++++- roles/wait-for-pods/tasks/main.yaml | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/roles/wait-for-pods/README.rst b/roles/wait-for-pods/README.rst index f93d0720b..d3a06e678 100644 --- a/roles/wait-for-pods/README.rst +++ b/roles/wait-for-pods/README.rst @@ -1,4 +1,9 @@ Wait for all pods to become Ready This role scans the current namespace for all pods and ensures that all of -them are in a Ready state. \ No newline at end of file +them are in a Ready state. + +.. zuul:rolevar:: wait_for_pods_namespace + + Name of the specified namespace. If not specified explicitly, + then use the namespace in the current context. \ No newline at end of file diff --git a/roles/wait-for-pods/tasks/main.yaml b/roles/wait-for-pods/tasks/main.yaml index 7c150b335..c311870c0 100644 --- a/roles/wait-for-pods/tasks/main.yaml +++ b/roles/wait-for-pods/tasks/main.yaml @@ -6,11 +6,11 @@ - name: Wait for all StatefulSets to become ready block: - name: Retrieve all StatefulSets - command: kubectl get statefulset -o name + command: kubectl get statefulset {% if wait_for_pods_namespace is defined %}-n {{ wait_for_pods_namespace }}{% endif %} -o name register: _statefulsets - name: Ensure the number of ready replicas matches the replicas - shell: kubectl get {{ zj_sts_item }} -ogo-template='{{ '{{' }}eq .status.replicas .status.readyReplicas{{ '}}' }}' + shell: kubectl get {{ zj_sts_item }} {% if wait_for_pods_namespace is defined %}-n {{ wait_for_pods_namespace }}{% endif %} -ogo-template='{{ '{{' }}eq .status.replicas .status.readyReplicas{{ '}}' }}' register: _is_ready until: _is_ready.stdout == 'true' retries: 60 @@ -23,11 +23,11 @@ - name: Wait for all DaemonSets to become ready block: - name: Retrieve all DaemonSets - command: kubectl get daemonset -o name + command: kubectl get daemonset {% if wait_for_pods_namespace is defined %}-n {{ wait_for_pods_namespace }}{% endif %} -o name register: _daemonsets - name: Ensure the ready number matches the scheduled number - shell: kubectl get {{ zj_ds_item }} -ogo-template='{{ '{{' }}eq .status.currentNumberScheduled .status.numberReady{{ '}}' }}' + shell: kubectl get {{ zj_ds_item }} {% if wait_for_pods_namespace is defined %}-n {{ wait_for_pods_namespace }}{% endif %} -ogo-template='{{ '{{' }}eq .status.currentNumberScheduled .status.numberReady{{ '}}' }}' register: _is_ready until: _is_ready.stdout == 'true' retries: 60 @@ -37,4 +37,4 @@ loop_var: zj_ds_item - name: Wait for all pods to become ready - command: kubectl wait --for=condition=Ready --timeout=120s pod --all + command: kubectl wait {% if wait_for_pods_namespace is defined %}-n {{ wait_for_pods_namespace }}{% endif %} --for=condition=Ready --timeout=120s pod --all