From c63c4ed70da51ab9b43bae34eb011156ab734714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Bedin?= Date: Sun, 19 Jun 2022 16:05:40 -0600 Subject: [PATCH] Adding role to wait for k8s/openshift api to be functional (#171) * Adding role to wait for k8s/openshift api to be functional * Adding role to wait for k8s/openshift api to be functional * Adding role to wait for k8s/openshift api to be functional --- roles/wait-for-api/README.md | 40 ++++++++++++++++++++++++++++ roles/wait-for-api/defaults/main.yml | 5 ++++ roles/wait-for-api/tasks/main.yml | 10 +++++++ 3 files changed, 55 insertions(+) create mode 100644 roles/wait-for-api/README.md create mode 100644 roles/wait-for-api/defaults/main.yml create mode 100644 roles/wait-for-api/tasks/main.yml diff --git a/roles/wait-for-api/README.md b/roles/wait-for-api/README.md new file mode 100644 index 0000000..0a95f38 --- /dev/null +++ b/roles/wait-for-api/README.md @@ -0,0 +1,40 @@ +wait-for-api +============ + +Role used to wait for the k8s/Openshift API to be ready/available + +Requirements +------------ + +Relies on the k8s or OpenShift(oc) CLI client + +Role Variables +-------------- + +Defaults file has all the variables that can be used. These can be overridden to fit the callers need. + +| Variable | Description | Required | Defaults | +|:--------:|:-----------:|:--------:|:--------:| +|**wait_for_api_delay**| number of seconds to wait between retries | no | 15 | +|**wait_for_api_retries**| number of retries before the role gives up | no | 30 | + + +Example Playbook +---------------- + +``` +- name: 'Wait for API to be available' + hosts: k8s_host + roles: + - wait-for-api +``` + +License +------- + +Apache License 2.0 + +Author Information +------------------ + +Red Hat Community of Practice & staff of the Red Hat Open Innovation Labs. diff --git a/roles/wait-for-api/defaults/main.yml b/roles/wait-for-api/defaults/main.yml new file mode 100644 index 0000000..d1a4960 --- /dev/null +++ b/roles/wait-for-api/defaults/main.yml @@ -0,0 +1,5 @@ +--- + +wait_for_api_delay: 15 +wait_for_api_retries: 30 + diff --git a/roles/wait-for-api/tasks/main.yml b/roles/wait-for-api/tasks/main.yml new file mode 100644 index 0000000..6bc0fac --- /dev/null +++ b/roles/wait-for-api/tasks/main.yml @@ -0,0 +1,10 @@ +--- + +- name: Wait for the API call to be successful + command: > + {{ client | default(oc) }} get Ingress.config/cluster + register: ingress_info + retries: "{{ wait_for_api_retries }}" # Default value in defaults/main.yml + delay: "{{ wait_for_api_delay }}" # Default value in defaults/main.yml + until: not ingress_info.failed +