@leverege/build-tools 2.14.1 → 2.14.2

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leverege/build-tools",
3
- "version": "2.14.1",
3
+ "version": "2.14.2",
4
4
  "description": "A collection of build / support tools for Leverege developers",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -61,7 +61,7 @@
61
61
  "inquirer": "^8.2.4",
62
62
  "js-yaml": "^4.1.0",
63
63
  "ncp": "^2.0.0",
64
- "npm-check-updates": "^13.1.1",
64
+ "npm-check-updates": "^13.1.2",
65
65
  "npm-registry-fetch": "^11.0.0",
66
66
  "open": "^8.4.0",
67
67
  "ora": "^5.4.1",
package/src/bash-funcs CHANGED
@@ -95,6 +95,8 @@ INSTALLING
95
95
  }
96
96
 
97
97
  function addHelmRepo() {
98
+ [ ! -z "$HELM_REPO_SKIP" ] && return
99
+
98
100
  local chart=$1
99
101
  local url=$2
100
102
 
@@ -107,5 +109,6 @@ REPOADD
107
109
  }
108
110
 
109
111
  function removeHelmRepo(){
112
+ [ ! -z "$HELM_REPO_SKIP" ] && return
110
113
  helm repo remove $1 &>/dev/null
111
114
  }
package/src/helmup CHANGED
@@ -8,7 +8,7 @@
8
8
  # Load the standard helper functions
9
9
  . `build-tools --bashfun`
10
10
 
11
- HELMUP_ARGS=("$*")
11
+ SHELMUP_ARGS=("$*")
12
12
 
13
13
  # removed geotile-server from standard platform 3/20/22 - low usage
14
14
  PLATFORM=(
@@ -59,6 +59,52 @@ CATNAMI
59
59
  addHelmRepo bitnami $BITNAMI_URL
60
60
  }
61
61
 
62
+ function getProjectIdFromK8sContext() {
63
+ local currContext=`kubectl config current-context`
64
+
65
+ IFS='_'
66
+ read -ra ADDR <<< "$currContext"
67
+
68
+ echo ${ADDR[1]} # project id is the second string split by _
69
+ }
70
+
71
+ function bindWorkloadIdentity(){
72
+ PROJECT_ID=$(getProjectIdFromK8sContext)
73
+ SVC_ACCT=$1
74
+ NAMESPACE=$2
75
+ SVC_ACCT_EMAIL="${SVC_ACCT}@${PROJECT_ID}.iam.gserviceaccount.com"
76
+
77
+ cat<<WORKLOAD_ID
78
+ Binding workload identity IAM policy
79
+ Service Account : `color g $SVC_ACCT`
80
+ Project : `color g $PROJECT_ID`
81
+ Namespace : `color g $NAMESPACE`
82
+ Service Email : `color g $SVC_ACCT_EMAIL`
83
+
84
+ WORKLOAD_ID
85
+
86
+ gcloud iam service-accounts add-iam-policy-binding \
87
+ --project $PROJECT_ID \
88
+ --member "serviceAccount:$PROJECT_ID.svc.id.goog[${NAMESPACE}/${SVC_ACCT}]" \
89
+ --role roles/iam.workloadIdentityUser $SVC_ACCT_EMAIL
90
+ warnOnError $? "gcloud workload identity binding may have failed"
91
+
92
+ # Verify the Kubernetes SA and create it if necessary
93
+ printf "\nChecking for the $NAMESPACE/#SVC_ACCT k8s SA\n"
94
+ kubectl get sa -n $NAMESPACE $SVC_ACCT
95
+ if [[ $? -eq 1 ]];
96
+ then
97
+ printf "Creating the k8s SA $NAMESPACE/@$SVC_ACCT\n"
98
+ kubectl create sa -n $NAMESPACE $SVC_ACCT
99
+ fi
100
+
101
+ printf "\nAnnotating the k8s SA $NAMESPACE/@$SVC_ACCT\n"
102
+ kubectl annotate serviceaccount $SVC_ACCT \
103
+ --namespace $NAMESPACE --overwrite \
104
+ "iam.gke.io/gcp-service-account=$SVC_ACCT_EMAIL"
105
+ warnOnError $? "Failed to annotate service account $NAMESPACE/$SVC_ACCT - things may fail"
106
+ }
107
+
62
108
  function checkTimescalePassword(){
63
109
  kubectl get secret postgresql-password
64
110
  if [[ $? -eq 1 ]]; then
@@ -90,6 +136,18 @@ function createNamespaceIfNeeded(){
90
136
  fi
91
137
  }
92
138
 
139
+ function installPrometheus() {
140
+ # Add the community helm repositories
141
+ addHelmRepo prometheus-community https://prometheus-community.github.io/helm-charts
142
+
143
+ helm upgrade --install prometheus prometheus-community/prometheus \
144
+ --namespace monitoring \
145
+ --values prometheus/values.yaml \
146
+ --version 13
147
+
148
+ # removeHelmRepo prometheus-community
149
+ }
150
+
93
151
  function installMonitoringCharts(){
94
152
  showInstalling "Grafana Monitoring"
95
153
  createNamespaceIfNeeded monitoring
@@ -168,10 +226,7 @@ SA_EXISTS
168
226
  fi
169
227
 
170
228
  ## Install Prometheus
171
- helm upgrade --install prometheus prometheus-community/prometheus \
172
- --namespace monitoring \
173
- --values prometheus/values.yaml \
174
- --version 13
229
+ installPrometheus
175
230
 
176
231
  ## Installing ES exporter
177
232
  helm upgrade --install elasticsearch-exporter prometheus-community/prometheus-elasticsearch-exporter \
@@ -253,45 +308,43 @@ function getManagedSecret() {
253
308
  echo $SECRET
254
309
  }
255
310
 
256
- function getProjectIdFromK8sContext() {
257
- local currContext=`kubectl config current-context`
258
-
259
- IFS='_'
260
- read -ra ADDR <<< "$currContext"
261
-
262
- echo ${ADDR[1]} # project id is the second string split by _
263
- }
264
-
265
311
  # https://github.com/estafette/estafette-gke-preemptible-killer
266
312
  function installPreemptibleKiller() {
267
313
  showInstalling "Preemptible Node Killing Adjusticator"
314
+ NAMESPACE="estafette"
268
315
  PROJECT_ID="$(getProjectIdFromK8sContext)"
269
- createNamespaceIfNeeded estafette
316
+ SVC_ACCT="preemptible-killer"
317
+
318
+ createNamespaceIfNeeded $NAMESPACE
270
319
  addHelmRepo estafette https://helm.estafette.io
271
320
 
272
- gcloud iam service-accounts create preemptible-killer \
273
- --project=$PROJECT_ID \
274
- --display-name preemptible-killer
321
+ printf "\nCreating the gcloud $SVC_ACCT service account (SA)\n"
322
+ gcloud iam service-accounts create $SVC_ACCT \
323
+ --project $PROJECT_ID \
324
+ --display-name "Estafette Node Killer"
325
+ warnOnError $? "SA creation may have failed or it already exists"
275
326
 
276
- gcloud iam roles create preemptible_killer \
327
+ printf "\nCreate the $SVC_ACCT IAM role\n"
328
+ gcloud iam roles create preemptibleKiller \
277
329
  --project $PROJECT_ID \
278
- --title preemptible-killer \
330
+ --title "Estafette Node Killer" \
279
331
  --description "Delete compute instances" \
280
332
  --permissions compute.instances.delete
333
+ warnOnError $? "Role creation may have failed or it already exists"
281
334
 
282
- local service_account_email=$(gcloud iam --project=$PROJECT_ID service-accounts list --filter preemptible-killer --format 'value([email])')
335
+ local service_account_email=$(gcloud iam --project=$PROJECT_ID service-accounts list --filter $SVC_ACCT --format 'value([email])')
336
+ printf "\nBinding the IAM role to the $SVC_ACCT SA\n"
283
337
  gcloud projects add-iam-policy-binding $PROJECT_ID \
284
338
  --member=serviceAccount:${service_account_email} \
285
- --role=projects/${PROJECT_ID}/roles/preemptible_killer &>/dev/null
339
+ --role=projects/${PROJECT_ID}/roles/preemptibleKiller &> /dev/null
340
+ warnOnError $? "Binding may have failed or it already exists"
286
341
 
287
- gcloud iam service-accounts keys create \
288
- --project=$PROJECT_ID \
289
- --iam-account $service_account_email \
290
- google_service_account.json &>/dev/null
342
+ bindWorkloadIdentity $SVC_ACCT $NAMESPACE
291
343
 
292
344
  helm upgrade --install estafette-gke-preemptible-killer \
293
345
  estafette/estafette-gke-preemptible-killer \
294
- --namespace estafette \
346
+ --namespace ${NAMESPACE} \
347
+ --set secret.workloadIdentityServiceAccount="$SVC_ACCT@$PROJECT_ID.iam.gserviceaccount.com" \
295
348
  --set extraEnv.BLACKLIST_HOURS="10:00-02:00" # No killing from 5AM-9PM EST
296
349
  # --set extraEnv.WHITELIST_HOURS="12:30-13:30"
297
350
  [ -f "google_service_account.json" ] && rm google_service_account.json
@@ -579,7 +632,7 @@ function installVelero() {
579
632
 
580
633
  kubectl annotate serviceaccount velero \
581
634
  --namespace velero \
582
- iam.gke.io/gcp-service-account=$SERVICE_ACCOUNT_EMAIL
635
+ "iam.gke.io/gcp-service-account=$SERVICE_ACCOUNT_EMAIL"
583
636
  warnOnError $? "Failed to annotate k8s SA - things may fail"
584
637
 
585
638
  gsutil iam ch serviceAccount:$SERVICE_ACCOUNT_EMAIL:objectAdmin gs://$BUCKET
@@ -770,6 +823,10 @@ function doInstall() {
770
823
  removeHelmRepo bitnami
771
824
  ;;
772
825
 
826
+ "prometheus")
827
+ installPrometheus
828
+ ;;
829
+
773
830
  "redis")
774
831
  showInstalling "Redis Network Cache"
775
832
  addBitnamiRepo