diff --git a/Makefile b/Makefile index bff5cbd9..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,12 +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_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 bb04f4ac..efde2eb9 100755 --- a/scripts/generate-k8s-yaml +++ b/scripts/generate-k8s-yaml @@ -2,41 +2,41 @@ 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=$(cat << EOM Usage: generate-k8s-yaml [-n ] Generates the kubernetes yaml resource files from the helm chart and places them into the build dir. Example: generate-k8s-yaml -n kube-system Optional: - -n Kubernetes namespace + -n NAMESPACE Kubernetes namespace + -k VERSION Target 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,20 +47,35 @@ while getopts "vn:" opt; do esac done -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 +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 + +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" \ --set enableProbesServer="true" \ $SCRIPTPATH/../config/helm/aws-node-termination-handler/ > $QP_AGG_RESOURCES_YAML @@ -74,15 +89,17 @@ 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" \ --output-dir $INDV_RESOURCES_DIR/ \ $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" \ --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..75096254 100755 --- a/scripts/upload-resources-to-github +++ b/scripts/upload-resources-to-github @@ -8,11 +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 -AGG_RESOURCES_YAML=$BUILD_DIR/all-resources.yaml -QP_INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources-queue-processor.tar -QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor.yaml BINARIES_ONLY="false" +SUFFIX="" USAGE=$(cat << 'EOM' Usage: upload-resources-to-github [-b] @@ -21,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 @@ -37,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')