@leverege/build-tools 2.0.4 → 2.0.6

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.
package/lib/server/helmup DELETED
@@ -1,349 +0,0 @@
1
- #!/bin/bash
2
- #
3
- # This script is used to ease the pain of transition testing to chart museum
4
- # for adding / updating deployments on a fluster.
5
- #
6
- # printf "\nRUNNING LOCALLY\n" && sleep 2
7
- PLATFORM=(
8
- api-server
9
- db-curator
10
- emailer
11
- imagine
12
- message-processor
13
- messenger
14
- reason
15
- scheduler
16
- transponder-bq
17
- transponder-fb
18
- transponder-postgres
19
- # transponder-sql
20
- )
21
-
22
- SYSTEM=(
23
- coredns
24
- disks
25
- elastic
26
- monitoring
27
- polaris
28
- redis
29
- velero
30
- # custom-metrics
31
- )
32
-
33
- # Simple ANSI color coded string generator.
34
- function color() {
35
- local color=
36
- case "$1" in
37
- 'g') color="92m" ;; # green
38
- 'c') color="96m" ;; # lt blue
39
- 'y') color="93m" ;; # yellow
40
- 'r') color="91m" ;; # red
41
- 'toast') color="1;3;7;91;103;5m" ;;
42
- esac
43
- printf "\e[$color$2\e[0m"
44
- }
45
- RED_ERROR=`color r '***ERROR:'`
46
- YELO_WARN="`color y '***WARNING:'`"
47
-
48
- function setOrUnset() {
49
- local setting=`color toast "NEEDS TO BE SET"`
50
- [ ! -z "$1" ] && setting=`color g $1`
51
- echo "$setting"
52
- }
53
-
54
-
55
- function createSSDYAML(){
56
- cat<<EOSSD > ${K8S_UTILS}/ssd-storageclass.yaml
57
- apiVersion: storage.k8s.io/v1
58
- kind: StorageClass
59
- metadata:
60
- name: ssd
61
- provisioner: kubernetes.io/gce-pd
62
- parameters:
63
- type: pd-ssd
64
- EOSSD
65
- }
66
-
67
- function checkSSDStorageClass(){
68
- kubectl get storageclass ssd
69
- if [[ $? -eq 1 ]]; then
70
- printf "\n*** SSD Storage Class not defined ***\n\n"
71
- if [ ! -f ${K8S_UTILS}/ssd-storageclass.yaml ]; then
72
- createSSDYAML
73
- fi
74
- kubectl apply -f ${K8S_UTILS}/ssd-storageclass.yaml
75
- fi
76
-
77
- printf "\n*** Attaching PVC to SSD Class ***\n\n"
78
- }
79
-
80
- function installVelero() {
81
- ## Set the project id by parsing current context
82
- currContext=`kubectl config current-context`
83
-
84
- IFS='_'
85
- read -ra ADDR <<< "$currContext"
86
-
87
- PROJECT_ID=${ADDR[1]} # project id is the second string split by _
88
-
89
- gcloud config set project $PROJECT_ID
90
-
91
- ## Create a bucket
92
- BUCKET="$PROJECT_ID-velero"
93
-
94
- gsutil mb gs://$BUCKET/
95
-
96
- ## Create a service account
97
- gcloud iam service-accounts create velero \
98
- --display-name "Velero service account"
99
-
100
- SERVICE_ACCOUNT_EMAIL=$(gcloud iam service-accounts list \
101
- --filter="displayName:Velero service account" \
102
- --format 'value(email)')
103
-
104
- ## Attach roles
105
- ROLE_PERMISSIONS=(
106
- compute.disks.get
107
- compute.disks.create
108
- compute.disks.createSnapshot
109
- compute.snapshots.get
110
- compute.snapshots.create
111
- compute.snapshots.useReadOnly
112
- compute.snapshots.delete
113
- compute.zones.get
114
- )
115
-
116
- gcloud iam roles create velero.server \
117
- --project $PROJECT_ID \
118
- --title "Velero Server" \
119
- --permissions "$(IFS=","; echo "${ROLE_PERMISSIONS[*]}")"
120
-
121
- gcloud projects add-iam-policy-binding $PROJECT_ID \
122
- --member serviceAccount:$SERVICE_ACCOUNT_EMAIL \
123
- --role projects/$PROJECT_ID/roles/velero.server
124
-
125
- gsutil iam ch serviceAccount:$SERVICE_ACCOUNT_EMAIL:objectAdmin gs://${BUCKET}
126
-
127
- ## Create keys
128
- gcloud iam service-accounts keys create credentials-velero \
129
- --iam-account $SERVICE_ACCOUNT_EMAIL
130
-
131
- ## Create velero namespace
132
- kubectl create ns velero
133
-
134
- ## Create kubernetes secret
135
- kubectl create secret generic velero-credentials --namespace velero --from-file cloud=credentials-velero
136
-
137
- ## Install velero
138
- helm upgrade --install velero stable/velero \
139
- --namespace velero \
140
- --set configuration.provider="gcp" \
141
- --set configuration.backupStorageLocation.name="gcp" \
142
- --set configuration.volumeSnapshotLocation.name="gcp" \
143
- --set configuration.backupStorageLocation.bucket="${BUCKET}" \
144
- --set credentials.existingSecret="velero-credentials" \
145
- --set "initContainers[0].name"="velero-plugin-for-gcp" \
146
- --set "initContainers[0].image"="velero/velero-plugin-for-gcp:v1.0.0" \
147
- --set "initContainers[0].volumeMounts[0].mountPath"="/target" \
148
- --set "initContainers[0].volumeMounts[0].name"="plugins" \
149
- --set schedules.timescale.schedule="0 3 * * *" \
150
- --set schedules.timescale.template.ttl="720h" \
151
- --set schedules.timescale.template.labelSelector.matchLabels.app="postgresql" \
152
- --set schedules.timescale.template.snapshotVolumes="true" \
153
-
154
- ## Instruct users to move velero keys
155
- printf "\n$YELO_WARN MOVE THE SERVICE ACCOUNT TO YOUR KEYS FOLDER"
156
- printf "\n$YELO_WARN NO REALLY...MOVE credentials-velero file NOW"
157
- }
158
-
159
- # ---------- helmup MAIN ----------
160
- command -v chartmuseum &> /dev/null
161
- if [ $? -ne 0 ];
162
- then
163
- cat<<NOMUSEUM
164
-
165
- $RED_ERROR Missing chartmuseum. Head over to the wiki site and follow the
166
- instructions in the section entitled Installing ChartMuseum down
167
- in the How-to articles -> Helm Charts via ChartMuseum.
168
-
169
- NOMUSEUM
170
- exit 1
171
- fi
172
-
173
- GITTOP=`git rev-parse --show-toplevel` && cd $GITTOP
174
- if [ -d "${GITTOP}/k8-utils" ];
175
- then
176
- cat<<BADK8
177
-
178
- $YELO_WARN The k8_utils directory should be renamed to k8s_utils
179
-
180
- This repository has the old k8_util directory name in place. Please rename
181
- it to the newer k8s_utils directory that `color c helmup` will be looking for.
182
-
183
- Run this => `color g "git mv k8-utils k8s-utils; git add k8*utils"`
184
-
185
- $YELO_WARN Don't forget to commit and push after the renaming.
186
-
187
- BADK8
188
- exit 1
189
- fi
190
-
191
- K8S_UTILS="${GITTOP}/k8s-utils"
192
- if [ ! -d "$K8S_UTILS" ];
193
- then
194
- cat<<EOK8S
195
-
196
- $RED_ERROR Missing the k8s utils dir => `color y $K8S_UTILS`
197
-
198
- This is a relatively new directory setup that should be copied over from one
199
- of the other configuration branches. The new-baseline branch should have this
200
- setup in place, so check there.
201
-
202
- EOK8S
203
-
204
- exit 1
205
- fi
206
-
207
- npm run ahoy
208
- [ $? -ne 0 ] && printf "\n\n***Aborting helmup...\n\n" && exit 1
209
-
210
- helm repo update &> /dev/null && helm search chartmuseum
211
-
212
- function doInstall() {
213
-
214
- for PARAM in "$@";
215
- do
216
- IFS="/" read SERVICE CHARTVER <<< "$PARAM"
217
- [ ! -z "$CHARTVER" ] && CHARTVER="--version $CHARTVER"
218
-
219
- case "$SERVICE" in
220
- "platform")
221
- doInstall "${PLATFORM[@]}"
222
- ;;
223
-
224
- "system")
225
- doInstall "${SYSTEM[@]}"
226
- ;;
227
-
228
- "coredns")
229
- helm install --name coredns --namespace=kube-system stable/coredns
230
- printf "\nGithub repo is here => https://github.com/helm/charts/tree/master/stable/coredns\n\n"
231
- ;;
232
-
233
- "descheduler")
234
- helm repo add akomljen-charts https://raw.githubusercontent.com/komljen/helm-charts/master/charts/
235
- helm upgrade --install descheduler akomljen-charts/descheduler --set schedule="*/15 * * * *",deschedulerPolicy.strategies.RemovePodsViolatingNodeAffinity.params.nodeAffinityType={preferredDuringSchedulingIgnoredDuringExecution}
236
- ;;
237
-
238
- "disks")
239
- checkSSDStorageClass
240
- helm upgrade --install disks ./disks
241
- ;;
242
-
243
- "elastic"|"elasticsearch")
244
- checkSSDStorageClass
245
- helm repo add elastic https://helm.elastic.co
246
- helm upgrade --install elasticsearch elastic/elasticsearch --set volumeClaimTemplate.storageClassName="ssd"
247
- ;;
248
-
249
- "monitoring")
250
- helm dep up ./monitoring && helm upgrade --install monitoring ./monitoring
251
- ;;
252
-
253
- "mysql")
254
- helm dep up ./mysql && helm upgrade --install mysql ./mysql
255
- printf "\n***Proxy 4306 with this => kubectl port-forward svc/mysql 4306:3306\n\n"
256
- printf "\n***Grab MYSQL Root Password => MYSQL_ROOT_PASSWORD=\$(kubectl get secret --namespace default mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)"
257
- printf "\n***Set MYSQL_HOST to 127.0.0.1 and MYSQL_PORT to 4306 and run => mysql -h \${MYSQL_HOST} -P\${MYSQL_PORT} -u root -p\${MYSQL_ROOT_PASSWORD} \n\n"
258
- printf "\n***Set Make sure to make api-server an admin \n\n"
259
- ;;
260
-
261
- "polaris")
262
- helm repo add reactiveops-stable https://charts.reactiveops.com/stable
263
- helm upgrade --install polaris reactiveops-stable/polaris --namespace polaris
264
- printf "\n***Proxy 8081 with this=> kubectl port-forward --namespace polaris svc/polaris-dashboard 8081:80\n\n"
265
- ;;
266
-
267
- "redis")
268
- # https://github.com/helm/charts/tree/master/stable/redis
269
- [ -z "$REDIS_HELM_CHART" ] && REDIS_HELM_CHART="v9.1.5"
270
- helm upgrade --install redis stable/redis \
271
- --version $REDIS_HELM_CHART \
272
- --set usePassword=false,cluster.slaveCount=3,networkPolicy.enabled=true,metrics.enabled=true
273
- printf "To start a specific version => `color c 'REDIS_HELM_CHART="v9.1.5" helmup redis'`\n\n"
274
- ;;
275
-
276
- "timescale-db")
277
- helm dep up ./timescale-db && helm upgrade --install timescale-db ./timescale-db
278
- ;;
279
-
280
- "ingress")
281
- helm upgrade --install ingress ./ingress
282
- ;;
283
-
284
- "custom-metrics")
285
- kubectl create -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter.yaml
286
- ;;
287
-
288
- "velero")
289
- installVelero # because it's a little more involved
290
- ;;
291
-
292
- *)
293
- if [ ! -d $SERVICE ] || [ ! -f $SERVICE/values-local.yaml ];
294
- then
295
- printf "\n$YELO_WARN Skipping unknown service => $SERVICE\n\n"
296
- continue
297
- fi
298
-
299
- if [ -f $SERVICE/.nohelm ];
300
- then
301
- printf "\n$YELO_WARN Helmup disabled for service => `color g $SERVICE`"
302
- printf "\n$YELO_WARN remove `color y $SERVICE/.nohelm` to enable\n"
303
- sleep 1 # sleep on it to make sure people see the deprecation
304
- continue
305
- fi
306
-
307
- printf "\n--------------------------------------------------------------\nCharting $SERVICE\n"
308
- # By default the museum chart name will be the same as the service, but
309
- # we have the flexibility to override the naming when the charts are
310
- # reference by the downstream repositories via the .helmup-charmuseum file.
311
- OVERRIDE="$SERVICE/.helmup-chartmuseum"
312
- MUSEUM=$SERVICE
313
- if [ -f $OVERRIDE ];
314
- then
315
- MUSEUM=$(<${OVERRIDE})
316
- printf "\n$YELO_WARN Local chartmuseum name override from ${SERVICE} to ${MUSEUM}\n"
317
- fi
318
- HELMUP="helm upgrade --install $SERVICE chartmuseum/$MUSEUM -f $SERVICE/values.yaml $CHARTVER"
319
- printf "Helming => `color g \"$HELMUP\"`\n" && $HELMUP
320
- SAVERR=$?
321
- if [ $SAVERR -ne 0 ];
322
- then
323
- cat<<NOTRUNNING
324
-
325
- $RED_ERROR helm exited with error status: $SAVERR
326
-
327
- $RED_ERROR The $SERVICE chart failed to upgrade or install. There may be an
328
- issue with the service's helm charts, or chartmuseum may not be
329
- up and running? If the latter, try firing it up with:
330
-
331
- chartmuseum \\
332
- --port="8080" \\
333
- --storage-google-bucket="leverege-helm-charts" \\
334
- --storage-google-prefix="" \\
335
- --storage="google" &> /dev/null &
336
-
337
- NOTRUNNING
338
- exit 1
339
- fi
340
- ;;
341
- esac
342
- done
343
-
344
- printf "\nRunning => helm ls\n\n"
345
- helm ls
346
- }
347
-
348
- doInstall $@
349
- cd - &> /dev/null
@@ -1,320 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const chalk = require( 'chalk' )
4
- const cliArgs = require( 'command-line-args' )
5
- const cliHelp = require( 'command-line-usage' )
6
- const exec = require( 'child_process' ).execSync
7
- const fs = require( 'fs' )
8
- const glob = require( 'glob' )
9
- const parse = require( 'parse-gitignore' )
10
- const ask = require( 'readline-sync' )
11
- const YAML = require( 'js-yaml' )
12
-
13
- const optionsDefinitions = [
14
- { name : 'context', alias : 'x', type : String, default : '' },
15
- { name : 'section', alias : 's', type : String, default : 'default' },
16
- { name : 'key', alias : 'k', type : String },
17
- { name : 'export', alias : 'e', type : Boolean, default : false },
18
- { name : 'continue', alias : 'c', type : Boolean, default : false },
19
- { name : 'checkctx', alias : 't', type : Boolean, default : false },
20
- { name : 'verbose', alias : 'v', type : Boolean, default : false },
21
- ]
22
- const args = cliArgs( optionsDefinitions )
23
-
24
- // The kubernetes context is equal to the git branch name.
25
- const gitBranch = require( 'git-branch' ).sync()
26
- const context = args.context || gitBranch
27
-
28
- if ( context == 'master' ) {
29
- console.log( '***ERROR: master context is forbidden; change to a different branch\n\n' )
30
- process.exit( 1 )
31
- }
32
-
33
- // Load the default values and then overlay with the project specific yaml
34
- // values. This supports the notion of this type of approach in the
35
- // overwhelm yaml settings:
36
- // default:
37
- // GCE_MACHINE : "n1-standard-2"
38
- //
39
- // my-project:
40
- // GCE_MACHINE : "n1-highcpu-8"
41
- //
42
- // fashion, but it is advised not to set a default region with this
43
- // approach in order to keep us cognizant of exactly where a cluster is
44
- // being formed.
45
- //
46
- const yaml = YAML.safeLoad( fs.readFileSync( 'overwhelm.yaml', 'utf-8' ) )
47
- const over = yaml.default
48
- let cfgs = yaml[context]
49
- let wtfs = cfgs
50
-
51
- // If we just need to check context return 0 if cfgs exists, else error.
52
- if ( args.checkctx ) { process.exit( !cfgs ) }
53
-
54
- if ( !cfgs ) {
55
- console.log( `***ERROR: Unknown context => [${context}]\n` )
56
- console.log( ' Known k8s contexts are:' )
57
- Object.keys( yaml ).forEach( ( key ) => {
58
- if ( key !== 'default' ) { console.log( ` ${key}` ) }
59
- } )
60
- console.log( `Add a section into overwhelm.yaml for ${context}\n\n` )
61
- process.exit( 1 )
62
- }
63
-
64
- // Check to see if we are deriving from another configuration.
65
- if ( cfgs['PROJECT_BASE'] ) {
66
- const baseName = cfgs['PROJECT_BASE']
67
- const tempCfgs = cfgs
68
- cfgs = yaml[baseName]
69
- Object.keys( tempCfgs ).forEach( ( key ) => { cfgs[key] = tempCfgs[key] } )
70
- console.log( "PROJECT_BASE still under evaluation" )
71
- console.log( "\n cfgs=", cfgs )
72
- process.exit( 1 ) //XXX HERE
73
- }
74
-
75
- Object.keys( cfgs ).forEach( ( key ) => { over[key] = cfgs[key] || over[key] } )
76
-
77
- // Expand any variables that reference other variable settings. A perfect
78
- // example of where this is useful is in the setting of a PROJECT_NAME and
79
- // a PROJECT_ID. Most of the time these values are identical, which is why
80
- // this setting exists in the default section:
81
- // default:
82
- // PROJECT_ID : ${PROJECT_NAME}
83
- //
84
- // However, in the case of projects like Siren Marine, this is the more
85
- // likely setup due to legacy naming schemes:
86
- // sire-marine:
87
- // PROJECT_NAME : siren-marine
88
- // PROJECT_ID : prod-rt-data
89
- //
90
- const varErrors = []
91
- Object.keys( over ).forEach( ( key ) => {
92
- if ( !over[key] ) return // no value to work with - skip it
93
-
94
- // Look for something in the form of "thing-${VAR1}-${VAR2}-${VARn}-stuff"
95
- const matches = over[key].match( /\$\{\w+\}/g )
96
- if ( !matches ) return
97
-
98
- matches.forEach( ( replaceThis ) => {
99
- // The matched variable names will be in the form of ${VARNAME} so drop
100
- // the ${} characters before using the VARNAME to map into the
101
- // overwhelm map containing the desired replacement value.
102
- const withThat = over[replaceThis.replace( /\W+/g, '' )]
103
- if ( !withThat ) {
104
- varErrors.push( `${key} : ${over[key]}` )
105
- return
106
- }
107
- // Store the replaced string back in the overwhelm value map.
108
- over[key] = over[key].replace( replaceThis, withThat )
109
- } )
110
- } )
111
-
112
- if ( varErrors.length > 0 ) {
113
- console.log( '***ERROR: unkown variable reference(s) in overwhelm.yaml:\n' )
114
- varErrors.forEach( ( error ) => {
115
- console.log( ` ${error}` )
116
- } )
117
- console.log('' )
118
- process.exit( 1 )
119
- }
120
-
121
- // Grab a list of the existing yaml templates.
122
- const yams = glob.sync( 'values-*.yaml' )
123
-
124
- // A function to apply the replacements to all of the matching yaml which
125
- // will error out if it runs into an unknown OVH<tag>.
126
- const doReplacements = ( yamls, replacements ) => {
127
- let replYaml = yamls
128
-
129
- Object.keys( replacements ).forEach( ( repl ) => {
130
- const replaceThis = new RegExp( `OVH:<${repl}>`, 'g' )
131
- const withThat = `${replacements[repl]}`
132
- replYaml = replYaml.replace( replaceThis, withThat )
133
- } )
134
-
135
- // Verify all replaceables have been handled, or error out.
136
- const missed = replYaml.match( /OVH:<(.*)>/g )
137
-
138
- if ( missed ) {
139
- console.log( '\n***ERROR: missing replacements in overwhelm.yaml for these tags:\n' )
140
- missed.forEach( ( miss ) => {
141
- console.log( ` TAG: ${miss.match( /OVH:<(.*)>/)[1]}` )
142
- } )
143
- console.log('' )
144
- process.exit( 1 )
145
- }
146
-
147
- return replYaml
148
- }
149
-
150
- // Collect all of the yaml from the yams, and always expect the default and
151
- // platform yamls to be in that list.
152
- const buildYaml = ( yamls, replacements ) => {
153
- // We always start with default but values-platform is no longer needed.
154
- const always = [ 'values-default.yaml' ]
155
- const values = [ ...always, ...yamls ]
156
- const loaded = []
157
- let allYamls = ''
158
-
159
- values.forEach( ( yaml ) => {
160
- if ( !fs.existsSync( yaml ) ) {
161
- console.log( `\n***ERROR: yaml file missing => ${yaml}\n` )
162
- process.exit( 1 )
163
- }
164
-
165
- if ( !loaded.includes( yaml ) ) {
166
- allYamls += `\n# AHOY => ${yaml}\n\n`
167
- allYamls += fs.readFileSync( yaml, { encoding : 'utf-8' } )
168
- loaded.push( yaml )
169
- }
170
- } )
171
-
172
- // Now apply all of the replacements from the overwhelm file.
173
- return doReplacements( allYamls, replacements )
174
- }
175
-
176
- // Call buildYaml to replace the OVH strings in the yaml files.
177
- const values = buildYaml( yams, over )
178
-
179
- // Check to see if someone is requesting a value from the yaml.
180
- if ( args.key ) {
181
- const section = args.section || 'default'
182
- const keys = yaml[section]
183
- if ( args.verbose ) {
184
- console.log( 'replacements' )
185
- console.log( keys )
186
- }
187
- if ( args.export ) {
188
- console.log( `export ${args.key}=${keys[args.key]}` )
189
- }
190
- else {
191
- console.log( keys[args.key] )
192
- }
193
- if ( ! args.continue ) process.exit()
194
- }
195
-
196
- // Find all of the potential target dirs. Utilize .gitignore to ignore files
197
- const opt = {
198
- ignore : parse( fs.readFileSync( '.gitignore' ) )
199
- }
200
-
201
- const ahoy = glob.sync( '*/', opt )
202
-
203
- // Keel supports a "never" policy which will cause it to skip over a release
204
- // if it is properly set. Adding a .nokeel file to a release directoy will
205
- // cause the creation of the file if it does not already exist.
206
- const generateKeelNeverPolicy = ( fileName ) => {
207
- if ( fs.existsSync( fileName ) ) return
208
- const neverPolicy = `
209
- keel:
210
- # keel policy (all/major/minor/patch/force)
211
- policy: "never"
212
- # approvals
213
- # approvals: 1
214
- # approvalDeadline: 24
215
- # # images to track and update
216
- # images:
217
- # - repository: never.IMAGE # [1]
218
- # tag: never.VERSION # [2]
219
- `
220
- fs.writeFileSync( fileName, neverPolicy )
221
- }
222
-
223
- // Generate the values.yaml files in directories not marked with .nohelm.
224
- ahoy.forEach( ( dir ) => {
225
- if ( !fs.existsSync( `${dir}/.nohelm` ) ) {
226
- console.log( `Generating values in ${dir}` )
227
-
228
- let valuesOut = [] // An accumulator for all of the output values.
229
-
230
- // Add support for localized values for things like keel (or whatever)
231
- const valuesLocal = `${dir}values-local.yaml`
232
-
233
- if ( fs.existsSync( `${dir}.nokeel` ) ) {
234
- generateKeelNeverPolicy( valuesLocal )
235
- }
236
-
237
- if ( fs.existsSync( valuesLocal ) ) {
238
- console.log( ` Local values in ${valuesLocal}` )
239
- valuesOut += `\n# AHOY => values-local.yaml\n\n`
240
- valuesOut += fs.readFileSync( valuesLocal, { encoding : 'utf-8' } )
241
- }
242
- valuesOut += `\n${values}`
243
- valuesOut = doReplacements( valuesOut, over )
244
-
245
- fs.writeFileSync( `${dir}/values.yaml`, valuesOut )
246
- }
247
- } )
248
-
249
- // Set the GCP context for safety!
250
- const clusterName = over['CLUSTER_NAME']
251
- const projectId = over['PROJECT_ID']
252
- const zone = over['GCE_REGION'] + ( over['GCE_ZONE'] ? `-${over['GCE_ZONE']}` : '' )
253
-
254
- if ( !clusterName ) {
255
- console.log( chalk.yellow(
256
- `
257
-
258
- The overwhelm.yaml file in this branch is missing a CLUSTER_NAME setting,
259
- which was added to support cluster names that do not match the project
260
- name. Since the mismatch is rare, you can probably get by with simply
261
- adding this line following PROJECT_NAME in the default section of
262
- overwhelm.yaml:
263
-
264
- ${chalk.bold.green( `CLUSTER_NAME : "\${PROJECT_NAME}"` )}
265
-
266
- However, if the CLUSTER_NAME is not the same as the PROJECT_NAME then go
267
- ahead and add the CLUSTER_NAME setting to the ${chalk.bold.green(projectId)} section of the
268
- overwhelm.yaml file.
269
-
270
- ` ) )
271
- process.exit( 1 )
272
- }
273
-
274
- let kubeout = '_no_current_context_'
275
- try {
276
- // if current is not set exec will throw
277
- kubeout = exec( 'kubectl config current-context' )
278
- } catch (err) { }
279
-
280
- const currentCtx = kubeout.toString().trim()
281
- const desiredCtx = `gke_${projectId}_${zone}_${clusterName}`
282
- const matchedCtx = ( currentCtx === desiredCtx )
283
- const cmd = `gcloud container clusters get-credentials ${clusterName} --zone ${zone} --project ${projectId}`
284
-
285
- if ( matchedCtx ) {
286
- console.log( `
287
-
288
- Current context ${chalk.bold.green(currentCtx)} matches the desired
289
- context. Do you want to update credentials anyway?
290
-
291
- ` )
292
- }
293
- else {
294
- console.log( `
295
-
296
- You are about to change your GCP context to:
297
- CLUSTER_NAME => ${chalk.bold.green(clusterName)}
298
- PROJECT_ID => ${chalk.bold.green(projectId)}
299
- GCE_REGION => ${chalk.bold.green(zone)}
300
-
301
- ` )
302
- }
303
- const ans = ask.question( `Enter "${chalk.bold.green( 'yes' )}" if you wish to proceed => ` )
304
- if ( ans !== 'yes' ) {
305
- if ( matchedCtx ) {
306
- console.log( chalk.bold.yellow( `\n\nSkipping a refetch of your GCP context and credentials\n\n` ) )
307
- process.exit( 0 )
308
- }
309
-
310
- console.log( chalk.bold.red( `\n\nYour GCP context and credentials do NOT match - this could be bad!\n\n` ) )
311
- process.exit( 1 )
312
- }
313
-
314
- console.log( `\n\nExecuting: ${cmd}\n\n` )
315
- exec( `${cmd}`, ( error, out ) => {
316
- if ( error ) {
317
- console.log( `\n\n***ERROR ${error}\n\n` )
318
- process.exit( 1 )
319
- }
320
- } )