Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit eaab78a

Browse files
author
Sean Sundberg
authored
Updates logic to wait for kubeconfig (#14)
Signed-off-by: Sean Sundberg <[email protected]>
1 parent 49ac771 commit eaab78a

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

main-2-config.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ resource null_resource setup_kube_config {
6868
depends_on = [null_resource.create_dirs, data.ibm_container_cluster_config.cluster]
6969

7070
provisioner "local-exec" {
71-
command = "echo 'Waiting for 5 minutes for permissions to be established...' && sleep 300"
71+
command = "${path.module}/scripts/wait-for-kubeconfig.sh"
72+
73+
environment = {
74+
KUBECONFIG = local.cluster_config
75+
}
7276
}
7377
}
7478

scripts/wait-for-kubeconfig.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z "${KUBECONFIG}" ]]; then
4+
echo "KUBECONFIG environment variable required"
5+
exit 1
6+
fi
7+
8+
echo "Waiting for cluster config to settle"
9+
sleep 300
10+
11+
count=0
12+
while [[ ! -f "${KUBECONFIG}" ]]; do
13+
if [[ $count -eq 10 ]]; then
14+
echo "Timed out waiting for KUBECONFIG"
15+
exit 1
16+
fi
17+
18+
echo "KUBECONFIG file not available yet: ${KUBECONFIG}. Sleeping... "
19+
sleep 30
20+
21+
count=$((count + 1))
22+
done
23+
24+
count=0
25+
while ! kubectl api-resources 1> /dev/null; do
26+
if [[ $count -eq 10 ]]; then
27+
echo "Timed out waiting for login to cluster"
28+
exit 1
29+
fi
30+
31+
echo "No access yet to cluster. Sleeping..."
32+
sleep 30
33+
34+
count=$((count + 1))
35+
done

0 commit comments

Comments
 (0)