Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate resource files for k8s 1.25 #808

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
67 changes: 42 additions & 25 deletions scripts/generate-k8s-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <K8s_NAMESPACE>]
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
;;
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script downloads its own copy of the helm executable if doesn't already exist in the build directory. Since we know the script will be run twice this check prevents an unnecessary re-download.

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
Expand All @@ -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/ \
Expand Down
16 changes: 11 additions & 5 deletions scripts/upload-resources-to-github
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -21,22 +18,31 @@ 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
;;
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')
Expand Down