From c8321e7f60c277e6fed084048bf9c414c01592c4 Mon Sep 17 00:00:00 2001 From: Jerad C Date: Mon, 10 Apr 2023 15:47:27 -0500 Subject: [PATCH 1/3] generate resource files for k8s 1.25 --- Makefile | 1 + scripts/generate-k8s-yaml | 46 +++++++++++++++++++----------- scripts/upload-resources-to-github | 15 +++++++++- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index bff5cbd9..db659cd0 100644 --- a/Makefile +++ b/Makefile @@ -124,6 +124,7 @@ upload-resources-to-github-windows: generate-k8s-yaml: ${MAKEFILE_PATH}/scripts/generate-k8s-yaml + ${MAKEFILE_PATH}/scripts/generate-k8s-yaml -k "1.25.0" -s "_k8s-1-25" sync-readme-to-ecr-public: @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login diff --git a/scripts/generate-k8s-yaml b/scripts/generate-k8s-yaml index bb04f4ac..762d87b9 100755 --- a/scripts/generate-k8s-yaml +++ b/scripts/generate-k8s-yaml @@ -2,24 +2,15 @@ set -euo pipefail SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" - -PLATFORM=$(uname | tr '[:upper:]' '[:lower:]') -HELM_VERSION="3.7.1" -NAMESPACE="kube-system" - MAKEFILEPATH=$SCRIPTPATH/../Makefile VERSION=$(make -s -f $MAKEFILEPATH version) BUILD_DIR=$SCRIPTPATH/../build/k8s-resources/$VERSION -INDV_RESOURCES_DIR=$BUILD_DIR/individual-resources -TAR_RESOURCES_FILE=$BUILD_DIR/individual-resources.tar -AGG_RESOURCES_YAML=$BUILD_DIR/all-resources.yaml -mkdir -p $INDV_RESOURCES_DIR - -QP_INDV_RESOURCES_DIR=$BUILD_DIR/individual-resources-queue-processor -QP_TAR_RESOURCES_FILE=$BUILD_DIR/individual-resources-queue-processor.tar -QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor.yaml -mkdir -p $QP_INDV_RESOURCES_DIR +PLATFORM=$(uname | tr '[:upper:]' '[:lower:]') +HELM_VERSION="3.7.1" +NAMESPACE="kube-system" +K8S_VERSION="1.24.0" +SUFFIX="" USAGE=$(cat << 'EOM' Usage: generate-k8s-yaml [-n ] @@ -27,16 +18,25 @@ USAGE=$(cat << 'EOM' and places them into the build dir. Example: generate-k8s-yaml -n kube-system Optional: - -n Kubernetes namespace + -n NAMESPACE Kubernetes namespace + -k VERSION Kubernetes version (default is ${K8S_VERSION}) + -s SUFFIX String appended to generated file and directory names + -v Enable verbose output EOM ) # Process our input arguments -while getopts "vn:" opt; do +while getopts "n:k:s:v" opt; do case ${opt} in n ) # K8s namespace NAMESPACE=$OPTARG ;; + k ) # K8s version + K8S_VERSION=$OPTARG + ;; + s ) # Suffix + SUFFIX=$OPTARG + ;; v ) # Verbose set -x ;; @@ -47,6 +47,16 @@ while getopts "vn:" opt; do esac done +INDV_RESOURCES_DIR=${BUILD_DIR}/individual-resources${SUFFIX} +TAR_RESOURCES_FILE=${BUILD_DIR}/individual-resources${SUFFIX}.tar +AGG_RESOURCES_YAML=${BUILD_DIR}/all-resources${SUFFIX}.yaml +mkdir -p $INDV_RESOURCES_DIR + +QP_INDV_RESOURCES_DIR=${BUILD_DIR}/individual-resources-queue-processor${SUFFIX} +QP_TAR_RESOURCES_FILE=${BUILD_DIR}/individual-resources-queue-processor${SUFFIX}.tar +QP_AGG_RESOURCES_YAML=${BUILD_DIR}/all-resources-queue-processor${SUFFIX}.yaml +mkdir -p $QP_INDV_RESOURCES_DIR + curl -L https://get.helm.sh/helm-v$HELM_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $BUILD_DIR mv $BUILD_DIR/$PLATFORM-amd64/helm $BUILD_DIR/. rm -rf $BUILD_DIR/$PLATFORM-amd64 @@ -55,12 +65,14 @@ chmod +x $BUILD_DIR/helm ## IMDS Mode $BUILD_DIR/helm template aws-node-termination-handler \ --namespace $NAMESPACE \ + --kube-version ${K8S_VERSION} \ --set targetNodeOs="linux windows" \ $SCRIPTPATH/../config/helm/aws-node-termination-handler/ > $AGG_RESOURCES_YAML ## Queue Processor Mode $BUILD_DIR/helm template aws-node-termination-handler \ --namespace $NAMESPACE \ + --kube-version ${K8S_VERSION} \ --set enableSqsTerminationDraining="true" \ --set enableProbesServer="true" \ $SCRIPTPATH/../config/helm/aws-node-termination-handler/ > $QP_AGG_RESOURCES_YAML @@ -76,6 +88,7 @@ mv $BUILD_DIR/helm_annotations_removed.yaml $QP_AGG_RESOURCES_YAML # IMDS Mode $BUILD_DIR/helm template aws-node-termination-handler \ --namespace $NAMESPACE \ + --kube-version ${K8S_VERSION} \ --set targetNodeOs="linux windows" \ --output-dir $INDV_RESOURCES_DIR/ \ $SCRIPTPATH/../config/helm/aws-node-termination-handler/ @@ -83,6 +96,7 @@ $BUILD_DIR/helm template aws-node-termination-handler \ # Queue Processor Mode $BUILD_DIR/helm template aws-node-termination-handler \ --namespace $NAMESPACE \ + --kube-version ${K8S_VERSION} \ --set enableSqsTerminationDraining="true" \ --set enableProbesServer="true" \ --output-dir $QP_INDV_RESOURCES_DIR/ \ diff --git a/scripts/upload-resources-to-github b/scripts/upload-resources-to-github index 7ad23c0f..2ecd842c 100755 --- a/scripts/upload-resources-to-github +++ b/scripts/upload-resources-to-github @@ -9,9 +9,13 @@ VERSION=$(make -s -f $SCRIPTPATH/../Makefile version) BUILD_DIR=$SCRIPTPATH/../build/k8s-resources/$VERSION BINARY_DIR=$SCRIPTPATH/../build/bin INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources.tar +INDV_K8S_1_25_RESOURCES=$BUILD_DIR/individual-resources_k8s-1-25.tar AGG_RESOURCES_YAML=$BUILD_DIR/all-resources.yaml +AGG_RESOURCES_K8S_1_25_YAML=$BUILD_DIR/all-resources_k8s-1-25.yaml QP_INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources-queue-processor.tar +QP_INDV_K8S_1_25_RESOURCES=$BUILD_DIR/individual-resources-queue-processor_k8s-1-25.tar QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor.yaml +QP_AGG_RESOURCES_K8S_1_25_YAML=$BUILD_DIR/all-resources-queue-processor_k8s-1-25.yaml BINARIES_ONLY="false" USAGE=$(cat << 'EOM' @@ -68,7 +72,16 @@ gather_assets_to_upload() { resources+=("$binary") done if [ $BINARIES_ONLY != "true" ]; then - resources+=("$INDV_K8S_RESOURCES" "$AGG_RESOURCES_YAML" "$QP_INDV_K8S_RESOURCES" "$QP_AGG_RESOURCES_YAML") + resources+=( + "$INDV_K8S_RESOURCES" + "$INDV_K8S_1_25_RESOURCES" + "$AGG_RESOURCES_YAML" + "$AGG_RESOURCES_K8S_1_25_YAML" + "$QP_INDV_K8S_RESOURCES" + "$QP_INDV_K8S_1_25_RESOURCES" + "$QP_AGG_RESOURCES_YAML" + "$QP_AGG_RESOURCES_K8S_1_25_YAML" + ) fi echo "${resources[@]}" } From a37125d3cca3430e4fa3c1302620c6fde4d75370 Mon Sep 17 00:00:00 2001 From: Jerad C Date: Tue, 11 Apr 2023 10:17:54 -0500 Subject: [PATCH 2/3] fix help string variable substitution --- scripts/generate-k8s-yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate-k8s-yaml b/scripts/generate-k8s-yaml index 762d87b9..d520bc6c 100755 --- a/scripts/generate-k8s-yaml +++ b/scripts/generate-k8s-yaml @@ -12,7 +12,7 @@ NAMESPACE="kube-system" K8S_VERSION="1.24.0" SUFFIX="" -USAGE=$(cat << 'EOM' +USAGE=$(cat << EOM Usage: generate-k8s-yaml [-n ] Generates the kubernetes yaml resource files from the helm chart and places them into the build dir. From 70b9c24dac99889d1c78667ef9cccb17f6a1030f Mon Sep 17 00:00:00 2001 From: Jerad C Date: Wed, 12 Apr 2023 14:01:03 -0500 Subject: [PATCH 3/3] review feedback --- Makefile | 4 +++- scripts/generate-k8s-yaml | 21 +++++++++++--------- scripts/upload-resources-to-github | 31 ++++++++++++------------------ 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index db659cd0..5a9308f5 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ SUPPORTED_PLATFORMS_WINDOWS ?= "windows/amd64" BINARY_NAME ?= "node-termination-handler" THIRD_PARTY_LICENSES = "${MAKEFILE_PATH}/THIRD_PARTY_LICENSES.md" GOLICENSES = $(BIN_DIR)/go-licenses +K8S_1_25_ASSET_SUFFIX = "_k8s-1-25-or-newer" $(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod) @@ -118,13 +119,14 @@ build-binaries-windows: upload-resources-to-github: ${MAKEFILE_PATH}/scripts/upload-resources-to-github + ${MAKEFILE_PATH}/scripts/upload-resources-to-github -s "${K8S_1_25_ASSET_SUFFIX}" upload-resources-to-github-windows: ${MAKEFILE_PATH}/scripts/upload-resources-to-github -b generate-k8s-yaml: ${MAKEFILE_PATH}/scripts/generate-k8s-yaml - ${MAKEFILE_PATH}/scripts/generate-k8s-yaml -k "1.25.0" -s "_k8s-1-25" + ${MAKEFILE_PATH}/scripts/generate-k8s-yaml -k "1.25.0" -s "${K8S_1_25_ASSET_SUFFIX}" sync-readme-to-ecr-public: @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login diff --git a/scripts/generate-k8s-yaml b/scripts/generate-k8s-yaml index d520bc6c..efde2eb9 100755 --- a/scripts/generate-k8s-yaml +++ b/scripts/generate-k8s-yaml @@ -19,7 +19,7 @@ USAGE=$(cat << EOM Example: generate-k8s-yaml -n kube-system Optional: -n NAMESPACE Kubernetes namespace - -k VERSION Kubernetes version (default is ${K8S_VERSION}) + -k VERSION Target Kubernetes version (default is ${K8S_VERSION}) -s SUFFIX String appended to generated file and directory names -v Enable verbose output EOM @@ -57,20 +57,23 @@ QP_TAR_RESOURCES_FILE=${BUILD_DIR}/individual-resources-queue-processor${SUFFIX} QP_AGG_RESOURCES_YAML=${BUILD_DIR}/all-resources-queue-processor${SUFFIX}.yaml mkdir -p $QP_INDV_RESOURCES_DIR -curl -L https://get.helm.sh/helm-v$HELM_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $BUILD_DIR -mv $BUILD_DIR/$PLATFORM-amd64/helm $BUILD_DIR/. -rm -rf $BUILD_DIR/$PLATFORM-amd64 -chmod +x $BUILD_DIR/helm +HELM=$BUILD_DIR/helm +if [[ ! -e $HELM ]]; then + curl -L https://get.helm.sh/helm-v$HELM_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $BUILD_DIR + mv $BUILD_DIR/$PLATFORM-amd64/helm $BUILD_DIR/. + rm -rf $BUILD_DIR/$PLATFORM-amd64 + chmod +x $HELM +fi ## IMDS Mode -$BUILD_DIR/helm template aws-node-termination-handler \ +$HELM template aws-node-termination-handler \ --namespace $NAMESPACE \ --kube-version ${K8S_VERSION} \ --set targetNodeOs="linux windows" \ $SCRIPTPATH/../config/helm/aws-node-termination-handler/ > $AGG_RESOURCES_YAML ## Queue Processor Mode -$BUILD_DIR/helm template aws-node-termination-handler \ +$HELM template aws-node-termination-handler \ --namespace $NAMESPACE \ --kube-version ${K8S_VERSION} \ --set enableSqsTerminationDraining="true" \ @@ -86,7 +89,7 @@ cat $QP_AGG_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Hel mv $BUILD_DIR/helm_annotations_removed.yaml $QP_AGG_RESOURCES_YAML # IMDS Mode -$BUILD_DIR/helm template aws-node-termination-handler \ +$HELM template aws-node-termination-handler \ --namespace $NAMESPACE \ --kube-version ${K8S_VERSION} \ --set targetNodeOs="linux windows" \ @@ -94,7 +97,7 @@ $BUILD_DIR/helm template aws-node-termination-handler \ $SCRIPTPATH/../config/helm/aws-node-termination-handler/ # Queue Processor Mode -$BUILD_DIR/helm template aws-node-termination-handler \ +$HELM template aws-node-termination-handler \ --namespace $NAMESPACE \ --kube-version ${K8S_VERSION} \ --set enableSqsTerminationDraining="true" \ diff --git a/scripts/upload-resources-to-github b/scripts/upload-resources-to-github index 2ecd842c..75096254 100755 --- a/scripts/upload-resources-to-github +++ b/scripts/upload-resources-to-github @@ -8,15 +8,8 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" VERSION=$(make -s -f $SCRIPTPATH/../Makefile version) BUILD_DIR=$SCRIPTPATH/../build/k8s-resources/$VERSION BINARY_DIR=$SCRIPTPATH/../build/bin -INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources.tar -INDV_K8S_1_25_RESOURCES=$BUILD_DIR/individual-resources_k8s-1-25.tar -AGG_RESOURCES_YAML=$BUILD_DIR/all-resources.yaml -AGG_RESOURCES_K8S_1_25_YAML=$BUILD_DIR/all-resources_k8s-1-25.yaml -QP_INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources-queue-processor.tar -QP_INDV_K8S_1_25_RESOURCES=$BUILD_DIR/individual-resources-queue-processor_k8s-1-25.tar -QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor.yaml -QP_AGG_RESOURCES_K8S_1_25_YAML=$BUILD_DIR/all-resources-queue-processor_k8s-1-25.yaml BINARIES_ONLY="false" +SUFFIX="" USAGE=$(cat << 'EOM' Usage: upload-resources-to-github [-b] @@ -25,15 +18,19 @@ USAGE=$(cat << 'EOM' Example: upload-resources-to-github -b Optional: -b Upload binaries only [DEFAULT: upload all the assets] + -s SUFFIX String appended to resource file names EOM ) # Process our input arguments -while getopts "b" opt; do +while getopts "bs:" opt; do case ${opt} in b ) # Binaries only BINARIES_ONLY="true" ;; + s) # Suffix + SUFFIX=$OPTARG + ;; \? ) echo "$USAGE" 1>&2 exit @@ -41,6 +38,11 @@ while getopts "b" opt; do esac done +INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources${SUFFIX}.tar +AGG_RESOURCES_YAML=$BUILD_DIR/all-resources${SUFFIX}.yaml +QP_INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources-queue-processor${SUFFIX}.tar +QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor${SUFFIX}.yaml + RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ https://api.github.com/repos/aws/aws-node-termination-handler/releases | \ jq --arg VERSION "$VERSION" '.[] | select(.tag_name==$VERSION) | .id') @@ -72,16 +74,7 @@ gather_assets_to_upload() { resources+=("$binary") done if [ $BINARIES_ONLY != "true" ]; then - resources+=( - "$INDV_K8S_RESOURCES" - "$INDV_K8S_1_25_RESOURCES" - "$AGG_RESOURCES_YAML" - "$AGG_RESOURCES_K8S_1_25_YAML" - "$QP_INDV_K8S_RESOURCES" - "$QP_INDV_K8S_1_25_RESOURCES" - "$QP_AGG_RESOURCES_YAML" - "$QP_AGG_RESOURCES_K8S_1_25_YAML" - ) + resources+=("$INDV_K8S_RESOURCES" "$AGG_RESOURCES_YAML" "$QP_INDV_K8S_RESOURCES" "$QP_AGG_RESOURCES_YAML") fi echo "${resources[@]}" }