-
Notifications
You must be signed in to change notification settings - Fork 268
/
Copy pathgenerate-k8s-yaml
executable file
·111 lines (93 loc) · 3.95 KB
/
generate-k8s-yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
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
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
EOM
)
# Process our input arguments
while getopts "vn:" opt; do
case ${opt} in
n ) # K8s namespace
NAMESPACE=$OPTARG
;;
v ) # Verbose
set -x
;;
\? )
echo "$USAGE" 1>&2
exit
;;
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
## IMDS Mode
$BUILD_DIR/helm template aws-node-termination-handler \
--namespace $NAMESPACE \
--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 \
--set enableSqsTerminationDraining="true" \
--set enableProbesServer="true" \
$SCRIPTPATH/../config/helm/aws-node-termination-handler/ > $QP_AGG_RESOURCES_YAML
# IMDS mode - remove helm annotations from template
cat $AGG_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $AGG_RESOURCES_YAML
# Queue Processor Mode - remove helm annotations from template
cat $QP_AGG_RESOURCES_YAML | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $QP_AGG_RESOURCES_YAML
# IMDS Mode
$BUILD_DIR/helm template aws-node-termination-handler \
--namespace $NAMESPACE \
--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 \
--set enableSqsTerminationDraining="true" \
--set enableProbesServer="true" \
--output-dir $QP_INDV_RESOURCES_DIR/ \
$SCRIPTPATH/../config/helm/aws-node-termination-handler/
# Queue Processor Mode - remove helm annotations from template
for i in $INDV_RESOURCES_DIR/aws-node-termination-handler/templates/*; do
cat $i | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $i
done
# IMDS Mode - remove helm annotations from template
for i in $QP_INDV_RESOURCES_DIR/aws-node-termination-handler/templates/*; do
cat $i | grep -v 'helm.sh\|app.kubernetes.io/managed-by: Helm' > $BUILD_DIR/helm_annotations_removed.yaml
mv $BUILD_DIR/helm_annotations_removed.yaml $i
done
cd $INDV_RESOURCES_DIR/aws-node-termination-handler/ && tar cvf $TAR_RESOURCES_FILE templates/*
cd $QP_INDV_RESOURCES_DIR/aws-node-termination-handler/ && tar cvf $QP_TAR_RESOURCES_FILE templates/*
cd $SCRIPTPATH
echo "Generated aws-node-termination-handler kubernetes yaml resources files in:"
echo " - $AGG_RESOURCES_YAML"
echo " - $TAR_RESOURCES_FILE"
echo " - $QP_AGG_RESOURCES_YAML"
echo " - $QP_TAR_RESOURCES_FILE"