Skip to content

Commit 6e56019

Browse files
authored
generate resource files for k8s 1.25 (#808)
1 parent 516b4c2 commit 6e56019

File tree

3 files changed

+56
-30
lines changed

3 files changed

+56
-30
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SUPPORTED_PLATFORMS_WINDOWS ?= "windows/amd64"
1818
BINARY_NAME ?= "node-termination-handler"
1919
THIRD_PARTY_LICENSES = "${MAKEFILE_PATH}/THIRD_PARTY_LICENSES.md"
2020
GOLICENSES = $(BIN_DIR)/go-licenses
21+
K8S_1_25_ASSET_SUFFIX = "_k8s-1-25-or-newer"
2122

2223
$(shell mkdir -p ${BUILD_DIR_PATH} && touch ${BUILD_DIR_PATH}/_go.mod)
2324

@@ -118,12 +119,14 @@ build-binaries-windows:
118119

119120
upload-resources-to-github:
120121
${MAKEFILE_PATH}/scripts/upload-resources-to-github
122+
${MAKEFILE_PATH}/scripts/upload-resources-to-github -s "${K8S_1_25_ASSET_SUFFIX}"
121123

122124
upload-resources-to-github-windows:
123125
${MAKEFILE_PATH}/scripts/upload-resources-to-github -b
124126

125127
generate-k8s-yaml:
126128
${MAKEFILE_PATH}/scripts/generate-k8s-yaml
129+
${MAKEFILE_PATH}/scripts/generate-k8s-yaml -k "1.25.0" -s "${K8S_1_25_ASSET_SUFFIX}"
127130

128131
sync-readme-to-ecr-public:
129132
@ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login

scripts/generate-k8s-yaml

+42-25
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
set -euo pipefail
33

44
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
5-
6-
PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
7-
HELM_VERSION="3.7.1"
8-
NAMESPACE="kube-system"
9-
105
MAKEFILEPATH=$SCRIPTPATH/../Makefile
116
VERSION=$(make -s -f $MAKEFILEPATH version)
127
BUILD_DIR=$SCRIPTPATH/../build/k8s-resources/$VERSION
138

14-
INDV_RESOURCES_DIR=$BUILD_DIR/individual-resources
15-
TAR_RESOURCES_FILE=$BUILD_DIR/individual-resources.tar
16-
AGG_RESOURCES_YAML=$BUILD_DIR/all-resources.yaml
17-
mkdir -p $INDV_RESOURCES_DIR
18-
19-
QP_INDV_RESOURCES_DIR=$BUILD_DIR/individual-resources-queue-processor
20-
QP_TAR_RESOURCES_FILE=$BUILD_DIR/individual-resources-queue-processor.tar
21-
QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor.yaml
22-
mkdir -p $QP_INDV_RESOURCES_DIR
9+
PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
10+
HELM_VERSION="3.7.1"
11+
NAMESPACE="kube-system"
12+
K8S_VERSION="1.24.0"
13+
SUFFIX=""
2314

24-
USAGE=$(cat << 'EOM'
15+
USAGE=$(cat << EOM
2516
Usage: generate-k8s-yaml [-n <K8s_NAMESPACE>]
2617
Generates the kubernetes yaml resource files from the helm chart
2718
and places them into the build dir.
2819
Example: generate-k8s-yaml -n kube-system
2920
Optional:
30-
-n Kubernetes namespace
21+
-n NAMESPACE Kubernetes namespace
22+
-k VERSION Target Kubernetes version (default is ${K8S_VERSION})
23+
-s SUFFIX String appended to generated file and directory names
24+
-v Enable verbose output
3125
EOM
3226
)
3327

3428
# Process our input arguments
35-
while getopts "vn:" opt; do
29+
while getopts "n:k:s:v" opt; do
3630
case ${opt} in
3731
n ) # K8s namespace
3832
NAMESPACE=$OPTARG
3933
;;
34+
k ) # K8s version
35+
K8S_VERSION=$OPTARG
36+
;;
37+
s ) # Suffix
38+
SUFFIX=$OPTARG
39+
;;
4040
v ) # Verbose
4141
set -x
4242
;;
@@ -47,20 +47,35 @@ while getopts "vn:" opt; do
4747
esac
4848
done
4949

50-
curl -L https://get.helm.sh/helm-v$HELM_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $BUILD_DIR
51-
mv $BUILD_DIR/$PLATFORM-amd64/helm $BUILD_DIR/.
52-
rm -rf $BUILD_DIR/$PLATFORM-amd64
53-
chmod +x $BUILD_DIR/helm
50+
INDV_RESOURCES_DIR=${BUILD_DIR}/individual-resources${SUFFIX}
51+
TAR_RESOURCES_FILE=${BUILD_DIR}/individual-resources${SUFFIX}.tar
52+
AGG_RESOURCES_YAML=${BUILD_DIR}/all-resources${SUFFIX}.yaml
53+
mkdir -p $INDV_RESOURCES_DIR
54+
55+
QP_INDV_RESOURCES_DIR=${BUILD_DIR}/individual-resources-queue-processor${SUFFIX}
56+
QP_TAR_RESOURCES_FILE=${BUILD_DIR}/individual-resources-queue-processor${SUFFIX}.tar
57+
QP_AGG_RESOURCES_YAML=${BUILD_DIR}/all-resources-queue-processor${SUFFIX}.yaml
58+
mkdir -p $QP_INDV_RESOURCES_DIR
59+
60+
HELM=$BUILD_DIR/helm
61+
if [[ ! -e $HELM ]]; then
62+
curl -L https://get.helm.sh/helm-v$HELM_VERSION-$PLATFORM-amd64.tar.gz | tar zxf - -C $BUILD_DIR
63+
mv $BUILD_DIR/$PLATFORM-amd64/helm $BUILD_DIR/.
64+
rm -rf $BUILD_DIR/$PLATFORM-amd64
65+
chmod +x $HELM
66+
fi
5467

5568
## IMDS Mode
56-
$BUILD_DIR/helm template aws-node-termination-handler \
69+
$HELM template aws-node-termination-handler \
5770
--namespace $NAMESPACE \
71+
--kube-version ${K8S_VERSION} \
5872
--set targetNodeOs="linux windows" \
5973
$SCRIPTPATH/../config/helm/aws-node-termination-handler/ > $AGG_RESOURCES_YAML
6074

6175
## Queue Processor Mode
62-
$BUILD_DIR/helm template aws-node-termination-handler \
76+
$HELM template aws-node-termination-handler \
6377
--namespace $NAMESPACE \
78+
--kube-version ${K8S_VERSION} \
6479
--set enableSqsTerminationDraining="true" \
6580
--set enableProbesServer="true" \
6681
$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
7489
mv $BUILD_DIR/helm_annotations_removed.yaml $QP_AGG_RESOURCES_YAML
7590

7691
# IMDS Mode
77-
$BUILD_DIR/helm template aws-node-termination-handler \
92+
$HELM template aws-node-termination-handler \
7893
--namespace $NAMESPACE \
94+
--kube-version ${K8S_VERSION} \
7995
--set targetNodeOs="linux windows" \
8096
--output-dir $INDV_RESOURCES_DIR/ \
8197
$SCRIPTPATH/../config/helm/aws-node-termination-handler/
8298

8399
# Queue Processor Mode
84-
$BUILD_DIR/helm template aws-node-termination-handler \
100+
$HELM template aws-node-termination-handler \
85101
--namespace $NAMESPACE \
102+
--kube-version ${K8S_VERSION} \
86103
--set enableSqsTerminationDraining="true" \
87104
--set enableProbesServer="true" \
88105
--output-dir $QP_INDV_RESOURCES_DIR/ \

scripts/upload-resources-to-github

+11-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
88
VERSION=$(make -s -f $SCRIPTPATH/../Makefile version)
99
BUILD_DIR=$SCRIPTPATH/../build/k8s-resources/$VERSION
1010
BINARY_DIR=$SCRIPTPATH/../build/bin
11-
INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources.tar
12-
AGG_RESOURCES_YAML=$BUILD_DIR/all-resources.yaml
13-
QP_INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources-queue-processor.tar
14-
QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor.yaml
1511
BINARIES_ONLY="false"
12+
SUFFIX=""
1613

1714
USAGE=$(cat << 'EOM'
1815
Usage: upload-resources-to-github [-b]
@@ -21,22 +18,31 @@ USAGE=$(cat << 'EOM'
2118
Example: upload-resources-to-github -b
2219
Optional:
2320
-b Upload binaries only [DEFAULT: upload all the assets]
21+
-s SUFFIX String appended to resource file names
2422
EOM
2523
)
2624

2725
# Process our input arguments
28-
while getopts "b" opt; do
26+
while getopts "bs:" opt; do
2927
case ${opt} in
3028
b ) # Binaries only
3129
BINARIES_ONLY="true"
3230
;;
31+
s) # Suffix
32+
SUFFIX=$OPTARG
33+
;;
3334
\? )
3435
echo "$USAGE" 1>&2
3536
exit
3637
;;
3738
esac
3839
done
3940

41+
INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources${SUFFIX}.tar
42+
AGG_RESOURCES_YAML=$BUILD_DIR/all-resources${SUFFIX}.yaml
43+
QP_INDV_K8S_RESOURCES=$BUILD_DIR/individual-resources-queue-processor${SUFFIX}.tar
44+
QP_AGG_RESOURCES_YAML=$BUILD_DIR/all-resources-queue-processor${SUFFIX}.yaml
45+
4046
RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
4147
https://api.github.com/repos/aws/aws-node-termination-handler/releases | \
4248
jq --arg VERSION "$VERSION" '.[] | select(.tag_name==$VERSION) | .id')

0 commit comments

Comments
 (0)