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 2 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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 31 additions & 17 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 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,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
Expand All @@ -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
Expand All @@ -76,13 +88,15 @@ 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/

# 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/ \
Expand Down
15 changes: 14 additions & 1 deletion scripts/upload-resources-to-github
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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[@]}"
}
Expand Down