This repository has been archived by the owner on Dec 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.deployUtils
571 lines (493 loc) · 20.9 KB
/
.deployUtils
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# shellcheck shell=bash
# Shared functions between local-setup-mgc and quickstart-setup script
if ! command -v timeout &> /dev/null
then
echo "'timeout' command not found."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Try 'brew install coreutils'"
fi
exit
elif ! command -v envsubst &> /dev/null
then
echo "'envsubst' command not found."
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Try 'brew install gettext'"
fi
exit
fi
wait_for() {
local command="${1}"
local description="${2}"
local timeout="${3}"
local interval="${4}"
printf "Waiting for %s for %s...\n" "${description}" "${timeout}"
timeout --foreground "${timeout}" bash -c "
until ${command}
do
printf \"Waiting for %s... Trying again in ${interval}s\n\" \"${description}\"
sleep ${interval}
done
"
printf "%s finished!\n" "${description}"
}
configureMetalLB () {
clusterName=${1}
metalLBSubnet=${2}
kubectl config use-context kind-${clusterName}
echo "Creating MetalLB AddressPool"
cat <<EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: example
namespace: metallb-system
spec:
addresses:
- 172.31.${metalLBSubnet}.0/24
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: empty
namespace: metallb-system
EOF
}
configureManagedAddon () {
clusterName=${1}
workloadCluster=${2}
kubectl config use-context kind-${clusterName}
echo "configureManagedAddon for workload cluster kind-${workloadCluster}"
cat <<EOF | kubectl apply -f -
apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ManagedClusterAddOn
metadata:
name: kuadrant-addon
namespace: kind-${workloadCluster}
spec:
installNamespace: open-cluster-management-agent-addon
EOF
}
deployOLM(){
clusterName=${1}
kubectl config use-context kind-${clusterName}
kubectl config --kubeconfig=${TMP_DIR}/kubeconfig use-context kind-${clusterName}
echo "Installing OLM in ${clusterName}"
${OPERATOR_SDK_BIN} olm install --timeout 10m0s
}
deployOCMHub(){
clusterName=${1}
minimal=${2}
echo "installing the hub cluster in kind-(${clusterName}) "
${CLUSTERADM_BIN} init --bundle-version='0.11.0' --wait --context kind-${clusterName}
echo "PATCHING CLUSTERMANAGER: placement image patch to use amd64 image - See https://kubernetes.slack.com/archives/C01GE7YSUUF/p1685016272443249"
kubectl patch clustermanager cluster-manager --type='merge' -p '{"spec":{"placementImagePullSpec":"quay.io/open-cluster-management/placement:v0.11.0-amd64"}}' --context kind-${clusterName}
echo "checking if cluster is single or multi"
if [[ -n "${OCM_SINGLE}" ]]; then
deployOCMSpoke ${clusterName}
configureManagedAddon ${clusterName} ${clusterName}
deployOLM ${KIND_CLUSTER_CONTROL_PLANE}
if ! [[ -n "${minimal}" ]]; then
deployIstio ${KIND_CLUSTER_CONTROL_PLANE}
fi
fi
if ! [[ -n "${minimal}" ]]; then
echo "Installing Redis in kind-mgc-control-plane"
${KUSTOMIZE_BIN} build ${REDIS_KUSTOMIZATION_DIR} | kubectl apply -f -
fi
}
deployOCMSpoke() {
clusterName=${1}
echo "joining the spoke cluster to the hub cluster kind-(${KIND_CLUSTER_CONTROL_PLANE}),"
join=$(${CLUSTERADM_BIN} get token --context kind-${KIND_CLUSTER_CONTROL_PLANE} | grep -o 'join.*--cluster-name')
${CLUSTERADM_BIN} ${join} kind-${clusterName} --bundle-version='0.11.0' --feature-gates=RawFeedbackJsonString=true --force-internal-endpoint-lookup --context kind-${clusterName} | grep clusteradm
echo "accepting OCM spoke cluster invite"
max_retry=18
counter=0
until ${CLUSTERADM_BIN} accept --clusters kind-${clusterName} --context kind-${KIND_CLUSTER_CONTROL_PLANE}
do
sleep 10
[[ counter -eq $max_retry ]] && echo "Failed!" && exit 1
echo "Trying again. Try #$counter"
((++counter))
done
}
# local-setup-mgc specific functions
LOCAL_SETUP_DIR="$(dirname "${BASH_SOURCE[0]}")"
REDIS_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/kuadrant/redis
deployMetalLB () {
clusterName=${1}
metalLBSubnet=${2}
kubectl config use-context kind-${clusterName}
echo "Deploying MetalLB to ${clusterName}"
${KUSTOMIZE_BIN} build "github.com/kuadrant/multicluster-gateway-controller.git/config/metallb?ref=v0.3.0" | kubectl apply -f -
echo "Waiting for deployments to be ready ..."
kubectl -n metallb-system wait --for=condition=ready pod --selector=app=metallb --timeout=600s
configureMetalLB ${clusterName} ${metalLBSubnet}
}
deployIngressController () {
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Deploying Ingress controller to ${clusterName}"
${KUSTOMIZE_BIN} build "github.com/kuadrant/multicluster-gateway-controller.git/config/ingress-nginx?ref=v0.3.0" --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -
echo "Waiting for deployments to be ready ..."
kubectl -n ingress-nginx wait --timeout=600s --for=condition=Available deployments --all
}
deployCertManager() {
clusterName=${1}
echo "Deploying Cert Manager to (${clusterName})"
kubectl config use-context kind-${clusterName}
${KUSTOMIZE_BIN} build "github.com/kuadrant/multicluster-gateway-controller.git/config/cert-manager?ref=v0.3.0" --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -
echo "Waiting for Cert Manager deployments to be ready..."
kubectl -n cert-manager wait --timeout=300s --for=condition=Available deployments --all
kubectl delete validatingWebhookConfiguration mgc-cert-manager-webhook
kubectl delete mutatingWebhookConfiguration mgc-cert-manager-webhook
# Apply the default glbc-ca issuer
${KUSTOMIZE_BIN} build "github.com/kuadrant/multicluster-gateway-controller.git/config/policy-controller/default?ref=v0.3.0" --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -
}
deployExternalDNS() {
local EXTERNAL_DNS_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/external-dns
clusterName=${1}
echo "Deploying ExternalDNS to (${clusterName})"
kubectl config use-context kind-${clusterName}
${KUSTOMIZE_BIN} build ${EXTERNAL_DNS_KUSTOMIZATION_DIR} --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -
echo "Waiting for External DNS deployments to be ready..."
kubectl -n external-dns wait --timeout=300s --for=condition=Available deployments --all
}
deployArgoCD() {
local ARGOCD_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/argocd
clusterName=${1}
echo "Deploying ArgoCD to (${clusterName})"
kubectl config use-context kind-${clusterName}
${KUSTOMIZE_BIN} build ${ARGOCD_KUSTOMIZATION_DIR} --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -
echo "Waiting for ARGOCD deployments to be ready..."
kubectl -n argocd wait --timeout=300s --for=condition=Available deployments --all
ports=$(docker ps --format '{{json .}}' | jq "select(.Names == \"$clusterName-control-plane\").Ports")
httpsport=$(echo $ports | sed -e 's/.*0.0.0.0\:\(.*\)->443\/tcp.*/\1/')
argoPassword=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d)
nodeIP=$(kubectl get nodes -o json | jq -r ".items[] | select(.metadata.name == \"$clusterName-control-plane\").status | .addresses[] | select(.type == \"InternalIP\").address")
echo -ne "\n\n\tConnect to ArgoCD UI\n\n"
echo -ne "\t\tLocal URL: https://argocd.127.0.0.1.nip.io:$httpsport\n"
echo -ne "\t\tNode URL : https://argocd.$nodeIP.nip.io\n"
echo -ne "\t\tUser : admin\n"
echo -ne "\t\tPassword : $argoPassword\n\n\n"
}
deployIstio() {
local ISTIO_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/istio/istio-operator.yaml
clusterName=${1}
echo "Deploying Istio to (${clusterName})"
kubectl config use-context kind-${clusterName}
${ISTIOCTL_BIN} operator init
kubectl apply -f ${ISTIO_KUSTOMIZATION_DIR}
}
deployRedis(){
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Installing Redis in kind-${clusterName}"
${KUSTOMIZE_BIN} build ${REDIS_KUSTOMIZATION_DIR} | kubectl apply -f -
}
deployDashboard() {
clusterName=${1}
portOffset=${2}
echo "Deploying Kubernetes Dashboard to (${clusterName})"
kubectl config use-context kind-${clusterName}
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
${KUSTOMIZE_BIN} build config/dashboard | kubectl apply -f -
kubectl wait --timeout=-30s --for=condition=Available deployment kubernetes-dashboard -n kubernetes-dashboard
token=$(kubectl get secret/admin-user-token -n kubernetes-dashboard -o go-template="{{.data.token | base64decode}}")
port=$((proxyPort + portOffset))
kubectl proxy --context kind-${clusterName} --port ${port} &
proxyPID=$!
echo $proxyPID >> /tmp/dashboard_pids
echo -ne "\n\n\tAccess Kubernetes Dashboard\n\n"
echo -ne "\t\t\t* The dashboard is available at http://localhost:$port/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/\n"
echo -ne "\t\tAccess the dashboard using the following Bearer Token: $token\n"
}
deployAgentSecret() {
clusterName=${1}
localAccess=${2:=LOCAL_ACCESS}
if [ $localAccess == "true" ]; then
secretName=control-plane-cluster
else
secretName=control-plane-cluster-internal
fi
echo "Deploying the agent secret to (${clusterName})"
kubectl config use-context kind-${clusterName}
kubectl create namespace mgc-system || true
makeSecretForCluster $KIND_CLUSTER_CONTROL_PLANE $clusterName $localAccess |
setNamespacedName mgc-system ${secretName} |
setLabel argocd.argoproj.io/secret-type cluster |
kubectl apply -f -
}
initController() {
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Initialize local dev setup for the controller on ${clusterName}"
# Add the mgc CRDs
${KUSTOMIZE_BIN} build config/policy-controller/crd | kubectl apply -f -
${KUSTOMIZE_BIN} build config/local-setup/controller/ | kubectl apply -f -
if [[ -f "controller-config.env" && -f "gcp-credentials.env" ]]; then
${KUSTOMIZE_BIN} --reorder none --load-restrictor LoadRestrictionsNone build config/local-setup/controller/gcp | kubectl apply -f -
fi
if [[ -f "controller-config.env" && -f "aws-credentials.env" ]]; then
${KUSTOMIZE_BIN} --reorder none --load-restrictor LoadRestrictionsNone build config/local-setup/controller/aws | kubectl apply -f -
fi
}
deploySubmarinerBroker() {
clusterName=${1}
if [[ -n "${SUBMARINER}" ]]; then
${SUBCTL_BIN} deploy-broker --kubeconfig ${TMP_DIR}/kubeconfigs/external/${clusterName}.kubeconfig
fi
}
joinSubmarinerBroker() {
clusterName=${1}
if [[ -n "${SUBMARINER}" ]]; then
${SUBCTL_BIN} join --kubeconfig ${TMP_DIR}/kubeconfigs/external/${clusterName}.kubeconfig broker-info.subm --clusterid ${clusterName} --natt=false --check-broker-certificate=false
fi
}
deployThanos() {
local THANOS_KUSTOMIZATION_DIR="$2"
if [ -z "$2" ]; then
THANOS_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/thanos
fi
clusterName=${1}
if [[ -n "${METRICS_FEDERATION}" ]]; then
echo "Deploying Thanos in ${clusterName}"
kubectl config use-context kind-${clusterName}
${KUSTOMIZE_BIN} build ${THANOS_KUSTOMIZATION_DIR} | kubectl apply -f -
nodeIP=$(kubectl get nodes -o json | jq -r ".items[] | select(.metadata.name == \"$clusterName-control-plane\").status | .addresses[] | select(.type == \"InternalIP\").address")
echo -ne "\n\n\tConnect to Thanos Query UI\n\n"
echo -ne "\t\tURL : https://thanos-query.$nodeIP.nip.io\n\n\n"
echo -ne "\n\n\tConnect to Grafana UI\n\n"
echo -ne "\t\tURL : https://grafana.$nodeIP.nip.io\n\n\n"
fi
}
deployPrometheusForFederation() {
local PROMETHEUS_FOR_FEDERATION_KUSTOMIZATION_DIR="$2"
if [ -z "$2" ]; then
PROMETHEUS_FOR_FEDERATION_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/prometheus-for-federation
fi
clusterName=${1}
if [[ -n "${METRICS_FEDERATION}" ]]; then
echo "Deploying Prometheus for federation in ${clusterName}"
kubectl config use-context kind-${clusterName}
# Use server-side apply to avoid below error if re-running apply
# 'The CustomResourceDefinition "prometheuses.monitoring.coreos.com" is invalid: metadata.annotations: Too long: must have at most 262144 bytes'
# Also need to apply the CRDs first to avoid the below error types that seem to be timing related
# 'resource mapping not found for name: "alertmanager-main-rules" namespace: "monitoring" from "STDIN": no matches for kind "PrometheusRule" in version "monitoring.coreos.com/v1"''
${KUSTOMIZE_BIN} build ${PROMETHEUS_FOR_FEDERATION_KUSTOMIZATION_DIR} | ${KFILT} -i kind=CustomResourceDefinition | kubectl apply --server-side -f -
# Apply remainder of resources
${KUSTOMIZE_BIN} build ${PROMETHEUS_FOR_FEDERATION_KUSTOMIZATION_DIR} | ${KFILT} -x kind=CustomResourceDefinition | kubectl apply -f -
fi
}
installAPIDashboards() {
local PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_KUSTOMIZATION_DIR="$2"
local PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH="$3"
if [ -z "$2" ]; then
PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/../config/prometheus-for-federation/api-dashboards
fi
if [ -z "$3" ]; then
PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH=${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_KUSTOMIZATION_DIR}/grafana_deployment_patch.yaml
fi
clusterName=${1}
if [[ -n "${METRICS_FEDERATION}" ]]; then
echo "Deploying API Dashboards in ${clusterName}"
kubectl config use-context kind-${clusterName}
${KUSTOMIZE_BIN} build ${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_KUSTOMIZATION_DIR} | kubectl apply -f -
if [[ ${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH} == https* ]]; then
echo "Fetching patch file from ${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH}"
curl -L -o ${TMP_DIR}/patch.yaml ${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH}
kubectl patch deployment grafana -n monitoring --type=json -p "$(cat ${TMP_DIR}/patch.yaml)"
else
echo "Using local file at ${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH}"
kubectl patch deployment grafana -n monitoring --type=json -p "$(cat ${PROMETHEUS_FOR_FEDERATION_API_DASHBOARDS_GRAFANA_PATCH})"
fi
kubectl rollout restart deployment/grafana -n monitoring
fi
}
# quickstart-setup specific functions
setupAWSProvider() {
local namespace="$1"
if [ -z "$1" ]; then
namespace="multi-cluster-gateways"
fi
if [ "$KUADRANT_AWS_ACCESS_KEY_ID" == "" ]; then
echo "KUADRANT_AWS_ACCESS_KEY_ID is not set"
exit 1
fi
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: ${KIND_CLUSTER_PREFIX}aws-credentials
namespace: ${namespace}
type: "kuadrant.io/aws"
stringData:
AWS_ACCESS_KEY_ID: ${KUADRANT_AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${KUADRANT_AWS_SECRET_ACCESS_KEY}
AWS_REGION: ${KUADRANT_AWS_REGION}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: ${KIND_CLUSTER_PREFIX}controller-config
namespace: ${namespace}
data:
AWS_DNS_PUBLIC_ZONE_ID: ${KUADRANT_AWS_DNS_PUBLIC_ZONE_ID}
ZONE_ROOT_DOMAIN: ${KUADRANT_ZONE_ROOT_DOMAIN}
LOG_LEVEL: "${LOG_LEVEL}"
---
apiVersion: kuadrant.io/v1alpha1
kind: ManagedZone
metadata:
name: ${KIND_CLUSTER_PREFIX}dev-mz
namespace: ${namespace}
spec:
id: ${KUADRANT_AWS_DNS_PUBLIC_ZONE_ID}
domainName: ${KUADRANT_ZONE_ROOT_DOMAIN}
description: "Dev Managed Zone"
dnsProviderSecretRef:
name: ${KIND_CLUSTER_PREFIX}aws-credentials
EOF
}
setupGCPProvider() {
local namespace="$1"
if [ -z "$1" ]; then
namespace="multi-cluster-gateways"
fi
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: ${KIND_CLUSTER_PREFIX}gcp-credentials
namespace: ${namespace}
type: "kuadrant.io/gcp"
stringData:
GOOGLE: '${GOOGLE}'
PROJECT_ID: ${PROJECT_ID}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: ${KIND_CLUSTER_PREFIX}controller-config
namespace: ${namespace}
data:
ZONE_DNS_NAME: ${ZONE_DNS_NAME}
ZONE_NAME: ${ZONE_NAME}
LOG_LEVEL: "${LOG_LEVEL}"
---
apiVersion: kuadrant.io/v1alpha1
kind: ManagedZone
metadata:
name: ${KIND_CLUSTER_PREFIX}dev-mz
namespace: ${namespace}
spec:
id: ${ZONE_NAME}
domainName: ${ZONE_DNS_NAME}
description: "Dev Managed Zone"
dnsProviderSecretRef:
name: ${KIND_CLUSTER_PREFIX}gcp-credentials
EOF
}
configureController() {
clusterName=${1}
namespace=${2}
kubectl config use-context kind-${clusterName}
echo "Initialize local dev setup for the controller on ${clusterName}"
case $DNS_PROVIDER in
aws)
echo "Setting up an AWS Route 53 DNS provider"
setupAWSProvider ${namespace}
;;
gcp)
echo "Setting up a Google Cloud DNS provider"
setupGCPProvider ${namespace}
;;
*)
echo "Unknown DNS provider"
exit
;;
esac
}
deployQuickStartControl() {
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Initialize quickstart setup on ${clusterName}"
wait_for "${KUSTOMIZE_BIN} --load-restrictor LoadRestrictionsNone build ${QUICK_START_HUB_KUSTOMIZATION} --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -" "${QUICK_START_HUB_KUSTOMIZATION} control cluster config apply" "1m" "5"
echo "Waiting for metallb-system deployments to be ready"
kubectl -n metallb-system wait --for=condition=ready pod --selector=app=metallb --timeout=300s
echo "Waiting for cert-manager deployments to be ready"
kubectl -n cert-manager wait --timeout=300s --for=condition=Available deployments --all
}
deployQuickStartWorkload() {
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Initialize quickstart setup on ${clusterName}"
wait_for "${KUSTOMIZE_BIN} --load-restrictor LoadRestrictionsNone build ${QUICK_START_SPOKE_KUSTOMIZATION} --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -" "${QUICK_START_SPOKE_KUSTOMIZATION} workload cluster config apply" "1m" "5"
echo "Waiting for metallb-system deployments to be ready"
kubectl -n metallb-system wait --for=condition=ready pod --selector=app=metallb --timeout=300s
echo "Waiting for istio deployments to be ready"
kubectl -n istio-operator wait --timeout=300s --for=condition=Available deployments --all
wait_for "kubectl -n istio-system wait --for=condition=Available deployments --all" "istio-system deployments" "300s" "20"
}
configureClusterAsIngress() {
hubCluster=${1}
spokeCluster=${2}
# Ensure the current context points to the control plane cluster
kubectl config use-context kind-${hubCluster}
kubectl label managedcluster kind-${spokeCluster} ingress-cluster=true
}
deployPrometheus() {
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Deploying Prometheus in ${clusterName}"
wait_for "${KUSTOMIZE_BIN} --load-restrictor LoadRestrictionsNone build ${PROMETHEUS_DIR} --enable-helm --helm-command ${HELM_BIN} | kubectl apply -f -" "${PROMETHEUS_DIR} cluster config apply" "1m" "5"
}
deployGatekeeper(){
clusterName=${1}
kubectl config use-context kind-${clusterName}
echo "Deploying Gatekeeper in kind-${clusterName}"
${HELM_BIN} repo add gatekeeper https://open-policy-agent.github.io/gatekeeper/charts
${HELM_BIN} install gatekeeper/gatekeeper --set replicas=1 --name-template=gatekeeper --namespace gatekeeper-system --create-namespace
kubectl --context kind-${clusterName} wait --namespace=gatekeeper-system --for=condition=available --timeout=300s deployment/gatekeeper-audit
kubectl --context kind-${clusterName} wait --namespace=gatekeeper-system --for=condition=available --timeout=300s deployment/gatekeeper-controller-manager
echo "Gatekeeper Ready"
}
configureGatekeeper() {
clusterName=${1}
local GATEKEEPER_KUSTOMIZATION_DIR=${LOCAL_SETUP_DIR}/config/gatekeeper
kubectl create namespace opa-exporter --dry-run=client -o yaml | kubectl apply -f -
${KUSTOMIZE_BIN} build ${GATEKEEPER_KUSTOMIZATION_DIR}/constraint-templates | kubectl apply -f -
${KUSTOMIZE_BIN} build ${GATEKEEPER_KUSTOMIZATION_DIR} | kubectl apply -f -
}
createAWSCredentialsSecret() {
clusterName=${1}
local GATEWAY_CONFIG=${LOCAL_SETUP_DIR}/config/gateway
envsubst < ${GATEWAY_CONFIG}/aws_credentials_secret.yaml | kubectl --context kind-$clusterName apply -f -
}
createManagedZone() {
clusterName=${1}
local GATEWAY_CONFIG=${LOCAL_SETUP_DIR}/config/gateway
envsubst < ${GATEWAY_CONFIG}/managedzone.yaml | kubectl --context kind-$clusterName apply -f -
}
createGateway() {
clusterName=${1}
local GATEWAY_CONFIG=${LOCAL_SETUP_DIR}/config/gateway
envsubst < ${GATEWAY_CONFIG}/gateway.yaml | kubectl --context kind-$clusterName apply -f -
}
createTLSPolicy() {
clusterName=${1}
local GATEWAY_CONFIG=${LOCAL_SETUP_DIR}/config/gateway
envsubst < ${GATEWAY_CONFIG}/tlspolicy.yaml | kubectl --context kind-$clusterName apply -f -
}
placeGateway() {
clusterName=${1}
kubectl --context kind-$clusterName label gateway prod-web "cluster.open-cluster-management.io/placement"="http-gateway" -n multi-cluster-gateways
}
setupDemoResources() {
clusterName=${1}
createAWSCredentialsSecret ${clusterName}
createManagedZone ${clusterName}
createGateway ${clusterName}
createTLSPolicy ${clusterName}
placeGateway ${clusterName}
}