-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
executable file
·375 lines (345 loc) · 11.9 KB
/
common.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
if [ -z "${PLATEFORM}" ]; then
echo "export PLATEFORM=[ aws | vsphere | multipass | desktop ] not defined!"
exit 1
fi
set -eu
export ANNOTE_MASTER=
export APISERVER_ADVERTISE_PORT=6443
export AUTOSCALE_MACHINE="medium"
export AUTOSCALER_DESKTOP_UTILITY_ADDR=
export AUTOSCALER_DESKTOP_UTILITY_CACERT=
export AUTOSCALER_DESKTOP_UTILITY_CERT=
export AUTOSCALER_DESKTOP_UTILITY_KEY=
export AUTOSCALER_DESKTOP_UTILITY_TLS=
export AUTOSTART=true
export AWS_ACCESSKEY=
export AWS_ROUTE53_ACCESSKEY=
export AWS_ROUTE53_PRIVATE_ZONE_ID=
export AWS_ROUTE53_PROFILE=
export AWS_ROUTE53_PUBLIC_ZONE_ID=
export AWS_ROUTE53_SECRETKEY=
export AWS_ROUTE53_TOKEN=
export AWS_SECRETKEY=
export AWS_TOKEN=
export CA_LOCATION=
export CACHE=${HOME}/.local/masterkube/${PLATEFORM}/cache
export CERT_EMAIL=
export CERT_GODADDY_API_KEY=${GODADDY_API_KEY:=}
export CERT_GODADDY_API_SECRET=${GODADDY_API_SECRET:=}
export CERT_SELFSIGNED=YES
export CERT_ZEROSSL_EAB_HMAC_SECRET=${ZEROSSL_EAB_HMAC_SECRET:=}
export CERT_ZEROSSL_EAB_KID=${ZEROSSL_EAB_KID:=}
export CLOUD_IMAGES_UBUNTU=cloud-images.ubuntu.com
export CLOUD_PROVIDER_CONFIG=
export CLOUD_PROVIDER=external
export CLOUDSTACK_API_KEY=
export CLOUDSTACK_API_URL=
export CLOUDSTACK_CLUSTER_NAME=
export CLOUDSTACK_HOST_NAME=
export CLOUDSTACK_POD_NAME=
export CLOUDSTACK_PROJECT_NAME=
export CLOUDSTACK_SECRET_KEY=
export CLOUDSTACK_ZONE_NAME=
export CLUSTER_NODES=
export CNI_PLUGIN=flannel
export CNI_VERSION=v1.4.0
export CONFIGURATION_LOCATION=${PWD}
export CONTAINER_CTL=docker
export CONTAINER_ENGINE=containerd
export CONTROL_PLANE_ENDPOINT=
export CONTROL_PLANE_MACHINE="medium"
export CONTROLNODES=1
export CONTROLPLANE_USE_PUBLICIP=false
export CORESTOTAL="0:24"
export CREATE_IMAGE_ONLY=NO
export DASHBOARD_HOSTNAME=
export DELETE_CLUSTER=NO
export DEPLOY_COMPONENTS=YES
export DEPLOY_MODE=dev
export UBUNTU_DISTRIBUTION=noble
export DOMAIN_NAME=
export ETCD_DST_DIR=
export ETCD_ENDPOINT=
export EXPOSE_PUBLIC_CLUSTER=false
export EXPOSE_PUBLIC_PORTS=80,443
export EXTERNAL_DNS_PROVIDER=none
export EXTERNAL_DNS_TARGET=
export EXTERNAL_ETCD_ARGS=
export EXTERNAL_ETCD=false
export EXTERNAL_SECURITY_GROUP=
export FIRST_WORKER_NODE_IP=
export FIRSTNODE=0
export GOVC_DATACENTER=${GOVC_DATACENTER:=}
export GOVC_DATASTORE=${GOVC_DATASTORE:=}
export GOVC_FOLDER=${GOVC_FOLDER:=}
export GOVC_HOST=${GOVC_HOST:=}
export GOVC_INSECURE=${GOVC_INSECURE:=}
export GOVC_NETWORK=${GOVC_NETWORK:=}
export GOVC_PASSWORD=${GOVC_PASSWORD:=}
export GOVC_RESOURCE_POOL=${GOVC_RESOURCE_POOL:=}
export GOVC_URL=${GOVC_URL:=}
export GOVC_USERNAME=${GOVC_USERNAME:=}
export GOVC_VIM_VERSION=${GOVC_VIM_VERSION:='6.0'}
export GRPC_PROVIDER=externalgrpc
export HA_CLUSTER=false
export IMAGE_CREDENTIALS_BIN=/usr/local/bin
export IMAGE_CREDENTIALS_CONFIG=/etc/kubernetes/credential.yaml
export INTERNAL_SECURITY_GROUP=
export KUBECONFIG=${HOME}/.kube/config
export KUBERNETES_DISTRO=k3s
export KUBERNETES_PASSWORD=
export KUBERNETES_USER=kubernetes
export KUBERNETES_VERSION=$(curl -sSL https://dl.k8s.io/release/stable.txt)
export LAUNCH_CA=YES
export LOAD_BALANCER_IP=
export LOAD_BALANCER_PORT=
export LXD_CONTAINER_TYPE=container
export LXD_KUBERNETES_PROFILE=masterkube
export LXD_PROJECT=default
export LXD_REMOTE=local
export LXD_SERVER_URL=
export LXD_STORAGE_POOL=default
export LXD_TLS_CLIENT_CERT=
export LXD_TLS_CLIENT_KEY=
export LXD_TLS_SERVER_CERT=
export LXD_TLS_CA=
export MASTER_INSTANCE_PROFILE_ARN=
export MASTER_NODE_ALLOW_DEPLOYMENT=NO
export MASTER_PROFILE_NAME="kubernetes-master-profile"
export MASTERKUBE=
export MAX_PODS=110
export MAXAUTOPROVISIONNEDNODEGROUPCOUNT="1"
export MAXNODEPROVISIONTIME=15m
export MAXNODES=9
export MAXTOTALNODES=${MAXNODES}
export MEMORYTOTAL="0:96"
export METALLB_IP_RANGE=
export MICROK8S_CHANNEL=latest
export MINNODES=0
export NETWORK_PRIVATE_ROUTES=()
export NETWORK_PUBLIC_ROUTES=()
export NFS_SERVER_ADDRESS=10.0.0.5
export NFS_SERVER_PATH=/mnt/Home/home/vmware
export NFS_STORAGE_CLASS=nfs-client
export NGINX_MACHINE="tiny"
export NODEGROUP_NAME=
export OS_APPLICATION_CREDENTIAL_ID=
export OS_APPLICATION_CREDENTIAL_NAME=
export OS_APPLICATION_CREDENTIAL_SECRET=
export OS_AUTH_URL=
export OS_DOMAIN_ID=
export OS_DOMAIN_NAME=
export OS_PASSWORD=
export OS_PRIVATE_DNS_ZONEID=
export OS_PROJECT_ID=
export OS_PROJECT_NAME=
export OS_PUBLIC_DNS_ZONEID=
export OS_REGION_NAME=RegionOne
export OS_SYSTEM_SCOPE=
export OS_TENANT_ID=
export OS_TENANT_NAME=
export OS_USER_DOMAIN_NAME=
export OS_USERNAME=
export OS_ZONE_NAME=nova
export OSDISTRO=$(uname -s)
export PREFER_SSH_PUBLICIP=NO
export PRIVATE_ADDR_IPS=()
export PRIVATE_DNS_NAMES=()
export PRIVATE_DNS=192.168.2.1
export PRIVATE_DOMAIN_NAME=acme.com
export PRIVATE_GATEWAY_METRIC=100
export PRIVATE_GATEWAY=
export PRIVATE_IP_START=80
export PRIVATE_IP=
export PRIVATE_MASK_CIDR=24
export PRIVATE_NET_INF=eth0
export PRIVATE_NETMASK=255.255.255.0
export PUBLIC_ADDR_IPS=()
export PUBLIC_DNS=
export PUBLIC_DOMAIN_NAME=acme.com
export PUBLIC_GATEWAY_METRIC=100
export PUBLIC_GATEWAY=
export PUBLIC_IP=DHCP
export PUBLIC_NET_INF=eth1
export PUBLIC_NETMASK=
export PUBLIC_MASK_CIDR=24
export REGION=home
export REGISTRY=fred78290
export RESUME=NO
export SCALEDNODES_DHCP=true
export SCALEDOWNDELAYAFTERADD="1m"
export SCALEDOWNDELAYAFTERDELETE="1m"
export SCALEDOWNDELAYAFTERFAILURE="1m"
export SCALEDOWNENABLED="true"
export SCALEDOWNGPUUTILIZATIONTHRESHOLD="0.5"
export SCALEDOWNUNEEDEDTIME="1m"
export SCALEDOWNUNREADYTIME="1m"
export SCALEDOWNUTILIZATIONTHRESHOLD="0.5"
export SEED_ARCH=$([[ "$(uname -m)" =~ arm64|aarch64 ]] && echo -n arm64 || echo -n amd64)
export SEED_IMAGE="${UBUNTU_DISTRIBUTION}-server-cloudimg-seed"
export SEED_USER=ubuntu
export SILENT="&> /dev/null"
export SSH_KEY_FNAME=
export SSH_KEY=$(cat ${HOME}/.ssh/id_rsa.pub)
export SSH_KEYNAME="ssh-k8s-key"
export SSH_OPTIONS="-o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
export SSH_PRIVATE_KEY="${HOME}/.ssh/id_rsa"
export SSH_PUBLIC_KEY="${SSH_PRIVATE_KEY}.pub"
export SSL_LOCATION=
export TARGET_CLUSTER_LOCATION=
export TARGET_CONFIG_LOCATION=
export TARGET_DEPLOY_LOCATION=
export TARGET_IMAGE_AMI=
export TARGET_IMAGE="${UBUNTU_DISTRIBUTION}-kubernetes-cni-${CNI_PLUGIN}-${KUBERNETES_VERSION}-${SEED_ARCH}-${CONTAINER_ENGINE}"
export TRACE_ARGS=
export TRACE_CURL=NO
export TRACE_FILE_CURL="utility-$(date +%s).log"
export TRANSPORT="tcp"
export UNREMOVABLENODERECHECKTIMEOUT="1m"
export UPDATE_PACKAGE=false
export UPGRADE_CLUSTER=NO
export USE_CERT_SELFSIGNED=NO
export USE_CLOUDINIT_TO_CONFIGURE=false
export USE_DHCP_ROUTES_PRIVATE=true
export USE_DHCP_ROUTES_PUBLIC=true
export USE_ETC_HOSTS=true
export USE_LOADBALANCER=false
export USE_NLB=none
export USE_ZEROSSL=NO
export VC_NETWORK_PRIVATE_TYPE=
export VC_NETWORK_PRIVATE="bridged100"
export VC_NETWORK_PUBLIC_TYPE=
export VC_NETWORK_PUBLIC="en0"
export VC_NETWORK_PUBLIC_ENABLED=true
export VERBOSE=NO
export VMREST_FOLDER=
export VMREST_INSECURE=true
export VMREST_PASSWORD=
export VMREST_URL=
export VMREST_USERNAME=
export VOLUME_SIZE=20
export VOLUME_TYPE=gp3
export VPC_PRIVATE_SECURITY_GROUPID=
export VPC_PRIVATE_SUBNET_ID=()
export VPC_PRIVATE_SUBNET_IDS=()
export VPC_PUBLIC_SECURITY_GROUPID=
export VPC_PUBLIC_SUBNET_ID=()
export VPC_PUBLIC_SUBNET_IDS=()
export WORKER_INSTANCE_PROFILE_ARN=
export WORKER_NODE_MACHINE="medium"
export WORKER_PROFILE_NAME="kubernetes-worker-profile"
export WORKERNODE_USE_PUBLICIP=false
export WORKERNODES=3
export ZONEID=office
export INSTALL_BIND9_SERVER=NO
export USE_BIND9_SERVER=false
export BIND9_HOST=
export BIND9_PORT=53
export BIND9_RNDCKEY=${CURDIR}/../etc/bind/rndc.key
export SCP_OPTIONS="${SSH_OPTIONS} -p -r"
export TARGET_CONFIG_LOCATION=
export TARGET_DEPLOY_LOCATION=
export TARGET_CLUSTER_LOCATION=
export PLATEFORMDEFS=${CURDIR}/plateform/${PLATEFORM}/vars.def
if [ "${OSDISTRO}" == "Darwin" ]; then
export VMWAREWM=".vmwarevm"
else
export VMWAREWM=""
fi
# Check if passord is defined
if [ -z ${KUBERNETES_PASSWORD} ]; then
if [ -f ~/.kubernetes_pwd ]; then
KUBERNETES_PASSWORD=$(cat ~/.kubernetes_pwd)
else
KUBERNETES_PASSWORD=$(uuidgen)
echo -n "${KUBERNETES_PASSWORD}" > ~/.kubernetes_pwd
fi
fi
#===========================================================================================================================================
#
#===========================================================================================================================================
source ${CURDIR}/echo.sh
source ${CURDIR}/network.sh
source ${CURDIR}/functions.sh
#===========================================================================================================================================
#
#===========================================================================================================================================
if [ "${OSDISTRO}" == "Darwin" ]; then
if [ -z "$(command -v cfssl)" ]; then
echo_red_bold "You must install gnu cfssl with brew (brew install cfssl)"
exit 1
fi
if [ -z "$(command -v gsed)" ]; then
echo_red_bold "You must install gnu sed with brew (brew install gsed), this script is not compatible with the native macos sed"
exit 1
fi
if [ -z "$(command -v gbase64)" ]; then
echo_red_bold "You must install gnu base64 with brew (brew install coreutils), this script is not compatible with the native macos base64"
exit 1
fi
if [ ! -e /usr/local/opt/gnu-getopt/bin/getopt ] && [ ! -e /opt/homebrew/opt/gnu-getopt/bin/getopt ]; then
echo_red_bold "You must install gnu gnu-getopt with brew (brew install coreutils), this script is not compatible with the native macos base64"
exit 1
fi
if [ -z "$(command -v jq)" ]; then
echo_red_bold "You must install gnu jq with brew (brew install jq)"
exit 1
fi
shopt -s expand_aliases
alias base64=gbase64
alias sed=gsed
if [ -e /usr/local/opt/gnu-getopt/bin/getopt ]; then
alias getopt=/usr/local/opt/gnu-getopt/bin/getopt
else
alias getopt=/opt/homebrew/opt/gnu-getopt/bin/getopt
fi
function delete_host() {
sudo gsed -i "/$1/d" /etc/hosts
}
TZ=$(sudo systemsetup -gettimezone | awk -F: '{print $2}' | tr -d ' ')
TRANSPORT_IF=$(route get 1 | grep -m 1 interface | awk '{print $2}')
LOCAL_IPADDR=$(ifconfig ${TRANSPORT_IF} | grep -m 1 "inet\s" | sed -n 1p | awk '{print $2}')
else
TZ=$(cat /etc/timezone)
TRANSPORT_IF=$(ip route get 1 | awk '{print $5;exit}')
LOCAL_IPADDR=$(ip addr show ${TRANSPORT_IF} | grep -m 1 "inet\s" | tr '/' ' ' | awk '{print $2}')
function delete_host() {
sudo sed -i "/$1/d" /etc/hosts
}
fi
#===========================================================================================================================================
#
#===========================================================================================================================================
function mandatories_command() {
local CMD_MISSING=()
local MANDATORY=
for MANDATORY in $@
do
if [ -z "$(command -v ${MANDATORY})" ]; then
CMD_MISSING+=(MANDATORY)
fi
done
if [ ${#CMD_MISSING[@]} -gt 0 ]; then
echo_red "The following command ${CMD_MISSING[@]} are missing"
exit 1
fi
}
#===========================================================================================================================================
#
#===========================================================================================================================================
mkdir -p ${CACHE}
if [ ! -d ${CURDIR}/plateform/${PLATEFORM} ]; then
echo_red_bold "Unknown plateform: ${PLATEFORM}"
exit 1
fi
if [ -f ${CURDIR}/plateform/${PLATEFORM}/override.sh ]; then
source ${CURDIR}/plateform/${PLATEFORM}/override.sh
fi
source ${CURDIR}/plateform/${PLATEFORM}/plateform.sh
#===========================================================================================================================================
#
#===========================================================================================================================================
mandatories_command ${CMD_MANDATORIES}
if [ -n "${AWS_ROUTE53_PUBLIC_ZONE_ID}" ] || [ -n "${AWS_ACCESSKEY}" ] || [ -n "${AWS_SECRETKEY}" ]; then
mandatories_command aws
fi