From 1b8c55d5c1ff3dd620ed89ae98ce40fffacbb934 Mon Sep 17 00:00:00 2001 From: Anton Novikov Date: Thu, 12 Dec 2024 17:13:54 +0100 Subject: [PATCH] Implement aws-iam-provision-postsync-hook.sh hook. --- bin/aws-cluster-postsync-hook.sh | 2 +- bin/aws-iam-provision-postsync-hook.sh | 32 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 bin/aws-iam-provision-postsync-hook.sh diff --git a/bin/aws-cluster-postsync-hook.sh b/bin/aws-cluster-postsync-hook.sh index ff5cb86..373262a 100755 --- a/bin/aws-cluster-postsync-hook.sh +++ b/bin/aws-cluster-postsync-hook.sh @@ -3,7 +3,7 @@ set -e RELEASE_NAME="${1}" -NAMESPACE="${2:-aws}" +NAMESPACE="${2:-capa-system}" LIMIT="${3:-1200}" GO_TEMPLATE=' diff --git a/bin/aws-iam-provision-postsync-hook.sh b/bin/aws-iam-provision-postsync-hook.sh new file mode 100755 index 0000000..2222f12 --- /dev/null +++ b/bin/aws-iam-provision-postsync-hook.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e + +RELEASE_NAME="${1:-aws-iam-provision}" +NAMESPACE="${2:-capa-system}" +LIMIT="${3:-120}" + +GO_TEMPLATE=' + {{- range .items -}} + {{- if not .status }}0{{- end }} + {{- if ne .status.phase "Provisioned" }}0{{- end }} + {{- end -}} +' + +COUNT=1 +while true; do + STATUS="$(kubectl --namespace "${NAMESPACE}" get awsiamprovision \ + --selector "app.kubernetes.io/instance=${RELEASE_NAME}" \ + --output "go-template=${GO_TEMPLATE}")" + if [[ "${STATUS}" != "" && "${COUNT}" -le "${LIMIT}" ]]; then + sleep 1 + ((++COUNT)) + elif [[ "${COUNT}" -gt "${LIMIT}" ]]; then + >2& echo "Limit exceeded." + exit 1 + else + echo + kubectl --namespace "${NAMESPACE}" get awsiamprovision --selector "app.kubernetes.io/instance=${RELEASE_NAME}" + break + fi +done