@leverege/build-tools 2.80.1 → 2.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.vscode/launch.json +22 -0
  2. package/package.json +7 -6
  3. package/src/Utils.mjs +2 -2
  4. package/src/bash-funcs +21 -0
  5. package/src/bitnami-audit.mjs +169 -0
  6. package/src/bitnami-audit.sh +75 -0
  7. package/src/bitnami-to-leverege-artifacts.sh +140 -0
  8. package/src/count-lines-of-code.mjs +6 -4
  9. package/src/crane-lift.sh +11 -0
  10. package/src/helm-charts/argocd/.nohelm +0 -0
  11. package/src/helm-charts/argocd/.nohelmdn +0 -0
  12. package/src/helm-charts/argocd/helmup.bootstrap +3 -0
  13. package/src/helm-charts/argocd/helmup.plugin +3 -0
  14. package/src/helm-charts/cnpg-db-pgbench/helmup.bootstrap +11 -0
  15. package/src/helm-charts/cnpg-db-psql-stack/helmup.bootstrap +11 -0
  16. package/src/helm-charts/cnpg-db-psql-stack/helmup.plugin +1 -1
  17. package/src/helm-charts/cnpg-db-recovery/helmup.bootstrap +11 -0
  18. package/src/helm-charts/cnpg-db-recovery/helmup.plugin +1 -1
  19. package/src/helm-charts/cnpg-db-tsdb-basic/helmup.bootstrap +11 -0
  20. package/src/helm-charts/cnpg-db-tsdb-basic/helmup.plugin +1 -1
  21. package/src/helm-charts/cnpg-db-tsdb-dense/helmup.bootstrap +11 -0
  22. package/src/helm-charts/cnpg-db-tsdb-dense/helmup.plugin +1 -1
  23. package/src/helm-charts/cnpg-operator/helmdn.plugin +1 -1
  24. package/src/helm-charts/cnpg-operator/helmup.bootstrap +201 -0
  25. package/src/helm-charts/cnpg-operator/helmup.plugin +1 -1
  26. package/src/helm-charts/cnpg-operator/operand.bootstrap +41 -0
  27. package/src/helm-charts/elasticsearch8/elasticsearch-local-dev.yaml +9 -0
  28. package/src/helm-charts/elasticsearch8/elasticsearch-local-prd.yaml +9 -0
  29. package/src/helm-charts/elasticsearch8/helmup.plugin +3 -3
  30. package/src/helm-charts/pgbouncer/helmup.bootstrap +24 -0
  31. package/src/helm-charts/postgres/.nohelm +0 -0
  32. package/src/helm-charts/postgres/.nohelmdn +0 -0
  33. package/src/helm-charts/postgres/README.md +6 -0
  34. package/src/helm-charts/postgres/helmdn.plugin +3 -0
  35. package/src/helm-charts/postgres/helmup.plugin +21 -0
  36. package/src/helm-charts/postgres/postgres-local.yaml +51 -0
  37. package/src/helm-charts/prom-operator/helmup.bootstrap +47 -0
  38. package/src/helm-charts/prom-operator/rules/traefik-rules.yaml +2 -2
  39. package/src/helm-charts/prom-operator/stackdriver-exporter.yaml.ovh +2 -1
  40. package/src/helm-charts/redis/helmup.plugin +2 -2
  41. package/src/helm-charts/redis/values-local.yaml +14 -0
  42. package/src/helm-charts/traefik/helmup.plugin +1 -1
  43. package/src/helm-charts/traefik/values-local.yaml +1 -1
  44. package/src/helm-charts/valkey/helmup.plugin +3 -3
  45. package/src/helm-charts/valkey/valkey-local.yaml +11 -1
  46. package/src/helm-charts/velero/helmup.bootstrap +104 -0
  47. package/src/helm-charts/velero/helmup.plugin +1 -1
  48. package/src/helmdn.sh +2 -1
  49. package/src/helmup.sh +65 -644
  50. package/src/init-my-chart.mjs +18 -0
  51. package/src/k8x.sh +4 -0
  52. package/src/overwhelm.mjs +1 -1
  53. package/.vscode/settings.json +0 -3
package/src/helmup.sh CHANGED
@@ -37,6 +37,7 @@ PLATFORM=(
37
37
  )
38
38
 
39
39
  AUXILIARY=(
40
+ argocd
40
41
  fota-server
41
42
  geotile-server
42
43
  overdose
@@ -48,8 +49,15 @@ AUXILIARY=(
48
49
  vin-decoder-server
49
50
  )
50
51
 
51
- # zombie-killer re-enabled 20240801
52
+ # There's a chicken / egg situation that arises with new clusters in that
53
+ # traefik wants to enable a prometheus service monitor, but the prom operator
54
+ # CRDs are yet to be installed - and the operator wants to define a traefik
55
+ # route for grafana so traefik needs to exist early. Note, this is only a
56
+ # problem on clean installs where the CRDs for those services are not yet
57
+ # installed.
52
58
  SYSTEM=(
59
+ traefik
60
+ prom-operator
53
61
  elasticsearch8
54
62
  redis
55
63
  cnpg-operator
@@ -57,52 +65,24 @@ SYSTEM=(
57
65
  zombie-killer
58
66
  reflector
59
67
  reloader
60
- traefik
61
68
  velero
62
69
  cnpg-db-psql-stack
63
70
  cnpg-db-tsdb-basic
64
- prom-operator
65
71
  )
66
72
 
67
73
  SYSTEM_LEGACY=(
68
- elasticsearch8
69
- redis
74
+ elasticsearch
70
75
  postgres
71
76
  timescale-db
72
- preemptible-killer
73
- zombie-killer
74
- reflector
75
- reloader
76
- traefik
77
- velero
78
77
  monitoring # do monitoring last to show password
79
78
  )
80
79
 
81
80
  function isLeveregeService() {
82
81
  local answer=0
83
- [[ ${PLATFORM[@]} =~ $1 || ${AUXILIARY[@]} =~ $1 || ${SYSTEM_LEGACY[@]}} =~ 1 || ${SYSTEM[@]} =~ $1 ]] && answer=1
82
+ [[ ${PLATFORM[@]} =~ $1 || ${AUXILIARY[@]} =~ $1 || ${SYSTEM_LEGACY[@]}} =~ $1 || ${SYSTEM[@]} =~ $1 ]] && answer=1
84
83
  echo $answer
85
84
  }
86
85
 
87
- # audit trail via slack
88
- # support for legacy bitnami charts
89
- function addBitnamiRepo() {
90
- if [ ! -z "$BITNAMI_LATEST" ] || [ "$1" == "latest" ];
91
- then
92
- BITNAMI_URL="https://charts.bitnami.com/bitnami"
93
- else
94
- cat<<CATNAMI
95
- Using the pre 2022 legacy charts from bitnami. To use latest run:
96
-
97
- `color y "BITNAMI_LATEST=1 $HELMUP_ARGS"`
98
-
99
- CATNAMI
100
- BITNAMI_URL="https://raw.githubusercontent.com/bitnami/charts/eb5f9a9513d987b519f0ecd732e7031241c50328/bitnami"
101
- fi
102
-
103
- addHelmRepo bitnami $BITNAMI_URL
104
- }
105
-
106
86
  # Accepts 3 paramaters - 1 mandatory.
107
87
  # bindWorkloadIdentity <Service Account> <Namespace> <Target Service Account>
108
88
  # where:
@@ -199,30 +179,9 @@ function setupStackBuckets() {
199
179
  makeUniformBucketWithCors geotile-server PUBLIC
200
180
  }
201
181
 
202
- function setupPgbouncerSecret() {
203
- # pgbouncer uses a k8s secret for the user access list which is in the form
204
- # of => "user" "password" - this function will create the pgbouncer secret
205
- # if it does not exist by pulling the password from the PG_PASSWORD secret
206
- # managed by the Google Secret Manager service.
207
- USERLIST_SECRET='pgbouncer-userlist-secret'
208
- kubectl get secret $USERLIST_SECRET &> $DEVNULL
209
- [[ $? -eq 0 ]] && return # already exists - bail
210
-
211
- cat<<PGB_SECRET
212
-
213
- `color y "Creatng $USERLIST_SECRET k8s secret from secret manager PG_PASSWORD secret..."`
214
-
215
- PGB_SECRET
216
- DECODED_PSQL_PASSWORD=$(gcloud secrets versions access latest --secret=PG_PASSWORD --project $GCP_PROJECT_ID)
217
- exitOnError $? "Failed to fetch PG_PASSWORD from the secret manager"
218
-
219
- kubectl create secret generic $USERLIST_SECRET --from-literal=userlist.txt="\"postgres\" \"$DECODED_PSQL_PASSWORD\""
220
- exitOnError $? "Failed to create the $USERLIST_SECRET k8s secret"
221
- }
222
-
223
182
  function doPlatormPreInstallChecks() {
224
183
  # This is where we handle platform specific things that need to be setup,
225
- # usuall once, and then promptly forgotten about.
184
+ # usually once, and then promptly forgotten about.
226
185
  setupStackBuckets
227
186
  }
228
187
 
@@ -265,11 +224,56 @@ MISSING_HELMUP_PLUGIN
265
224
  cp -a $SERVICE_CHART .
266
225
  # because npm tends to not allow .gitinore files the easy way...
267
226
  find $SERVICE -type f -name "gitignore" -execdir mv {} .gitignore \;
268
- git add $SERVICE
269
227
  overwhelm --genvals
228
+ FIRST_RUN="$SERVICE/helmup.bootstrap"
229
+ if [ -f "$FIRST_RUN" ];
230
+ then
231
+ [ ! -x "$FIRST_RUN" ] && chmod +x "$FIRST_RUN" # force it to be executable
232
+ cat<<SERVICE_BOOTSTRAP
233
+
234
+ `color y "*** Bootstrapping $SERVICE with =>"` `color g "$FIRST_RUN"`
235
+
236
+ SERVICE_BOOTSTRAP
237
+
238
+ . "$FIRST_RUN"
239
+ if [[ $? = 1 ]];
240
+ then
241
+ rm -rf "$SERVICE"
242
+ exit 1
243
+ fi
244
+ fi
245
+ git add $SERVICE
270
246
  ifPluggedIn $SERVICE
271
247
  }
272
248
 
249
+ # some initial installs may be performed from the local setups in the
250
+ # build-tools helm-charts directory
251
+ function ifCanBootstrap() {
252
+ local bootstrap_targets=(
253
+ argocd
254
+ cnpg-operator
255
+ cnpg-db-psql-stack
256
+ cnpg-db-tsdb-basic
257
+ elasticsearch8
258
+ pgbouncer
259
+ prom-operator
260
+ redis
261
+ valkey
262
+ traefik
263
+ traefik-canary
264
+ velero
265
+ )
266
+ local svc_name="$1"
267
+
268
+ if [[ " ${bootstrap_targets[*]} " == *" $svc_name "* ]];
269
+ then
270
+ bootstrapLocalSetup $svc_name
271
+ return 0
272
+ else
273
+ return 1
274
+ fi
275
+ }
276
+
273
277
  function installDefaultConfigs() {
274
278
  showInstalling "Default Configs"
275
279
 
@@ -298,110 +302,6 @@ function errorIfMissingSecret() {
298
302
  fi
299
303
  }
300
304
 
301
- function installFirebaseDatabases() {
302
- showInstalling "Firebase Realtime Databases"
303
-
304
- open https://console.firebase.google.com/u/0/project/${GCP_PROJECT_ID}/authentication/users
305
- yesToContinue "when you have pressed Get Started on the Firebase Authentication page"
306
-
307
- # create the firebase primary db
308
- firebase --project $GCP_PROJECT_ID database:instances:create ${PROJECT}
309
-
310
- # TODO: should maybe be more flexible with number of shards in the future
311
- for SHARD in {0..9}
312
- do
313
- SHARD="${GCP_PROJECT_ID}-rt-${SHARD}"
314
- printf "Creating shard $SHARD\n"
315
- firebase --project $GCP_PROJECT_ID database:instances:create ${SHARD}
316
- done
317
- }
318
-
319
- function installStackdriverExporterEnvironment() {
320
- showInstalling "Stackdriver Exporter Service Account Binding"
321
-
322
- # Add necessary helm repositories - note that stable is deprecated
323
- addHelmRepo prometheus-community https://prometheus-community.github.io/helm-charts
324
-
325
- local SDEXP_NS=${1:-monitoring}
326
- local SDEXP_SA="stackdriver-exporter"
327
- local SDEXP_EM="$SDEXP_SA@$GCP_PROJECT_ID.iam.gserviceaccount.com"
328
-
329
- createNamespaceIfNeeded $SDEXP_NS
330
-
331
- # guarantee any previous remnants of the exporter are gone
332
- printf "\n*** Removing the previous $SDEXP_SA installation...\n"
333
- helm uninstall -n $SDEXP_NS $SDEXP_SA &> $DEVNULL
334
- kubectl delete serviceaccounts -n $SDEXP_NS $SDEXP_SA &> $DEVNULL
335
- printf "!!! Skipping deletion of the gcloud SA $SDEXP_EM\n"
336
- # gcloud --quiet iam service-accounts delete $SDEXP_EM &> $DEVNULL
337
-
338
- # NOTE: The k8s SA != GCP SA - the former is created by the helm chart
339
- # that installs the stackdriver-exporter, the latter is handled here in
340
- # order to provide the proper IAM permissions to the exporter.
341
-
342
- # Create GCP SA and bind policies
343
- printf "\n*** Creating GCP SA with $SDEXP_NS/viewer ***\n"
344
- gcloud iam service-accounts create $SDEXP_SA \
345
- --project "$GCP_PROJECT_ID" \
346
- --display-name "Prometheus Stackdriver Exporter" &> $DEVNULL
347
- warnOnError $? "the GCP SA $SDEXP_SA may already exist"
348
-
349
- printf "\n*** Binding IAM role of $SDEXP_NS viewer to $SDEXP_SA in $GCP_PROJECT_ID\n"
350
- gcloud projects add-iam-policy-binding "$GCP_PROJECT_ID" \
351
- --role "roles/monitoring.viewer" \
352
- --member "serviceAccount:$SDEXP_EM" &> $DEVNULL
353
- sleep 2 # give the IAM binding a chance to complete before moving on
354
-
355
- bindWorkloadIdentity $SDEXP_SA $SDEXP_NS
356
-
357
- removeHelmRepo prometheus-community
358
- }
359
-
360
- function installMonitoringEnvironment() {
361
- showInstalling "Monitoring Components"
362
- createNamespaceIfNeeded monitoring
363
-
364
- ## Install Stackdriver Exporter
365
- installStackdriverExporterEnvironment
366
- bootstrapLocalSetup stackdriver-exporter
367
-
368
- # Add necessary helm repositories - note that stable is deprecated
369
- addHelmRepo prometheus-community https://prometheus-community.github.io/helm-charts
370
-
371
- ## Install Prometheus
372
- bootstrapLocalSetup prometheus
373
-
374
- ## Install Grafana
375
- bootstrapLocalSetup grafana
376
-
377
- ## Clean up
378
- removeHelmRepo prometheus-community
379
- }
380
-
381
- function monitoringHelp() {
382
- MONPASS=`kubectl get secret --namespace monitoring grafana -o jsonpath='{.data.admin-password}' | base64 --decode`
383
-
384
- cat<<ACCESS
385
- `color g "Proxy to Prometheus (manage targets, configs, alerts):"`
386
- export POD_NAME=\$(kubectl get pods --namespace monitoring -l 'app=prometheus,component=server' -o jsonpath='{.items[0].metadata.name}')
387
- kubectl --namespace monitoring port-forward \$POD_NAME 9090
388
-
389
- `color g "Proxy to Alertmanager (manage alert notification, silences):"`
390
- export POD_NAME=\$(kubectl get pods --namespace monitoring -l 'app=prometheus,component=alertmanager' -o jsonpath='{.items[0].metadata.name}')
391
- kubectl --namespace monitoring port-forward \$POD_NAME 9093
392
-
393
- `color g "Proxy to Grafana (the charts you're looking for):"`
394
- export GRAFANA_POD=\$(kubectl --namespace monitoring get pods -l 'app.kubernetes.io/instance=grafana' -o jsonpath='{.items[0].metadata.name}')
395
- kubectl --namespace monitoring port-forward \$GRAFANA_POD 3000 &
396
- sleep 2; open http://localhost:3000
397
-
398
- `color toast "Save monitoring login to Keeper"` => `color r "admin / $MONPASS"`
399
-
400
- `color g "Show this helpful message again with"` => `color r "helmup monitoring-wtf"`
401
-
402
- ACCESS
403
- }
404
-
405
305
  # https://github.com/estafette/estafette-gke-preemptible-killer
406
306
  function installPreemptibleKiller() {
407
307
  showInstalling "Preemptible Node Killing Coordinator"
@@ -514,34 +414,6 @@ status: {}
514
414
  END_OF_ZOMBIE
515
415
  }
516
416
 
517
- function installCertManagerSecret() {
518
- showInstalling "Cert Managment"
519
- createNamespaceIfNeeded cert-manager
520
-
521
- local NSPACE="default"
522
- kubectl get secret cloudflare --namespace $NSPACE &> $DEVNULL
523
- if [[ $? -eq 1 ]];
524
- then
525
- cat<<NEED_MANAGED_SECRET
526
- $RED_ERROR missing secret: `color y cloudflare` namespace: `color y $NSPACE`
527
-
528
- This secret will be fetched from the leverege-docker-images cluster and
529
- injected into this cluster.
530
- NEED_MANAGED_SECRET
531
- #yesToContinue "to copy and inject the cloudflare secret"
532
- TOKEN=$(getManagedSecret "CLOUDFLARE_API_TOKEN")
533
- if [ $? -ne 0 ];
534
- then
535
- printf "$RED_ERROR getManagedSecret reponse=>[$TOKEN]"
536
- exitOnError 1 "Failed to fetch the secret from leverege-docker-images"
537
- fi
538
- printf "\nInjecting=[$TOKEN] into cloudflare secret\n"
539
- kubectl create secret generic cloudflare \
540
- --namespace $NSPACE \
541
- --from-literal=dns-token=$TOKEN
542
- fi
543
- }
544
-
545
417
  # See => https://github.com/emberstack/kubernetes-reflector
546
418
  function reflectSecretIntoNamespaces() {
547
419
  local SECRET="$1"
@@ -566,238 +438,8 @@ metadata:
566
438
  REFLECTED_SECRET
567
439
  }
568
440
 
569
- # This function is used to randomly generate the postgresql database passwords
570
- # for the postgres and imagine users in a cnpg operator configuration. Since
571
- # the resultant passwords will live in the cnpg-operands namespace they will
572
- # be mirrored to the default namespace via the reflector service. Lastly, the
573
- # service account will have workload identity bound to it in the cnpg-operands
574
- # namespace.
575
- function initializeCnpgOperand() {
576
- local CNPG_SERVICE="$1"
577
- local CNPG_NAMESPACE="cnpg-operands"
578
- local CNPG_SVC_ACCT="$CNPG_NAMESPACE-sa"
579
- local IMAGINE_PW_NAME="$CNPG_SERVICE-imagine-pw"
580
- local POSTGRES_PW_NAME="$CNPG_SERVICE-postgres-pw"
581
-
582
- # TODO: we use postgres root password for access - that is bad - fix it?
583
- # printf "\nCreating imagine db password for `color g $CNPG_SERVICE`\n"
584
- # kubectl create secret generic -n $CNPG_NAMESPACE "$IMAGINE_PW_NAME" \
585
- # --from-literal=username="imagine" \
586
- # --from-literal=password="$(generatePassword)" &> $DEVNULL
587
- # warnOnError $? "the `color y $IMAGINE_PW_NAME` secret may already exist"
588
-
589
- # # reflect the secret to default namespace
590
- # reflectSecretIntoNamespaces $IMAGINE_PW_NAME $CNPG_NAMESPACE "default"
591
-
592
- printf "\nCreating postgres db password for `color g $CNPG_SERVICE`\n"
593
- kubectl create secret generic -n $CNPG_NAMESPACE "$POSTGRES_PW_NAME" \
594
- --from-literal=username="postgres" \
595
- --from-literal=password="$(generatePassword)" &> $DEVNULL
596
- warnOnError $? "the `color y $POSTGRES_PW_NAME` secret may already exist"
597
-
598
- # reflect the secret to default namespace
599
- reflectSecretIntoNamespaces $POSTGRES_PW_NAME $CNPG_NAMESPACE "default"
600
-
601
- printf "\nBinding `color g $CNPG_SERVICE` to the `color y "$CNPG_SVC_ACCT"` SA\n"
602
- bindWorkloadIdentity $CNPG_SVC_ACCT $CNPG_NAMESPACE $CNPG_SERVICE
603
- }
604
-
605
- function installCnpgOperatorEnvironment() {
606
- # See => https://github.com/cloudnative-pg/charts
607
-
608
- gcloud config set project $GCP_PROJECT_ID
609
-
610
- # create an SA in the cnpg namespace for the operands to bind to
611
- CNPG_NAMESPACE="cnpg-operands"
612
- CNPG_SVC_ACCT="$CNPG_NAMESPACE-sa"
613
- CNPG_SVC_EMAIL="$CNPG_SVC_ACCT@$GCP_PROJECT_ID.iam.gserviceaccount.com"
614
-
615
- # We used to delete the SA when we were doing clean installs but that bit
616
- # me in the ass the time I moved the operator dir out of the way to run
617
- # helmwhat to populate with latest operator version. The result? The SA
618
- # was deleted and recreated and the existing system lost the ability to
619
- # write to GCS which resulted in WAL failures. The deletion / recreation
620
- # logic was only useful in the early days of creating / deleting for
621
- # initial development.
622
- #
623
- # Synopsis: deleting an SA from an actual non-test system is BAD NEWS
624
- # and if it happens then you will need to rebind the SA to
625
- # workload identity by hand.
626
- #
627
- # kubectl delete serviceaccounts -n $CNPG_NAMESPACE $CNPG_SVC_ACCT &> $DEVNULL
628
- # gcloud --quiet iam service-accounts delete $CNPG_SVC_EMAIL --project $GCP_PROJECT_ID&> $DEVNULL
629
- kubectl describe serviceaccounts -n $CNPG_NAMESPACE $CNPG_SVC_ACCT &> $DEVNULL
630
- if [ $? -eq 0 ];
631
- then
632
- cat<<SKIP_CNPG_SA_CREATION
633
-
634
- $YELO_WARN The CNPG SA $CNPG_SVC_ACCT already exists
635
-
636
- Deleting the SA for the purposes of upgrading the operator is going to
637
- wreck someone's day (probably yours) if the desire is to simply upgrade
638
- in place. To force a clean reinstall, delete both the k8s and gcp SA for
639
- CNPG and try again. (see comments in helmup for more info)
640
-
641
- SKIP_CNPG_SA_CREATION
642
- return
643
- fi
644
-
645
- # Create the operands namespace and annotate to allow redis access
646
- createNamespaceIfNeeded $CNPG_NAMESPACE
647
-
648
- # Create GCP SA and bind policies
649
- printf "\nCreating the gcloud `color g $CNPG_SVC_ACCT` service account (SA)\n"
650
- gcloud iam service-accounts create $CNPG_SVC_ACCT \
651
- --project "$GCP_PROJECT_ID" \
652
- --description "CNPG Operands SA" \
653
- --display-name "CNPG Operands SA" &> $DEVNULL
654
- warnOnError $? "the GCP SA `color y $CNPG_SVC_ACCT` may already exist"
655
-
656
- CNPG_OPS_ROLE="cnpg.operands"
657
- printf "\nCreating the `color g $CNPG_OPS_ROLE` IAM role\n"
658
- ## Attach roles
659
- ROLE_PERMISSIONS=(
660
- iam.serviceAccounts.actAs
661
- iam.serviceAccounts.get
662
- iam.serviceAccounts.getAccessToken
663
- iam.serviceAccounts.getOpenIdToken
664
- iam.serviceAccounts.implicitDelegation
665
- iam.serviceAccounts.list
666
- iam.serviceAccounts.signBlob
667
- iam.serviceAccounts.signJwt
668
- resourcemanager.projects.get
669
- storage.buckets.create
670
- storage.buckets.get
671
- storage.buckets.getIamPolicy
672
- storage.buckets.list
673
- storage.buckets.update
674
- storage.objects.create
675
- storage.objects.delete
676
- storage.objects.get
677
- storage.objects.getIamPolicy
678
- storage.objects.list
679
- )
680
- gcloud iam roles create $CNPG_OPS_ROLE \
681
- --project $GCP_PROJECT_ID \
682
- --title "CNPG Operands" \
683
- --description "CNPG Operands" \
684
- --permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
685
- if [ $? -ne 0 ];
686
- then
687
- # assume error is that role exists so try updating instead
688
- printf "\nUpdating the permissions on the `color g $CNPG_OPS_ROLE` IAM role\n"
689
- gcloud iam roles update $CNPG_OPS_ROLE \
690
- --project $GCP_PROJECT_ID \
691
- --title "CNPG Operands" \
692
- --permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
693
- fi
694
- warnOnError $? "Failed to add roles to $CNPG_OPS_ROLE - perhaps they already exist?"
695
-
696
- printf "\nBinding IAM role to the SA `color g $CNPG_SVC_EMAIL`\n"
697
- gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
698
- --member="serviceAccount:$CNPG_SVC_EMAIL" \
699
- --role "roles/storage.admin" &> $DEVNULL
700
- # --role projects/$GCP_PROJECT_ID/roles/$CNPG_OPS_ROLE &> $DEVNULL
701
- # --role "roles/storage.admin" &> $DEVNULL
702
- warnOnError $? "gcloud problem binding IAM policy"
703
-
704
- printf "\nBinding IAM the Token Creator role to the SA `color g $CNPG_SVC_EMAIL`\n"
705
- gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
706
- --member="serviceAccount:$CNPG_SVC_EMAIL" \
707
- --role="roles/iam.serviceAccountTokenCreator"
708
-
709
- # workload binding will be performed by each cnpg operand on startup
710
-
711
- BARMAN_BUCKET="gs://$GCP_PROJECT_ID-barman"
712
- gsutil ls -p $GCP_PROJECT_ID -b $BARMAN_BUCKET &> $DEVNULL
713
- if [ "$?" -eq 0 ];
714
- then
715
- printf "\nBarman bucket `color g "$BARMAN_BUCKET"` already exists - skipping recreation\n"
716
- else
717
- printf "\nCreating a bucket for barman backups: `color g $BARMAN_BUCKET`\n"
718
- gsutil mb -l $GCE_REGION $BARMAN_BUCKET &> $DEVNULL
719
- gsutil iam ch serviceAccount:$CNPG_SVC_EMAIL:objectAdmin $BARMAN_BUCKET
720
- gsutil ubla set on $BARMAN_BUCKET # uniform bucket access
721
- fi
722
-
723
- # define the snapshot storage class
724
- printf "\nApplying the CNPG VolumeSnapshotClass `color g cnpg-snapshotclass` definition\n"
725
- cat<<EOSNAPSC | kubectl apply -f -
726
- apiVersion: snapshot.storage.k8s.io/v1
727
- kind: VolumeSnapshotClass
728
- metadata:
729
- name: cnpg-snapshotclass
730
- driver: pd.csi.storage.gke.io
731
- deletionPolicy: Retain
732
- EOSNAPSC
733
-
734
- sleep 2 # hold up processing for a moment to allow IAM mods to propagate
735
- }
736
-
737
- # this function is a little convoluted in the way it attempts to install the
738
- # scripts and yaml necessary for the CNPG cleanup activities - the idea is to
739
- # be able to update the scripts without touching anything else since the target
740
- # directory is the cnpg-operator setup
741
- function installCnpgCleanupCronjob() {
742
- CNPG_OPERATOR_DIR="cnpg-operator"
743
- if [ ! -d "$CNPG_OPERATOR_DIR" ];
744
- then
745
- cat<<CNPG_OPERATOR_MISSING
746
- `color r "The cnpg-operator must be installed before proceeding"`
747
-
748
- CNPG_OPERATOR_MISSING
749
- exit 1
750
- fi
751
-
752
- # create the destination bucket for k8s cronjob scripts
753
- BUCKET_SUFFIX="k8s-cronjobs"
754
- makeUniformBucketWithCors $BUCKET_SUFFIX
755
-
756
- CNPG_CLEANUP_CRONJOB_OVH="cnpg-cleanup-cronjob.yaml.ovh"
757
- CNPG_CLEANUP_CRONJOB="$CNPG_OPERATOR_DIR/$CNPG_CLEANUP_CRONJOB_OVH"
758
- CNPG_CLEANUP_SCRIPT_BASH="cnpg-cleanup-script.sh"
759
- CNPG_CLEANUP_SCRIPT="$CNPG_OPERATOR_DIR/$CNPG_CLEANUP_SCRIPT_BASH"
760
- if [ ! -f "$CNPG_CLEANUP_SCRIPT" ];
761
- then
762
- cat<<CNPG_FETCH_CLEANUP_CRONJOB_YAML
763
- `color y "Missing $CNPG_CLEANUP_SCRIPT_BASH - updating local cron setup scripts"`
764
-
765
- CNPG_FETCH_CLEANUP_CRONJOB_YAML
766
- CNPG_OP_ROOT="$(build-tools --reporoot)/src/helm-charts/cnpg-operator"
767
- cp $CNPG_OP_ROOT/$CNPG_CLEANUP_CRONJOB_OVH $CNPG_CLEANUP_CRONJOB
768
- cp $CNPG_OP_ROOT/$CNPG_CLEANUP_SCRIPT_BASH $CNPG_CLEANUP_SCRIPT
769
- fi
770
-
771
- # copy / update the script in the bucket referenced in the cronjob
772
- printf "\ngsutil cp $CNPG_CLEANUP_SCRIPT gs://$GCP_PROJECT_ID-$BUCKET_SUFFIX\n"
773
- gsutil cp $CNPG_CLEANUP_SCRIPT gs://$GCP_PROJECT_ID-$BUCKET_SUFFIX
774
-
775
- local CNPG_NAMESPACE="cnpg-operands"
776
- local CNPG_CLEANUP_SA="cnpg-cleanup-sa"
777
-
778
- gcloud iam service-accounts create "$CNPG_CLEANUP_SA" \
779
- --project="$GCP_PROJECT_ID" \
780
- --description="Used for cronjob cleanup with Workload Identity" \
781
- --display-name="CNPG Cleanup SA" &> $DEVNULL
782
- warnOnError $? "the GCP SA $CNPG_CLEANUP_SA may already exist"
783
-
784
- gcloud projects add-iam-policy-binding "$GCP_PROJECT_ID" \
785
- --project="$GCP_PROJECT_ID" \
786
- --member="serviceAccount:$CNPG_CLEANUP_SA@$GCP_PROJECT_ID.iam.gserviceaccount.com" \
787
- --role="roles/storage.objectViewer"
788
-
789
- bindWorkloadIdentity "$CNPG_CLEANUP_SA" "$CNPG_NAMESPACE"
790
-
791
- CNPG_CLEANUP_CRONJOB_YAML="$CNPG_OPERATOR_DIR/$(basename $CNPG_CLEANUP_CRONJOB_OVH .ovh)"
792
- overwhelm -g # allow ovh -> yaml to occur
793
- cat<<CNPG_CLEANUP_CRONJOB_APPLY
794
- `color g "Creating cronjob =>"``color y " kubectl apply -f $CNPG_CLEANUP_CRONJOB_YAML"`
795
-
796
- CNPG_CLEANUP_CRONJOB_APPLY
797
- kubectl apply -f $CNPG_CLEANUP_CRONJOB_YAML
798
- }
799
-
800
- function ensureCnpgSecret() {
441
+ # uses service-man to synchronize a secret manager secret with its k8s counterpart
442
+ function synchronizeSecrets() {
801
443
  local mgrSecret=$1
802
444
  local k8sSecret=$2
803
445
 
@@ -814,105 +456,6 @@ BAD_SECRETS
814
456
  fi
815
457
  }
816
458
 
817
- function installVeleroEnvironment() {
818
- # Follows instructions => https://github.com/vmware-tanzu/velero-plugin-for-gcp
819
- showInstalling "Velero Backup Management"
820
- createNamespaceIfNeeded velero
821
-
822
- # Do we need to => gcloud auth application-default
823
- gcloud config set project $GCP_PROJECT_ID
824
-
825
- ## The major chart version will determine the bucket suffix
826
- [ -z "$VELERO_CHART_VERSION" ] && VELERO_CHART_VERSION="10"
827
-
828
- ## Create a bucket
829
- BUCKET="$GCP_PROJECT_ID-velero-$VELERO_CHART_VERSION"
830
- printf "\nCreating storage bucket `color g $BUCKET` in `color g $GCE_REGION`\n"
831
- gsutil mb -l $GCE_REGION gs://$BUCKET/ &> $DEVNULL
832
- warnOnError $? "Bucket failed to create or already exists - go check it\n"
833
- gsutil ubla set on gs://$BUCKET &> $DEVNULL
834
-
835
- ## Create a service account
836
- printf "\nCreating the service account\n"
837
- gcloud iam service-accounts create velero \
838
- --project $GCP_PROJECT_ID \
839
- --display-name "Velero service account" \
840
- --description "Velero service account" &> $DEVNULL
841
- if [ $? -eq 0 ];
842
- then
843
- # no error means a new SA was created - slight delay to let it update
844
- sleep 2
845
- else
846
- printf "$YELO_WARN Failed to create the service account - does it already exist?"
847
- fi
848
-
849
- SERVICE_ACCOUNT_EMAIL="velero@${GCP_PROJECT_ID}.iam.gserviceaccount.com"
850
-
851
- ## Attach roles
852
- ROLE_PERMISSIONS=(
853
- compute.disks.get
854
- compute.disks.create
855
- compute.disks.createSnapshot
856
- compute.projects.get
857
- compute.snapshots.get
858
- compute.snapshots.create
859
- compute.snapshots.useReadOnly
860
- compute.snapshots.delete
861
- compute.zones.get
862
- iam.serviceAccounts.actAs
863
- iam.serviceAccounts.signBlob
864
- storage.objects.create
865
- storage.objects.delete
866
- storage.objects.get
867
- storage.objects.list
868
- )
869
-
870
- printf "\nAssigning roles to the SA\n"
871
- gcloud iam roles create velero.server \
872
- --project $GCP_PROJECT_ID \
873
- --title "Velero Server" \
874
- --permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
875
- if [ $? -ne 0 ];
876
- then
877
- # assume error is that role exists so try updating instead
878
- printf "\nUpdating roles on the SA\n"
879
- gcloud iam roles update velero.server \
880
- --project $GCP_PROJECT_ID \
881
- --title "Velero Server" \
882
- --permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")" &> $DEVNULL
883
- fi
884
- warnOnError $? "Failed to add roles to velero.server - perhaps they already exist?"
885
-
886
- printf "\nBinding IAM policy to the SA\n"
887
- gcloud projects add-iam-policy-binding $GCP_PROJECT_ID \
888
- --project $GCP_PROJECT_ID \
889
- --member serviceAccount:$SERVICE_ACCOUNT_EMAIL \
890
- --condition 'None' \
891
- --role projects/$GCP_PROJECT_ID/roles/velero.server &> $DEVNULL
892
- warnOnError $? "gcloud problem binding IAM policy"
893
-
894
- printf "\nBinding workload identity IAM policy to the SA\n"
895
- gcloud iam service-accounts add-iam-policy-binding \
896
- --member "serviceAccount:$GCP_PROJECT_ID.svc.id.goog[velero/velero]" \
897
- --role roles/iam.workloadIdentityUser \
898
- $SERVICE_ACCOUNT_EMAIL
899
- warnOnError $? "gcloud workload identity binding may have failed"
900
-
901
- printf "\nCreate and annotate the k8s SA\n"
902
- kubectl create serviceaccount velero --namespace velero
903
- warnOnError $? "Failed to create k8s SA - perhaps it already exists?"
904
-
905
- kubectl annotate serviceaccount velero \
906
- --namespace velero \
907
- "iam.gke.io/gcp-service-account=$SERVICE_ACCOUNT_EMAIL"
908
- warnOnError $? "Failed to annotate k8s SA - things may fail"
909
-
910
- gsutil iam ch serviceAccount:$SERVICE_ACCOUNT_EMAIL:objectAdmin gs://$BUCKET
911
-
912
- ## Clean up from previous failed install
913
- kubectl delete volumesnapshotlocation.velero.io -n velero gcp &> $DEVNULL
914
- }
915
-
916
459
  function getServiceAndChartVersion() {
917
460
  SERVICE=
918
461
  CHARTVER=
@@ -1050,127 +593,35 @@ CATBACKUP
1050
593
  # If we're referencing a plugin then execute it and continue
1051
594
  ifPluggedIn $SERVICE && continue
1052
595
 
596
+ # If we can bootstrap a service on a new setup
597
+ ifCanBootstrap $SERVICE && continue
598
+
1053
599
  case "$SERVICE" in
1054
600
  "platform")
1055
601
  doPlatormPreInstallChecks
1056
602
  doInstall "${PLATFORM[@]}"
1057
603
  ;;
1058
604
 
1059
- "system-legacy")
1060
- doInstall "${SYSTEM_LEGACY[@]}"
1061
- ;;
1062
-
1063
605
  "system")
1064
606
  doInstall "${SYSTEM[@]}"
1065
607
  ;;
1066
608
 
1067
- "cert-manager")
1068
- installCertManagerSecret
1069
- bootstrapLocalSetup $SERVICE
1070
- ;;
1071
-
1072
- cnpg-db-*)
1073
- if [ ! -d $SERVICE ];
1074
- then
1075
- # this code only executes on the first deployment
1076
- initializeCnpgOperand $SERVICE
1077
- bootstrapLocalSetup $SERVICE
1078
- fi
1079
- ;;
1080
-
1081
- "cnpg-operator")
1082
- installCnpgOperatorEnvironment
1083
- bootstrapLocalSetup $SERVICE
1084
- installCnpgCleanupCronjob
1085
- ;;
1086
-
1087
- "cnpg-cronjob")
1088
- installCnpgCleanupCronjob
1089
- ;;
1090
-
1091
609
  "cronZombieKiller"|"zombie-killer")
1092
610
  installCronZombieKiller # eradicate the gke 1.20+ zombies
1093
611
  ;;
1094
612
 
1095
- "custom-metrics")
1096
- kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter.yaml
1097
- ;;
1098
-
1099
613
  default-configs*)
1100
614
  installDefaultConfigs
1101
615
  ;;
1102
616
 
1103
- "db-curator-dh")
1104
- # db-curator-dh is a variant of db-curator with diff controlled in values-local.yaml
1105
- HELMUP="helm upgrade --install $SERVICE leverege/db-curator --values $SERVICE/values.yaml $CHARTVER $HELM_WHAT"
1106
- doHelmup "$HELMUP"
1107
- ;;
1108
-
1109
- "elasticsearch") # simple 3 master v7.16 cluster
1110
- bootstrapLocalSetup $SERVICE
1111
- ;;
1112
-
1113
- "elasticsearch-cluster") # complex master/data/client ES cluster
1114
- bootstrapLocalSetup $SERVICE
1115
- ;;
1116
-
1117
- "elasticsearch8") # complex master/data/client ES v8 cluster
1118
- bootstrapLocalSetup $SERVICE
1119
- ;;
1120
-
1121
617
  "estafette"|"preemptible-killer")
1122
618
  installPreemptibleKiller # the gke preemptible node spreader outer
1123
619
  ;;
1124
620
 
1125
- "firebase")
1126
- installFirebaseDatabases
1127
- bootstrapLocalSetup firebase-rules
1128
- ;;
1129
-
1130
- "grafana")
1131
- bootstrapLocalSetup $SERVICE
1132
- ;;
1133
-
1134
- "kube-prometheus-stack")
1135
- bootstrapLocalSetup $SERVICE
1136
- ;;
1137
-
1138
- "monitoring")
1139
- installMonitoringEnvironment
1140
- monitoringHelp
1141
- ;;
1142
-
1143
- "monitoring-wtf")
1144
- monitoringHelp && exit 0
1145
- ;;
1146
-
1147
621
  "platform-buckets")
1148
622
  setupStackBuckets && exit 0
1149
623
  ;;
1150
624
 
1151
- "pgbouncer")
1152
- setupPgbouncerSecret
1153
- bootstrapLocalSetup $SERVICE
1154
- ;;
1155
-
1156
- "postgres")
1157
- bootstrapLocalSetup $SERVICE
1158
- ;;
1159
-
1160
- "prometheus")
1161
- installStackdriverExporterEnvironment
1162
- bootstrapLocalSetup $SERVICE
1163
- ;;
1164
-
1165
- "prom-operator")
1166
- installStackdriverExporterEnvironment prometheus
1167
- bootstrapLocalSetup $SERVICE
1168
- ;;
1169
-
1170
- "redis"|"valkey")
1171
- bootstrapLocalSetup $SERVICE
1172
- ;;
1173
-
1174
625
  "reflector")
1175
626
  showInstalling "Secrets/ConfigMap Namespace Reflector"
1176
627
  addHelmRepo emberstack https://emberstack.github.io/helm-charts
@@ -1185,41 +636,13 @@ CATBACKUP
1185
636
  removeHelmRepo stakater
1186
637
  ;;
1187
638
 
1188
- "stackdriver-exporter")
1189
- installStackdriverExporterEnvironment
1190
- bootstrapLocalSetup $SERVICE
1191
- ;;
1192
-
1193
- "timescale-db")
1194
- bootstrapLocalSetup $SERVICE
1195
- ;;
1196
-
1197
639
  transponder-*)
1198
640
  # transponders use the same chart but different deployment name
1199
641
  [ ! -d $SERVICE ] && bootstrapLocalSetup $SERVICE
1200
642
  HELMUP="helm upgrade --install $SERVICE leverege/transponder --values $SERVICE/values.yaml $CHARTVER $HELM_WHAT"
1201
643
  doHelmup "$HELMUP"
1202
644
  ;;
1203
-
1204
- "traefik")
1205
- # installTraefikEnvironment
1206
- bootstrapLocalSetup $SERVICE
1207
- ;;
1208
-
1209
- "traefik-canary")
1210
- # only valid if traefik is already installed
1211
- bootstrapLocalSetup $SERVICE
1212
- ;;
1213
-
1214
- "velero")
1215
- installVeleroEnvironment
1216
- bootstrapLocalSetup $SERVICE
1217
- ;;
1218
-
1219
- "vernemq")
1220
- bootstrapLocalSetup $SERVICE
1221
- ;;
1222
-
645
+
1223
646
  *)
1224
647
  # if the service dir is missing then check to see if it's a platform
1225
648
  # service and if it is then try to bootstrap from charts in build-tools
@@ -1296,7 +719,7 @@ NOTRUNNING
1296
719
  }
1297
720
 
1298
721
  # ---------- helmup MAIN ----------
1299
- GITTOP=`git rev-parse --show-toplevel` # `&& cd $GITTOP
722
+ GITTOP=`git rev-parse --show-toplevel`
1300
723
  K8S_UTILS="${GITTOP}/k8s-utils"
1301
724
 
1302
725
  overwhelm
@@ -1310,5 +733,3 @@ GCE_REGION=`overwhelm -k GCE_REGION`
1310
733
  doInstall $@
1311
734
 
1312
735
  displayBanner
1313
-
1314
- cd - &> $DEVNULL