This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
setup_create_gcp.go
681 lines (597 loc) · 20.3 KB
/
setup_create_gcp.go
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/*
* Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package setup
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
"cloud.google.com/go/storage"
"github.com/manifoldco/promptui"
"golang.org/x/oauth2/google"
"google.golang.org/api/container/v1"
"google.golang.org/api/file/v1"
sqladmin "google.golang.org/api/sqladmin/v1beta4"
"github.com/cellery-io/sdk/components/cli/pkg/constants"
"github.com/cellery-io/sdk/components/cli/pkg/kubernetes"
"github.com/cellery-io/sdk/components/cli/pkg/runtime"
"github.com/cellery-io/sdk/components/cli/pkg/runtime/gcp"
"github.com/cellery-io/sdk/components/cli/pkg/util"
)
var projectName string
var accountName string
var region string
var zone string
var uniqueNumber string
func init() {
rand.Seed(time.Now().UTC().UnixNano())
uniqueNumber = strconv.Itoa(rand.Intn(1000))
}
func RunSetupCreateGcp(isCompleteSetup bool) {
projectName, accountName, region, zone = getGcpData()
if region == "" {
util.ExitWithErrorMessage("Error creating cluster", fmt.Errorf("region not found in gcloud "+
"config list. Please run `gcloud init` to set the region"))
}
if zone == "" {
util.ExitWithErrorMessage("Error creating cluster", fmt.Errorf("zone not found in gcloud "+
"config list. Please run `gcloud init` to set the zone"))
}
if isCompleteSetup {
createCompleteGcpRuntime()
} else {
createMinimalGcpRuntime()
}
runtime.WaitFor(true, false)
}
func createGcp() error {
var isCompleteSelected = false
cellTemplate := &promptui.SelectTemplates{
Label: "{{ . }}",
Active: "\U000027A4 {{ .| bold }}",
Inactive: " {{ . | faint }}",
Help: util.Faint("[Use arrow keys]"),
}
cellPrompt := promptui.Select{
Label: util.YellowBold("?") + " Select the type of runtime",
Items: []string{constants.BASIC, constants.COMPLETE, constants.CellerySetupBack},
Templates: cellTemplate,
}
_, value, err := cellPrompt.Run()
if err != nil {
return fmt.Errorf("failed to select an option: %v", err)
}
if value == constants.CellerySetupBack {
createEnvironment()
return nil
}
if value == constants.COMPLETE {
isCompleteSelected = true
}
RunSetupCreateGcp(isCompleteSelected)
return nil
}
func createMinimalGcpRuntime() {
util.CopyK8sArtifacts(util.UserHomeCelleryDir())
gcpBucketName := configureGCPCredentials()
_ = configureGCPCredentials()
ctx := context.Background()
// Create a GKE client
gcpSpinner := util.StartNewSpinner("Creating GKE client")
createKubernetesClusterOnGcp(ctx, gcpSpinner)
sqlService, serviceAccountEmailAddress := configureMysqlOnGcp(ctx, gcpSpinner)
configureBucketOnGcp(ctx, gcpSpinner, gcpBucketName, serviceAccountEmailAddress, sqlService)
configureNfsOnGcp(gcpSpinner, ctx)
// Deploy cellery runtime
gcpSpinner.SetNewAction("Deploying Cellery runtime")
deployMinimalCelleryRuntime()
util.RemoveDir(filepath.Join(util.UserHomeCelleryDir(), constants.K8sArtifacts))
gcpSpinner.Stop(true)
}
func createCompleteGcpRuntime() error {
util.CopyK8sArtifacts(util.UserHomeCelleryDir())
gcpBucketName := configureGCPCredentials()
ctx := context.Background()
// Create a GKE client
gcpSpinner := util.StartNewSpinner("Creating GKE client")
createKubernetesClusterOnGcp(ctx, gcpSpinner)
sqlService, serviceAccountEmailAddress := configureMysqlOnGcp(ctx, gcpSpinner)
configureBucketOnGcp(ctx, gcpSpinner, gcpBucketName, serviceAccountEmailAddress, sqlService)
configureNfsOnGcp(gcpSpinner, ctx)
// Deploy cellery runtime
gcpSpinner.SetNewAction("Deploying Cellery runtime")
deployCompleteCelleryRuntime()
util.RemoveDir(filepath.Join(util.UserHomeCelleryDir(), constants.K8sArtifacts))
gcpSpinner.Stop(true)
return nil
}
func configureNfsOnGcp(gcpSpinner *util.Spinner, ctx context.Context) {
// Create NFS server
gcpSpinner.SetNewAction("Creating NFS server")
hcNfs, err := google.DefaultClient(ctx, file.CloudPlatformScope)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error getting authenticated client: %v", err)
}
nfsService, err := file.New(hcNfs)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating nfs service: %v", err)
}
if err := createNfsServer(nfsService); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating NFS server: %v", err)
}
nfsIpAddress, errIp := getNfsServerIp(nfsService)
fmt.Printf("Nfs Ip address : %v", nfsIpAddress)
if errIp != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error getting NFS server IP address: %v", errIp)
}
if err := gcp.UpdateNfsServerDetails(nfsIpAddress, "/data"); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error replacing in file artifacts-persistent-volume.yaml: %v", err)
}
}
func configureBucketOnGcp(ctx context.Context, gcpSpinner *util.Spinner, gcpBucketName string,
serviceAccountEmailAddress string, sqlService *sqladmin.Service) {
client, err := storage.NewClient(ctx)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating storage client: %v", err)
}
// Create bucket
gcpSpinner.SetNewAction("Creating gcp bucket")
if err := createGcpStorage(client, projectName, gcpBucketName); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating storage client: %v", err)
}
// Upload init file to S3 bucket
gcpSpinner.SetNewAction("Uploading init.sql file to GCP bucket")
if err := uploadSqlFile(client, gcpBucketName, constants.InitSql); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error Uploading Sql file: %v", err)
}
// Update bucket permission
gcpSpinner.SetNewAction("Updating bucket permission")
if err := updateBucketPermission(gcpBucketName, serviceAccountEmailAddress); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error Updating bucket permission: %v", err)
}
// Import sql script
gcpSpinner.SetNewAction("Importing sql script")
var uri = "gs://" + gcpBucketName + "/init.sql"
if err := importSqlScript(sqlService, projectName, constants.GcpDbInstanceName+uniqueNumber, uri); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error Updating bucket permission: %v", err)
}
time.Sleep(30 * time.Second)
// Update sql instance
gcpSpinner.SetNewAction("Updating sql instance")
if err := updateInstance(sqlService, projectName, constants.GcpDbInstanceName+uniqueNumber); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error Updating sql instance: %v", err)
}
}
func configureMysqlOnGcp(ctx context.Context, gcpSpinner *util.Spinner) (*sqladmin.Service, string) {
hcSql, err := google.DefaultClient(ctx, sqladmin.CloudPlatformScope)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating client: %v", err)
}
sqlService, err := sqladmin.New(hcSql)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating sql service: %v", err)
}
//Create sql instance
gcpSpinner.SetNewAction("Creating sql instance")
_, err = createSqlInstance(sqlService, projectName, region, region, constants.GcpDbInstanceName+uniqueNumber)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error creating sql instance: %v", err)
}
sqlIpAddress, serviceAccountEmailAddress := getSqlServieAccount(ctx, sqlService, projectName,
constants.GcpDbInstanceName+uniqueNumber)
fmt.Printf("Sql Ip address : %v", sqlIpAddress)
if err := gcp.UpdateMysqlCredentials(constants.GcpSqlUserName, constants.GcpSqlPassword+uniqueNumber,
sqlIpAddress); err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Error updating file: %v", err)
}
return sqlService, serviceAccountEmailAddress
}
func createKubernetesClusterOnGcp(ctx context.Context, gcpSpinner *util.Spinner) {
gkeClient, err := google.DefaultClient(ctx, container.CloudPlatformScope)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Could not get authenticated client: %v", err)
}
gcpService, err := container.New(gkeClient)
if err != nil {
gcpSpinner.Stop(false)
fmt.Printf("Could not initialize gke client: %v", err)
}
// Create GCP cluster
gcpSpinner.SetNewAction("Creating GCP cluster " + constants.GcpClusterName + uniqueNumber)
errCreate := createGcpCluster(gcpService, constants.GcpClusterName+uniqueNumber)
if errCreate != nil {
gcpSpinner.Stop(false)
fmt.Printf("Could not create cluster: %v", errCreate)
}
// Update kube config file
gcpSpinner.SetNewAction("Updating kube config cluster")
updateKubeConfig()
}
func configureGCPCredentials() string {
// Get the GCP cluster data
projectName, accountName, region, zone = getGcpData()
var gcpBucketName = constants.GcpBucketName + uniqueNumber
jsonAuthFile := util.FindInDirectory(filepath.Join(util.UserHomeDir(), constants.CelleryHome, constants.GCP),
".json")
if len(jsonAuthFile) > 0 {
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", jsonAuthFile[0])
} else {
util.ExitWithErrorMessage("Failed to create gcp cluster", fmt.Errorf(
"Could not find authentication json file in : %s. Please copy GCP service account credentials"+
" json file into this directory.\n", filepath.Join(util.UserHomeDir(),
constants.CelleryHome, constants.GCP)))
}
return gcpBucketName
}
func createGcpCluster(gcpService *container.Service, clusterName string) error {
gcpGKENode := &container.NodeConfig{
ImageType: constants.GcpClusterImageType,
MachineType: constants.GcpClusterMachineType,
DiskSizeGb: constants.GcpClusterDiskSizeGb,
}
gcpCluster := &container.Cluster{
Name: clusterName,
Description: "k8s cluster",
InitialClusterVersion: "1.14",
InitialNodeCount: 1,
Location: zone,
NodeConfig: gcpGKENode,
ResourceLabels: getCreatedByLabel(),
}
createClusterRequest := &container.CreateClusterRequest{
ProjectId: projectName,
Zone: zone,
Cluster: gcpCluster,
}
k8sCluster, err := gcpService.Projects.Zones.Clusters.Create(projectName, zone, createClusterRequest).Do()
// Loop until cluster status becomes RUNNING
for i := 0; i < 30; i++ {
resp, err := gcpService.Projects.Zones.Clusters.Get(projectName, zone, constants.GcpClusterName+uniqueNumber).Do()
if err != nil {
time.Sleep(30 * time.Second)
} else {
if resp.Status == "RUNNING" {
fmt.Printf("Cluster: %v created", k8sCluster.Name)
return nil
}
time.Sleep(15 * time.Second)
}
}
return fmt.Errorf("failed to create clusters: %v", err)
}
func createSqlInstance(service *sqladmin.Service, projectId string, region string, zone string,
instanceName string) ([]*sqladmin.DatabaseInstance, error) {
settings := &sqladmin.Settings{
DataDiskSizeGb: constants.GcpSqlDiskSizeGb,
Tier: constants.GcpSqlTier,
UserLabels: getCreatedByLabel(),
}
dbInstance := &sqladmin.DatabaseInstance{
Name: instanceName,
Project: projectId,
Region: region,
GceZone: zone,
BackendType: "SECOND_GEN",
DatabaseVersion: "MYSQL_5_7",
Settings: settings,
}
if _, err := service.Instances.Insert(projectId, dbInstance).Do(); err != nil {
fmt.Printf("Error in sql instance creation")
}
return nil, nil
}
func createGcpStorage(client *storage.Client, projectID, bucketName string) error {
ctx := context.Background()
attributes := &storage.BucketAttrs{
Labels: getCreatedByLabel(),
}
if err := client.Bucket(bucketName).Create(ctx, projectID, attributes); err != nil {
return err
}
return nil
}
func uploadSqlFile(client *storage.Client, bucket, object string) error {
ctx := context.Background()
if err := gcp.UpdateInitSql(constants.GcpSqlUserName, constants.GcpSqlPassword+uniqueNumber); err != nil {
return err
}
f, err := os.Open(filepath.Join(util.UserHomeDir(), constants.CelleryHome, constants.K8sArtifacts,
constants.MySql, constants.DbScripts, constants.InitSql))
if err != nil {
return err
}
defer f.Close()
wc := client.Bucket(bucket).Object(object).NewWriter(ctx)
if _, err = io.Copy(wc, f); err != nil {
return err
}
if err := wc.Close(); err != nil {
return err
}
return nil
}
func updateKubeConfig() {
cmd := exec.Command("bash", "-c", "gcloud container clusters get-credentials "+constants.GcpClusterName+uniqueNumber+" --zone "+zone+" --project "+projectName)
stderr, err := cmd.StderrPipe()
if err != nil {
log.Fatal(err)
}
if err = cmd.Start(); err != nil {
log.Fatal(err)
}
defer cmd.Wait()
go io.Copy(os.Stdout, stderr)
}
func createNfsServer(nfsService *file.Service) error {
fileShare := &file.FileShareConfig{
Name: constants.GcpNfsConfigName,
CapacityGb: constants.GcpNfsConfigCapacity,
}
fileShares := append([]*file.FileShareConfig{}, fileShare)
network := &file.NetworkConfig{
Network: "default",
}
networks := append([]*file.NetworkConfig{}, network)
nfsInstance := &file.Instance{
FileShares: fileShares,
Networks: networks,
Tier: "STANDARD",
Labels: getCreatedByLabel(),
}
if _, err := nfsService.Projects.Locations.Instances.Create("projects/"+projectName+"/locations/"+zone,
nfsInstance).InstanceId(constants.GcpNfsServerInstance + uniqueNumber).Do(); err != nil {
return err
}
return nil
}
func getNfsServerIp(nfsService *file.Service) (string, error) {
serverIp := ""
for true {
inst, err := nfsService.Projects.Locations.Instances.Get("projects/" + projectName + "/locations/" + zone +
"/instances/" + constants.GcpNfsServerInstance + uniqueNumber).Do()
if err != nil {
return serverIp, err
} else {
if inst.State == "READY" {
serverIp = inst.Networks[0].IpAddresses[0]
return serverIp, nil
} else {
time.Sleep(10 * time.Second)
}
}
}
return serverIp, nil
}
func getSqlServieAccount(ctx context.Context, gcpService *sqladmin.Service, projectId string, instanceName string) (string, string) {
for i := 0; i < 30; i++ {
resp, err := gcpService.Instances.Get(projectId, instanceName).Context(ctx).Do()
if err != nil {
time.Sleep(60 * time.Second)
} else {
if resp.State == "RUNNABLE" {
return resp.IpAddresses[0].IpAddress, resp.ServiceAccountEmailAddress
}
time.Sleep(15 * time.Second)
}
}
return "", ""
}
func updateBucketPermission(bucketName string, svcAccount string) (err error) {
scCtx := context.Background()
c, err := storage.NewClient(scCtx)
if err != nil {
return err
}
ctx := context.Background()
bucket := c.Bucket(bucketName)
policy, err := bucket.IAM().Policy(ctx)
if err != nil {
return err
}
policy.Add(strings.Join([]string{"serviceAccount:", svcAccount}, ""), "roles/storage.objectViewer")
if err := bucket.IAM().SetPolicy(ctx, policy); err != nil {
return err
}
return nil
}
func importSqlScript(service *sqladmin.Service, projectId string, instanceName string, uri string) error {
ic := &sqladmin.ImportContext{
FileType: "SQL",
Uri: uri,
}
iIR := &sqladmin.InstancesImportRequest{
ImportContext: ic,
}
_, err := service.Instances.Import(projectId, instanceName, iIR).Do()
if err != nil {
return err
}
return nil
}
func updateInstance(service *sqladmin.Service, projectId string, instanceName string) error {
aclEntry := &sqladmin.AclEntry{
Value: "0.0.0.0/0",
}
var aclEntryList []*sqladmin.AclEntry
aclEntryList = append(aclEntryList, aclEntry)
ipConfigs := &sqladmin.IpConfiguration{
AuthorizedNetworks: aclEntryList,
}
newSettings := &sqladmin.Settings{
IpConfiguration: ipConfigs,
}
newDbInstance := &sqladmin.DatabaseInstance{
Settings: newSettings,
}
_, err := service.Instances.Patch(projectId, instanceName, newDbInstance).Do()
if err != nil {
fmt.Printf("Error updating instance :%v", err)
}
return nil
}
func createController(errorMessage string) {
// Give permission to the user
if err := kubernetes.CreateClusterRoleBinding("cluster-admin", accountName); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
// Setup Celley namespace
if err := runtime.CreateCelleryNameSpace(); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
// Apply Istio CRDs
if err := runtime.ApplyIstioCrds(filepath.Join(util.CelleryInstallationDir(), constants.K8sArtifacts)); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
// sleep for few seconds - this is to make sure that the CRDs are properly applied
time.Sleep(20 * time.Second)
// Enabling Istio injection
if err := kubernetes.ApplyLable("namespace", "default", "istio-injection=enabled",
false); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
// Install istio
if err := runtime.InstallIstio(filepath.Join(util.CelleryInstallationDir(), constants.K8sArtifacts)); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
// Install knative serving
if err := runtime.InstallKnativeServing(filepath.Join(util.CelleryInstallationDir(), constants.K8sArtifacts)); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
// Apply controller CRDs
if err := runtime.InstallController(filepath.Join(util.CelleryInstallationDir(), constants.K8sArtifacts)); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
}
func deployMinimalCelleryRuntime() error {
errorDeployingCelleryRuntime := "Error deploying cellery runtime"
createController(errorDeployingCelleryRuntime)
createAllDeploymentArtifacts()
createIdpGcp(errorDeployingCelleryRuntime)
createNGinx(errorDeployingCelleryRuntime)
return nil
}
func deployCompleteCelleryRuntime() {
errorDeployingCelleryRuntime := "Error deploying cellery runtime"
createController(errorDeployingCelleryRuntime)
createAllDeploymentArtifacts()
//Create gateway deployment and the service
if err := gcp.AddApim(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
// Create observability
if err := gcp.AddObservability(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
//Create NGinx
createNGinx(errorDeployingCelleryRuntime)
}
func createIdpGcp(errorDeployingCelleryRuntime string) {
// Create IDP deployment and the service
if err := gcp.CreateIdp(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
}
func createNGinx(errorMessage string) {
// Install nginx-ingress for control plane ingress
if err := gcp.InstallNginx(); err != nil {
util.ExitWithErrorMessage(errorMessage, err)
}
}
func createAllDeploymentArtifacts() {
errorDeployingCelleryRuntime := "Error deploying cellery runtime"
// Create apim NFS volumes and volume claims
if err := gcp.CreatePersistentVolume(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
// Create the gw config maps
if err := gcp.CreateGlobalGatewayConfigMaps(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
// Create Observability configmaps
if err := gcp.CreateObservabilityConfigMaps(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
// Create the IDP config maps
if err := gcp.CreateIdpConfigMaps(); err != nil {
util.ExitWithErrorMessage(errorDeployingCelleryRuntime, err)
}
}
func getGcpData() (string, string, string, string) {
cmd := exec.Command("gcloud", "config", "list", "--format", "json")
stdoutReader, _ := cmd.StdoutPipe()
stdoutScanner := bufio.NewScanner(stdoutReader)
output := ""
go func() {
for stdoutScanner.Scan() {
output = output + stdoutScanner.Text()
}
}()
stderrReader, _ := cmd.StderrPipe()
stderrScanner := bufio.NewScanner(stderrReader)
go func() {
for stderrScanner.Scan() {
fmt.Println(stderrScanner.Text())
}
}()
err := cmd.Start()
if err != nil {
util.ExitWithErrorMessage("Error occurred while getting gcp data", err)
}
err = cmd.Wait()
if err != nil {
util.ExitWithErrorMessage("Error occurred while getting gcp data", err)
}
jsonOutput := &util.Gcp{}
errJson := json.Unmarshal([]byte(output), jsonOutput)
if errJson != nil {
fmt.Println(errJson)
}
return jsonOutput.Core.Project, jsonOutput.Core.Account, jsonOutput.Compute.Region, jsonOutput.Compute.Zone
}
func getCreatedByLabel() map[string]string {
// Add a label to identify the user who created it
labels := make(map[string]string)
createdBy := util.ConvertToAlphanumeric(accountName, "_")
labels["created_by"] = createdBy
return labels
}