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
This commit is contained in:
Siraj Yasin 2021-09-14 15:44:10 +00:00
parent 885187f37c
commit c7be426de3
3 changed files with 54 additions and 4 deletions

View File

@ -39,13 +39,34 @@ function cloneRepo() {
git checkout FETCH_HEAD 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" ]] if [[ "$USE_CACHED_AIRSHIPCTL" = "true" ]]
then then
printf "Using cached airshipctl\n" printf "Using cached airshipctl\n"
cp -r "$CACHE_DIR/*" "$ARTIFACTS_DIR" cp -r "$CACHE_DIR/*" "$ARTIFACTS_DIR"
else else
printf "Waiting 30 seconds for the libvirt and docker services to be ready\n" check_docker_readiness
sleep 30
repo_dir="$ARTIFACTS_DIR/airshipctl" repo_dir="$ARTIFACTS_DIR/airshipctl"
cloneRepo "$repo_dir" "$AIRSHIPCTL_REPO_URL" "$AIRSHIPCTL_REPO_REF" cloneRepo "$repo_dir" "$AIRSHIPCTL_REPO_URL" "$AIRSHIPCTL_REPO_REF"

View File

@ -31,6 +31,7 @@ spec:
- name: libvirt - name: libvirt
image: quay.io/airshipit/libvirt:aiap-v1 image: quay.io/airshipit/libvirt:aiap-v1
imagePullPolicy: IfNotPresent
securityContext: securityContext:
privileged: true privileged: true
#SYS_ADMIN required for systemd, need to work out reqs for libvirt #SYS_ADMIN required for systemd, need to work out reqs for libvirt
@ -80,6 +81,7 @@ spec:
- name: sushy - name: sushy
image: quay.io/metal3-io/sushy-tools image: quay.io/metal3-io/sushy-tools
imagePullPolicy: IfNotPresent
command: command:
- bash - bash
- -cex - -cex
@ -130,6 +132,7 @@ spec:
- name: nginx - name: nginx
image: nginx:latest image: nginx:latest
imagePullPolicy: IfNotPresent
command: command:
- bash - bash
- -cex - -cex
@ -177,6 +180,7 @@ spec:
- name: dind - name: dind
image: docker:stable-dind image: docker:stable-dind
imagePullPolicy: IfNotPresent
securityContext: securityContext:
privileged: true privileged: true
volumeMounts: volumeMounts:
@ -195,6 +199,7 @@ spec:
- name: artifact-setup - name: artifact-setup
image: quay.io/airshipit/aiap-artifact-setup:latest image: quay.io/airshipit/aiap-artifact-setup:latest
imagePullPolicy: IfNotPresent
command: command:
- bash - bash
- -cex - -cex
@ -248,6 +253,7 @@ spec:
- name: infra-builder - name: infra-builder
image: quay.io/airshipit/aiap-infra-builder:latest image: quay.io/airshipit/aiap-infra-builder:latest
imagePullPolicy: IfNotPresent
securityContext: securityContext:
privileged: true privileged: true
command: command:
@ -305,6 +311,7 @@ spec:
- name: runner - name: runner
image: quay.io/airshipit/aiap-runner:latest image: quay.io/airshipit/aiap-runner:latest
imagePullPolicy: IfNotPresent
command: command:
- bash - bash
- -cex - -cex

View File

@ -24,10 +24,32 @@ function cleanup() {
rm /tmp/healthy/infra-builder rm /tmp/healthy/infra-builder
fi 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 trap cleanup EXIT
printf "Waiting 30 seconds for the libvirt and docker services to be ready\n" check_libvirt_readiness
sleep 30
ansible-playbook -v /opt/ansible/playbooks/build-infra.yaml \ ansible-playbook -v /opt/ansible/playbooks/build-infra.yaml \
-e local_src_dir="$(pwd)" -e local_src_dir="$(pwd)"