From 051c00a20a6a09c72d6c4980ef76d3fcfbccf388 Mon Sep 17 00:00:00 2001 From: Anton Novikov Date: Mon, 28 Oct 2024 16:10:46 +0300 Subject: [PATCH 1/3] Add aws-cluster-*.sh hooks based on the Azure's ones. --- bin/aws-cluster-postsync-hook.sh | 50 ++++++++++++++++++++++++++++++ bin/aws-cluster-presync-hook.sh | 11 +++++++ bin/aws-cluster-uninstall-hook.sh | 9 ++++++ bin/azure-cluster-postsync-hook.sh | 7 +++++ bin/azure-cluster-presync-hook.sh | 2 +- 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100755 bin/aws-cluster-postsync-hook.sh create mode 100755 bin/aws-cluster-presync-hook.sh create mode 100755 bin/aws-cluster-uninstall-hook.sh diff --git a/bin/aws-cluster-postsync-hook.sh b/bin/aws-cluster-postsync-hook.sh new file mode 100755 index 0000000..4a18ea9 --- /dev/null +++ b/bin/aws-cluster-postsync-hook.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +set -e + +RELEASE_NAME="${1}" +NAMESPACE="${2:-azure}" +LIMIT="${3:-1200}" + +GO_TEMPLATE=' + {{- range .items -}} + {{- if eq .kind "Cluster" -}} + {{- if ne .status.phase "Provisioned" }}0{{- end }} + {{- if not .status.controlPlaneReady }}0{{- end }} + {{- if not .status.infrastructureReady }}0{{- end }} + {{- end -}} + {{- if eq .kind "AWSManagedCluster" -}} + {{- if not .status.ready }}0{{- end }} + {{- end -}} + {{- if eq .kind "AWSManagedControlPlane" -}} + {{- if not .status.ready }}0{{- end }} + {{- if not .status.initialized }}0{{- end }} + {{- end -}} + {{- if eq .kind "AWSManagedMachinePool" -}} + {{- if not .status.ready }}0{{- end -}} + {{- end -}} + {{- if eq .kind "MachinePool" -}} + {{- if ne .status.phase "Running" }}0{{- end }} + {{- if not .status.bootstrapReady }}0{{- end }} + {{- if not .status.infrastructureReady }}0{{- end }} + {{- end -}} + {{- end -}} +' + +COUNT=1 +while true; do + STATUS="$(kubectl --namespace "${NAMESPACE}" get cluster-api \ + --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 cluster-api --selector "app.kubernetes.io/instance=${RELEASE_NAME}" + break + fi +done diff --git a/bin/aws-cluster-presync-hook.sh b/bin/aws-cluster-presync-hook.sh new file mode 100755 index 0000000..fc0afa3 --- /dev/null +++ b/bin/aws-cluster-presync-hook.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +# Cluster API settings +export EXP_MACHINE_POOL="true" +# https://cluster-api-aws.sigs.k8s.io/topics/eks/enabling +export CAPA_EKS_IAM="true" +export CAPA_EKS_ADD_ROLES="true" + +clusterctl init --infrastructure aws --wait-providers diff --git a/bin/aws-cluster-uninstall-hook.sh b/bin/aws-cluster-uninstall-hook.sh new file mode 100755 index 0000000..a717433 --- /dev/null +++ b/bin/aws-cluster-uninstall-hook.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +CLUSTER_NAME="${1}" +NAMESPACE="${2}" +WAIT_FOR_CLUSTER_DELETION="${3:-false}" + +kubectl --namespace "${NAMESPACE}" delete cluster "${CLUSTER_NAME}" "--wait=${WAIT_FOR_CLUSTER_DELETION}" diff --git a/bin/azure-cluster-postsync-hook.sh b/bin/azure-cluster-postsync-hook.sh index 4c8aa7e..519889b 100755 --- a/bin/azure-cluster-postsync-hook.sh +++ b/bin/azure-cluster-postsync-hook.sh @@ -10,6 +10,8 @@ GO_TEMPLATE=' {{- range .items -}} {{- if eq .kind "Cluster" -}} {{- if ne .status.phase "Provisioned" }}0{{- end }} + {{- if not .status.controlPlaneReady }}0{{- end }} + {{- if not .status.infrastructureReady }}0{{- end }} {{- end -}} {{- if eq .kind "AzureManagedCluster" -}} {{- if not .status.ready }}0{{- end }} @@ -21,6 +23,11 @@ GO_TEMPLATE=' {{- if eq .kind "AzureManagedMachinePool" -}} {{- if not .status.ready }}0{{- end -}} {{- end -}} + {{- if eq .kind "MachinePool" -}} + {{- if ne .status.phase "Running" }}0{{- end }} + {{- if not .status.bootstrapReady }}0{{- end }} + {{- if not .status.infrastructureReady }}0{{- end }} + {{- end -}} {{- end -}} ' diff --git a/bin/azure-cluster-presync-hook.sh b/bin/azure-cluster-presync-hook.sh index 45b64da..793d9ad 100755 --- a/bin/azure-cluster-presync-hook.sh +++ b/bin/azure-cluster-presync-hook.sh @@ -2,7 +2,7 @@ set -e -# Cluster-api settings +# Cluster API settings export EXP_AKS=true export EXP_MACHINE_POOL=true export EXP_CLUSTER_RESOURCE_SET=false From b6fb4583b7baa3237d3017232cdf5cff86d78dff Mon Sep 17 00:00:00 2001 From: Anton Novikov Date: Mon, 28 Oct 2024 16:11:48 +0300 Subject: [PATCH 2/3] Fix default namespace in aws-cluster-postsync-hook.sh. --- bin/aws-cluster-postsync-hook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/aws-cluster-postsync-hook.sh b/bin/aws-cluster-postsync-hook.sh index 4a18ea9..ff5cb86 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:-azure}" +NAMESPACE="${2:-aws}" LIMIT="${3:-1200}" GO_TEMPLATE=' From 417783723e44f2a8f3be76e2ba4b9ad8a0259211 Mon Sep 17 00:00:00 2001 From: Anton Novikov Date: Tue, 29 Oct 2024 11:02:29 +0300 Subject: [PATCH 3/3] Remove aws-cluster-presync-hook.sh and azure-cluster-presync-hook.sh (already implemented in RMK). --- bin/aws-cluster-presync-hook.sh | 11 ----------- bin/azure-cluster-presync-hook.sh | 10 ---------- 2 files changed, 21 deletions(-) delete mode 100755 bin/aws-cluster-presync-hook.sh delete mode 100755 bin/azure-cluster-presync-hook.sh diff --git a/bin/aws-cluster-presync-hook.sh b/bin/aws-cluster-presync-hook.sh deleted file mode 100755 index fc0afa3..0000000 --- a/bin/aws-cluster-presync-hook.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Cluster API settings -export EXP_MACHINE_POOL="true" -# https://cluster-api-aws.sigs.k8s.io/topics/eks/enabling -export CAPA_EKS_IAM="true" -export CAPA_EKS_ADD_ROLES="true" - -clusterctl init --infrastructure aws --wait-providers diff --git a/bin/azure-cluster-presync-hook.sh b/bin/azure-cluster-presync-hook.sh deleted file mode 100755 index 793d9ad..0000000 --- a/bin/azure-cluster-presync-hook.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -e - -# Cluster API settings -export EXP_AKS=true -export EXP_MACHINE_POOL=true -export EXP_CLUSTER_RESOURCE_SET=false - -clusterctl init --infrastructure azure --wait-providers