From c7be426de3894dc4fff828ff34071e4346013138 Mon Sep 17 00:00:00 2001 From: Siraj Yasin Date: Tue, 14 Sep 2021 15:44:10 +0000 Subject: [PATCH] Removed the hardcoded wait logic * Removed the hardcoded wait condition ( 30s delay ) for docker and libvirtd service * Added logic to wait until docker is available for artifact-setup. * Added logic to wait until libvritd is available for infra-builder. * Added "imagePullPolicy: IfNotPresent" to make use of local changes. Closes: #629 Change-Id: I8956cf5927be6142fcc0a3b1a112ea82511fd9bb --- .../artifact-setup/assets/entrypoint.sh | 25 ++++++++++++++++-- .../examples/base/airship-in-a-pod.yaml | 7 +++++ .../infra-builder/assets/entrypoint.sh | 26 +++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/tools/airship-in-a-pod/artifact-setup/assets/entrypoint.sh b/tools/airship-in-a-pod/artifact-setup/assets/entrypoint.sh index c8527304b..e9b317501 100755 --- a/tools/airship-in-a-pod/artifact-setup/assets/entrypoint.sh +++ b/tools/airship-in-a-pod/artifact-setup/assets/entrypoint.sh @@ -39,13 +39,34 @@ function cloneRepo() { git checkout FETCH_HEAD } +function check_docker_readiness() { + timeout=300 + + #add wait condition + end=$(($(date +%s) + $timeout)) + echo "Waiting $timeout seconds for docker to be ready." + while true; do + if ( docker version | grep 'Version' ); then + echo "docker is now ready" + break + else + echo "docker is not ready" + fi + now=$(date +%s) + if [ $now -gt $end ]; then + echo -e "\n Docker failed to become ready within a reasonable timeframe." + exit 1 + fi + sleep 10 + done +} + if [[ "$USE_CACHED_AIRSHIPCTL" = "true" ]] then printf "Using cached airshipctl\n" cp -r "$CACHE_DIR/*" "$ARTIFACTS_DIR" else - printf "Waiting 30 seconds for the libvirt and docker services to be ready\n" - sleep 30 + check_docker_readiness repo_dir="$ARTIFACTS_DIR/airshipctl" cloneRepo "$repo_dir" "$AIRSHIPCTL_REPO_URL" "$AIRSHIPCTL_REPO_REF" diff --git a/tools/airship-in-a-pod/examples/base/airship-in-a-pod.yaml b/tools/airship-in-a-pod/examples/base/airship-in-a-pod.yaml index 1fad04d93..1d8cb23e2 100644 --- a/tools/airship-in-a-pod/examples/base/airship-in-a-pod.yaml +++ b/tools/airship-in-a-pod/examples/base/airship-in-a-pod.yaml @@ -31,6 +31,7 @@ spec: - name: libvirt image: quay.io/airshipit/libvirt:aiap-v1 + imagePullPolicy: IfNotPresent securityContext: privileged: true #SYS_ADMIN required for systemd, need to work out reqs for libvirt @@ -80,6 +81,7 @@ spec: - name: sushy image: quay.io/metal3-io/sushy-tools + imagePullPolicy: IfNotPresent command: - bash - -cex @@ -130,6 +132,7 @@ spec: - name: nginx image: nginx:latest + imagePullPolicy: IfNotPresent command: - bash - -cex @@ -177,6 +180,7 @@ spec: - name: dind image: docker:stable-dind + imagePullPolicy: IfNotPresent securityContext: privileged: true volumeMounts: @@ -195,6 +199,7 @@ spec: - name: artifact-setup image: quay.io/airshipit/aiap-artifact-setup:latest + imagePullPolicy: IfNotPresent command: - bash - -cex @@ -248,6 +253,7 @@ spec: - name: infra-builder image: quay.io/airshipit/aiap-infra-builder:latest + imagePullPolicy: IfNotPresent securityContext: privileged: true command: @@ -305,6 +311,7 @@ spec: - name: runner image: quay.io/airshipit/aiap-runner:latest + imagePullPolicy: IfNotPresent command: - bash - -cex diff --git a/tools/airship-in-a-pod/infra-builder/assets/entrypoint.sh b/tools/airship-in-a-pod/infra-builder/assets/entrypoint.sh index d956f348a..952d78b11 100755 --- a/tools/airship-in-a-pod/infra-builder/assets/entrypoint.sh +++ b/tools/airship-in-a-pod/infra-builder/assets/entrypoint.sh @@ -24,10 +24,32 @@ function cleanup() { rm /tmp/healthy/infra-builder fi } + +function check_libvirt_readiness() { + timeout=300 + + #add wait condition + end=$(($(date +%s) + $timeout)) + echo "Waiting $timeout seconds for libvirt to be ready." + while true; do + if ( virsh version | grep 'library' ); then + echo "libvrit is now ready" + break + else + echo "libvirt is not ready" + fi + now=$(date +%s) + if [ $now -gt $end ]; then + echo -e "\n Libvirt failed to become ready within a reasonable timeframe." + exit 1 + fi + sleep 10 + done +} + trap cleanup EXIT -printf "Waiting 30 seconds for the libvirt and docker services to be ready\n" -sleep 30 +check_libvirt_readiness ansible-playbook -v /opt/ansible/playbooks/build-infra.yaml \ -e local_src_dir="$(pwd)"