diff --git a/deploy/k01/apply-infra.sh b/deploy/k01/apply-infra.sh index e0e5eb7..0e8f8b7 100755 --- a/deploy/k01/apply-infra.sh +++ b/deploy/k01/apply-infra.sh @@ -4,6 +4,30 @@ set -euo pipefail INFRA_DIR="$(cd "$(dirname "$0")/infra" && pwd)" export KUBECONFIG="${KUBECONFIG:-/etc/rancher/k3s/k3s.yaml}" +apply_docs() { + local file="$1" kind="$2" wait_expr="$3" buf i + i=0 + buf="" + while IFS= read -r line; do + if [[ "$line" == "---" ]]; then + printf '%s\n' "$buf" | kubectl apply -f - + ((i++)) + echo " ($i) applied" + buf="" + else + [[ -n "$buf" ]] && buf+=$'\n' + buf+="$line" + fi + done < "$file" + printf '%s\n' "$buf" | kubectl apply -f - + ((i++)) + echo " ($i) applied" + + if [ -n "$kind" ]; then + kubectl -n juwan wait --for="$wait_expr" --timeout=900s "$kind" --all || true + fi +} + echo envoy + ratelimit kubectl apply -f "${INFRA_DIR}/envoy.yaml" kubectl apply -f "${INFRA_DIR}/ratelimit.yaml" @@ -11,12 +35,10 @@ kubectl -n juwan wait --for=condition=Ready pod -l app=envoy-gateway --timeout=1 kubectl -n juwan wait --for=condition=Ready pod -l "app in (ratelimit,rl-redis)" --timeout=120s || true echo redis -kubectl apply -f "${INFRA_DIR}/redis.yaml" -kubectl -n juwan wait --for=jsonpath='{.status.readyReplicas}'=1 redisreplication --all --timeout=600s || true +apply_docs "${INFRA_DIR}/redis.yaml" redisreplication "jsonpath={.status.readyReplicas}=1" echo postgres -kubectl apply -f "${INFRA_DIR}/postgres.yaml" -kubectl -n juwan wait --for=condition=Ready cluster --all --timeout=900s || true +apply_docs "${INFRA_DIR}/postgres.yaml" cluster.postgresql.cnpg.io "condition=Ready" echo mongo kubectl apply -f "${INFRA_DIR}/mongo.yaml"