wait-for-pods: Wait for all pods to become Ready
This refactors the code inside helm-template which waits for all pods to become Ready to move inside it's own seperate role instead which can be used for other tasks. Change-Id: Ibb234c46c49fe656cf918a7a4af115e0d26f23f0
This commit is contained in:
4
doc/source/kubernetes-roles.rst
Normal file
4
doc/source/kubernetes-roles.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Kubernetes Roles
|
||||||
|
================
|
||||||
|
|
||||||
|
.. zuul:autorole:: wait-for-pods
|
@@ -18,4 +18,5 @@ Roles
|
|||||||
puppet-roles
|
puppet-roles
|
||||||
python-roles
|
python-roles
|
||||||
translation-roles
|
translation-roles
|
||||||
|
kubernetes-roles
|
||||||
helm-roles
|
helm-roles
|
||||||
|
@@ -16,24 +16,6 @@
|
|||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
chdir: "{{ zuul_work_dir }}"
|
chdir: "{{ zuul_work_dir }}"
|
||||||
|
|
||||||
# NOTE(mnaser): When a StatefulSet is deployed, it creates the pods one
|
- name: Wait for all pods to become Ready
|
||||||
# by one, which means the `kubectl wait` can race if it
|
include_role:
|
||||||
# is ran before the other pods are created. We instead
|
name: wait-for-pods
|
||||||
# check for all the StatefulSets here manually instead
|
|
||||||
# and then use the second check below to do a "confirmation"
|
|
||||||
- name: Wait for all StatefulSets to become ready
|
|
||||||
block:
|
|
||||||
- name: Retrieve all StatefulSets
|
|
||||||
command: kubectl get statefulset -o name
|
|
||||||
register: _statefulsets
|
|
||||||
|
|
||||||
- name: Ensure the number of ready replicas matches the replicas
|
|
||||||
shell: kubectl get {{ item }} -ogo-template='{{ '{{' }}eq .status.replicas .status.readyReplicas{{ '}}' }}'
|
|
||||||
register: _is_ready
|
|
||||||
until: _is_ready.stdout == 'true'
|
|
||||||
retries: 60
|
|
||||||
delay: 5
|
|
||||||
loop: "{{ _statefulsets.stdout_lines }}"
|
|
||||||
|
|
||||||
- name: Wait for all pods to become ready
|
|
||||||
command: kubectl wait --for=condition=Ready --timeout=120s pod --all
|
|
4
roles/wait-for-pods/README.rst
Normal file
4
roles/wait-for-pods/README.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
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.
|
21
roles/wait-for-pods/tasks/main.yaml
Normal file
21
roles/wait-for-pods/tasks/main.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# NOTE(mnaser): When a StatefulSet is deployed, it creates the pods one
|
||||||
|
# by one, which means the `kubectl wait` can race if it
|
||||||
|
# is ran before the other pods are created. We instead
|
||||||
|
# check for all the StatefulSets here manually instead
|
||||||
|
# and then use the second check below to do a "confirmation"
|
||||||
|
- name: Wait for all StatefulSets to become ready
|
||||||
|
block:
|
||||||
|
- name: Retrieve all StatefulSets
|
||||||
|
command: kubectl get statefulset -o name
|
||||||
|
register: _statefulsets
|
||||||
|
|
||||||
|
- name: Ensure the number of ready replicas matches the replicas
|
||||||
|
shell: kubectl get {{ item }} -ogo-template='{{ '{{' }}eq .status.replicas .status.readyReplicas{{ '}}' }}'
|
||||||
|
register: _is_ready
|
||||||
|
until: _is_ready.stdout == 'true'
|
||||||
|
retries: 60
|
||||||
|
delay: 5
|
||||||
|
loop: "{{ _statefulsets.stdout_lines }}"
|
||||||
|
|
||||||
|
- name: Wait for all pods to become ready
|
||||||
|
command: kubectl wait --for=condition=Ready --timeout=120s pod --all
|
Reference in New Issue
Block a user