-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
629 lines (486 loc) · 19.2 KB
/
main.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
package main
import (
"bytes"
"flag"
"fmt"
"log"
"os"
"os/exec"
"strconv"
"strings"
"time"
"gopkg.in/yaml.v2"
k8Yaml "k8s.io/apimachinery/pkg/util/yaml"
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
knative "knative.dev/serving/pkg/apis/serving/v1"
//"github.com/jedib0t/go-pretty/v6/progress"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/schollz/progressbar/v3"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gw "sigs.k8s.io/gateway-api/apis/v1"
//gw "sigs.k8s.io/gateway-api/apis/v1alpha2"
Yml "sigs.k8s.io/yaml"
)
// struct for unmarshalling revision details from command line
type Revisions struct {
Revision []struct {
RevisionId string `yaml:"revision_id"`
Region string `yaml:"region"`
ProjectId string `yaml:"project_id"`
} `yaml:"revisions"`
}
// function to read revision manifest from command line
func readRevisions(filename string) (Revisions, error) {
buf, err := os.ReadFile(filename)
if err != nil {
log.Fatal(err)
}
//r := &revisions{}
r := Revisions{}
err = yaml.Unmarshal(buf, &r)
if err != nil {
return r, fmt.Errorf("in file %q: %v", filename, err)
}
return r, nil
}
// super hacky way of removing empty fields
// the benefit of doing this is that resources don't always show as `configured` even when there are no changes
func hackToRemoveEmptyFields(ymlBytes []byte) []byte {
lines := bytes.Replace(ymlBytes, []byte(" creationTimestamp: null\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte("spec: {}\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte(" creationTimestamp: null\n"), []byte(""), -1)
lines = bytes.Replace(lines, []byte("status: {}\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte("status:\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte(" strategy: {}\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte(" loadBalancer: {}\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte("currentMetrics: null\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte(" desiredReplicas: 0\n"), []byte(""), 1)
lines = bytes.Replace(lines, []byte(" parents: null\n"), []byte(""), 1)
return lines
}
func generateNamespaceSpec(stream []uint8) []byte {
rev := &knative.Revision{}
ns_1 := &corev1.Namespace{}
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
ns_1.APIVersion = "v1"
ns_1.Kind = "Namespace"
ns_1.ObjectMeta.Name = rev.Labels["serving.knative.dev/service"]
ns_1_yaml, err := Yml.Marshal(ns_1)
if err != nil {
log.Fatal(err)
}
ns_1_yaml = hackToRemoveEmptyFields(ns_1_yaml)
return ns_1_yaml
}
func generateServiceAccountSpec(stream []uint8) []byte {
rev := &knative.Revision{}
sa_1 := &corev1.ServiceAccount{}
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
// set up basics for service account
sa_1.APIVersion = "v1"
sa_1.Kind = "ServiceAccount"
sa_1.ObjectMeta.Name = rev.Labels["serving.knative.dev/service"]
sa_1.ObjectMeta.Namespace = rev.Labels["serving.knative.dev/service"]
// configure the KSA to be ready for Workload Identity
sa_1.Annotations = make(map[string]string)
sa_1.Annotations["iam.gke.io/gcp-service-account"] = rev.Spec.ServiceAccountName
sa_1_yaml, err := Yml.Marshal(sa_1)
if err != nil {
log.Fatal(err)
}
sa_1_yaml = hackToRemoveEmptyFields(sa_1_yaml)
return sa_1_yaml
}
func generateDeploymentSpec(stream []uint8) []byte {
rev := &knative.Revision{}
pod_1 := &corev1.Pod{}
dep_1 := &appsv1.Deployment{}
var dep_replicas int32 = 1 // default number of replicas for the generated deployment
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
// copy podspec from YAML import to new pod
pod_1.Spec = rev.DeepCopy().Spec.PodSpec
// get and set service name from revision to pod
s_name := rev.Labels["serving.knative.dev/service"]
pod_1.Name = s_name
pod_1.Spec.Containers[0].Name = s_name
// hard code the apiVersion & kind
dep_1.APIVersion = "apps/v1"
dep_1.Kind = "Deployment"
// set deployment name and replica count
dep_1.Name = s_name
dep_1.Spec.Replicas = &dep_replicas
dep_1.ObjectMeta.Namespace = rev.Labels["serving.knative.dev/service"]
// selector & labeling setup for deployment
app_label_selector_v1 := v1.LabelSelector{}
label_map := make(map[string]string)
app_label_selector_v1.MatchLabels = label_map
dep_1.Spec.Selector = &app_label_selector_v1
dep_1.Spec.Template.ObjectMeta.Labels = label_map
dep_1.Spec.Template.ObjectMeta.Labels["app"] = s_name
// create some annotations for the deployment's template metadata that indicate the source kn revision
annotation_map := make(map[string]string)
annotation_map["sourceKnativeService"] = s_name
annotation_map["sourceKnativeRevision"] = rev.ObjectMeta.Name
annotation_map["sourceKnativeServiceAccount"] = rev.Spec.ServiceAccountName
dep_1.Spec.Template.Annotations = annotation_map
// copy the podspec container spec to the deployment container spec
dep_1.Spec.Template.Spec.Containers = pod_1.Spec.Containers
// set the service account
dep_1.Spec.Template.Spec.ServiceAccountName = s_name
dep_1_yaml, err := Yml.Marshal(dep_1)
if err != nil {
log.Fatal(err)
}
dep_1_yaml = hackToRemoveEmptyFields(dep_1_yaml)
return dep_1_yaml
}
func generateServiceSpec(stream []uint8, serviceType string, servicePort int) []byte {
service_1 := &corev1.Service{}
rev := &knative.Revision{}
service_port := &corev1.ServicePort{}
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
// set Kind & API
service_1.Kind = "Service"
service_1.APIVersion = "v1"
service_1.Spec.Type = corev1.ServiceType(serviceType)
service_1.ObjectMeta.Namespace = rev.Labels["serving.knative.dev/service"]
service_port.Name = rev.Spec.Containers[0].Ports[0].Name
service_port.Protocol = rev.Spec.Containers[0].Ports[0].Protocol
service_port.Port = int32(servicePort)
service_port.TargetPort.IntVal = rev.Spec.Containers[0].Ports[0].ContainerPort
service_1.Spec.Ports = append(service_1.Spec.Ports, *service_port)
label_map := make(map[string]string)
label_map["app"] = rev.Labels["serving.knative.dev/service"]
service_1.Spec.Selector = label_map
// set Service name
service_1.Name = rev.Labels["serving.knative.dev/service"]
service_1_yaml, err := Yml.Marshal(service_1)
if err != nil {
log.Fatal(err)
}
service_1_yaml = hackToRemoveEmptyFields(service_1_yaml)
return service_1_yaml
}
func generateHorizontalPodAutoscalerSpec(stream []uint8, minReplicas int, maxReplicas int) []byte {
// create HPA resource
hpa_1 := &autoscaling.HorizontalPodAutoscaler{}
rev := &knative.Revision{}
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
// set prelim vars
var avgUtilization int32 = 50
var currentReplicas int32 = 1
var minReplicasPtr *int32 = new(int32)
*minReplicasPtr = int32(minReplicas)
// figure out if maxReplicas has been provided via CLI
if maxReplicas == 0 {
maxReplicas, _ = strconv.Atoi(rev.Annotations["autoscaling.knative.dev/maxScale"])
}
// define fields
hpa_1.APIVersion = "autoscaling/v2"
hpa_1.Kind = "HorizontalPodAutoscaler"
hpa_1.ObjectMeta.Name = rev.Labels["serving.knative.dev/service"]
hpa_1.ObjectMeta.Namespace = rev.Labels["serving.knative.dev/service"]
hpa_1.Spec.ScaleTargetRef.APIVersion = "apps/v1"
hpa_1.Spec.ScaleTargetRef.Kind = "Deployment"
hpa_1.Spec.ScaleTargetRef.Name = rev.Labels["serving.knative.dev/service"]
hpa_1.Spec.MinReplicas = minReplicasPtr
hpa_1.Spec.MaxReplicas = int32(maxReplicas)
hpa_1.Status = autoscaling.HorizontalPodAutoscalerStatus{}
hpa_1.Status.CurrentReplicas = currentReplicas
hpa_1.Status.Conditions = append(hpa_1.Status.Conditions, autoscaling.HorizontalPodAutoscalerCondition{})
// create CPU-based metric spec
metricsSpec := &autoscaling.MetricSpec{}
metricsResource := &autoscaling.ResourceMetricSource{}
metricsResource.Name = "cpu"
metricsResource.Target.Type = "Utilization"
metricsResource.Target.AverageUtilization = &avgUtilization
metricsSpec.Type = "Resource"
metricsSpec.Resource = metricsResource
hpa_1.Spec.Metrics = append(hpa_1.Spec.Metrics, *metricsSpec)
hpa_1.Status = autoscaling.HorizontalPodAutoscaler{}.Status // set blank status for easier cleanup
hpa_1_yaml, err := Yml.Marshal(hpa_1)
if err != nil {
log.Fatal(err)
}
hpa_1_yaml = hackToRemoveEmptyFields(hpa_1_yaml)
return hpa_1_yaml
}
func generateHttpRouteSpec(stream []uint8, gwName string, gwNamespace string, svcPort int) []byte {
httpRoute_1 := gw.HTTPRoute{}
//httpRoute_2 := gw.
httpRouteParentRef := gw.ParentReference{}
httpRouteName := gw.ObjectName(gwName)
httpRouteNamespace := gw.Namespace(gwNamespace)
httpRouteRulesPathMatch := gw.HTTPPathMatch{}
httpRoutePathMatchType := gw.PathMatchType("Exact")
httpRouteBackendRef := gw.HTTPBackendRef{}
httpRouteBackendPort := gw.PortNumber(svcPort)
//httpRouteFilter := gw.HTTPRequestRedirectFilter{}
rev := &knative.Revision{}
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
// set path details
// httpRouteRulesPath := gw.PathMatchPathPrefix("/" + rev.Labels["serving.knative.dev/service"])
prefix := "/" + rev.Labels["serving.knative.dev/service"]
httpRouteRulesPathMatch.Value = &prefix
httpRouteRulesPathMatch.Type = &httpRoutePathMatchType
httpRouteBackendRef.Name = gw.ObjectName(rev.Labels["serving.knative.dev/service"])
httpRouteBackendRef.Port = &httpRouteBackendPort
// set API version and Kind
httpRoute_1.APIVersion = "gateway.networking.k8s.io/v1beta1"
httpRoute_1.Kind = "HTTPRoute"
// configure metadata
httpRoute_1.ObjectMeta.Name = rev.Labels["serving.knative.dev/service"]
httpRoute_1.ObjectMeta.Namespace = rev.Labels["serving.knative.dev/service"]
// configure nested fields
httpRouteParentRef.Name = httpRouteName
httpRouteParentRef.Namespace = &httpRouteNamespace
httpRoute_1.Spec.ParentRefs = make([]gw.ParentReference, 1)
httpRoute_1.Spec.ParentRefs[0] = httpRouteParentRef
httpRoute_1.Spec.Rules = make([]gw.HTTPRouteRule, 1)
//httpRoute_1.Spec.Rules[0] = httpRouteRules
httpRoute_1.Spec.Rules[0].Matches = make([]gw.HTTPRouteMatch, 1)
httpRoute_1.Spec.Rules[0].Matches[0].Path = &httpRouteRulesPathMatch
httpRoute_1.Spec.Rules[0].BackendRefs = make([]gw.HTTPBackendRef, 1)
httpRoute_1.Spec.Rules[0].BackendRefs[0] = httpRouteBackendRef
// handle path rewrites # CAN'T DO THIS YET AS IT'S NOT IMPLEMENTED
/*basePath := ""
httpRoute_1.Spec.Rules[0].Filters = make([]gw.HTTPRouteFilter, 1)
httpRoute_1.Spec.Rules[0].Filters[0].Type = "URLRewrite"
httpRoute_1.Spec.Rules[0].Filters[0].URLRewrite = &gw.HTTPURLRewriteFilter{}
httpRoute_1.Spec.Rules[0].Filters[0].URLRewrite.Path = &gw.HTTPPathModifier{}
httpRoute_1.Spec.Rules[0].Filters[0].URLRewrite.Path.Type = "ReplaceFullPath"
httpRoute_1.Spec.Rules[0].Filters[0].URLRewrite.Path.ReplaceFullPath = &basePath*/
httpRoute_1_yaml, err := Yml.Marshal(httpRoute_1)
if err != nil {
log.Fatal(err)
}
// clean up HTTPRoute output
httpRoute_1_yaml = hackToRemoveEmptyFields(httpRoute_1_yaml)
return httpRoute_1_yaml
}
func kubectlApply(path string) {
kubectl_cmd := exec.Command("kubectl", "apply", "-f", path)
var out bytes.Buffer
var stderr bytes.Buffer
kubectl_cmd.Stdout = &out
kubectl_cmd.Stderr = &stderr
kubectl_err := kubectl_cmd.Run()
if kubectl_err != nil {
//log.Fatal(kubectl_err.Error() + ": " + stderr.String())
log.Fatal(stderr.String())
}
}
func getServiceInfo(stream []uint8) map[string]string {
revInfo := make(map[string]string)
rev := &knative.Revision{}
dec := k8Yaml.NewYAMLOrJSONDecoder(bytes.NewReader([]byte(stream)), 1000)
if err := dec.Decode(&rev); err != nil {
log.Fatal(err)
}
revInfo["serviceName"] = rev.Labels["serving.knative.dev/service"]
revInfo["revisionId"] = rev.Name
revInfo["image"] = rev.Spec.Containers[0].Image
revInfo["cpu"] = rev.Spec.Containers[0].Resources.Limits.Cpu().String()
revInfo["memory"] = rev.Spec.Containers[0].Resources.Limits.Memory().String()
return revInfo
}
func main() {
// pull optional command line params (used to configure service port & service type)
manifestFilePtr := flag.String("manifestFile", "manifest.yaml", "input file name")
serviceTypePtr := flag.String("serviceType", "ClusterIP", "string to indicate type of service to create")
servicePortPtr := flag.Int("servicePort", 80, "int to set external port used by service")
maxReplicasPtr := flag.Int("maxReplicas", 0, "int to set maximum replicas via HPA - otherwise will set to revision maxScale value") // default to zero to detect input
minReplicasPtr := flag.Int("minReplicas", 1, "int to set minimum replicas via HPA")
gwNamePtr := flag.String("gatewayName", "external-http", "string of gateway object name")
gwNamespacePtr := flag.String("gatewayNamespace", "external-gw", "string of gateway namespace")
modePtr := flag.String("mode", "default", "set to `yaml` to dump YAML only instead of applying")
flag.Parse()
/*
// set up piping stdin to utility
reader := bufio.NewReader(os.Stdin)
var output []uint8
for {
input, err := reader.ReadByte()
if err != nil && err == io.EOF {
break
}
output = append(output, input)
}
*/
// get timestamp
timeString := string(time.Now().Format(time.RFC3339))
timeString = strings.Replace(timeString, ":", "", -1)
fmt.Printf("# reading manifest file %v\n", *manifestFilePtr)
r, err := readRevisions(*manifestFilePtr)
if err != nil {
log.Fatal(err)
}
fmt.Printf("# dumping YAML to %v\n", "output/"+timeString+"/")
// decide whether we run in default "apply" mode where script automatically applies to current kubecontxt or,
// if `--mode yaml`, just dump the YAML to stdout. note that in either case, the YAML will also be written to
// a time-stamped subfolder of `ouput/`
if *modePtr == "yaml" {
// cycle through revisions and process
for _, revision := range r.Revision {
// get revision info via gcloud
var out bytes.Buffer
cmd := exec.Command("gcloud", "run", "revisions", "describe", revision.RevisionId, "--region="+revision.Region, "--project="+revision.ProjectId, "--format=yaml")
cmd.Stdout = &out
cmd_err := cmd.Run()
if err != nil {
log.Fatal(cmd_err)
}
// get revision data
serviceInfo := getServiceInfo(out.Bytes())
// create subfolder per revision
pathPrefix := "output/" + timeString + "/" + serviceInfo["serviceName"] + "/"
err := os.MkdirAll(pathPrefix+"", 0755)
if err != nil {
log.Fatal(err)
}
// create and apply YAML files
namespaceSpec := generateNamespaceSpec(out.Bytes())
ns_err := os.WriteFile(pathPrefix+"ns.yaml", namespaceSpec, 0755)
if ns_err != nil {
log.Fatal(ns_err)
}
fmt.Printf(string(namespaceSpec))
fmt.Print("---\n")
serviceAccountSpec := generateServiceAccountSpec(out.Bytes())
sa_err := os.WriteFile(pathPrefix+"sa.yaml", serviceAccountSpec, 0755)
if sa_err != nil {
log.Fatal(sa_err)
}
fmt.Printf(string(serviceAccountSpec))
fmt.Print("---\n")
deploymentSpec := generateDeploymentSpec(out.Bytes())
deployment_err := os.WriteFile(pathPrefix+"deployment.yaml", deploymentSpec, 0755)
if deployment_err != nil {
log.Fatal(deployment_err)
}
fmt.Printf(string(deploymentSpec))
fmt.Print("---\n")
serviceSpec := generateServiceSpec(out.Bytes(), *serviceTypePtr, *servicePortPtr)
service_err := os.WriteFile(pathPrefix+"service.yaml", serviceSpec, 0755)
if service_err != nil {
log.Fatal(service_err)
}
fmt.Printf(string(serviceSpec))
fmt.Print("---\n")
hpaSpec := generateHorizontalPodAutoscalerSpec(out.Bytes(), *minReplicasPtr, *maxReplicasPtr)
hpa_err := os.WriteFile(pathPrefix+"hpa.yaml", hpaSpec, 0755)
if hpa_err != nil {
log.Fatal(hpa_err)
}
fmt.Printf(string(hpaSpec))
fmt.Print("---\n")
routeSpec := generateHttpRouteSpec(out.Bytes(), *gwNamePtr, *gwNamespacePtr, 80)
route_err := os.WriteFile(pathPrefix+"route.yaml", routeSpec, 0755)
if route_err != nil {
log.Fatal(route_err)
}
fmt.Printf(string(routeSpec))
fmt.Print("---\n")
}
} else {
// create output table
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Service", "Revision", "Image", "CPU", "Memory", "Path"})
// create progress
//p := progress.NewWriter()
//p.SetOutputWriter(os.Stdout)
// cycle through revisions and process
for _, revision := range r.Revision {
// get revision info via gcloud
var out bytes.Buffer
cmd := exec.Command("gcloud", "run", "revisions", "describe", revision.RevisionId, "--region="+revision.Region, "--project="+revision.ProjectId, "--format=yaml")
cmd.Stdout = &out
cmd_err := cmd.Run()
if err != nil {
log.Fatal(cmd_err)
}
// get revision data
serviceInfo := getServiceInfo(out.Bytes())
// create table output
t.AppendRow([]interface{}{serviceInfo["serviceName"], serviceInfo["revisionId"], serviceInfo["image"], serviceInfo["cpu"], serviceInfo["memory"], "/" + serviceInfo["serviceName"]})
t.AppendSeparator()
// set up progress bar
fmt.Printf("\nProcessing revision %v of service %v\n", serviceInfo["revisionId"], serviceInfo["serviceName"])
bar := progressbar.NewOptions(100, progressbar.OptionSetWidth(50), progressbar.OptionEnableColorCodes(true), progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "[green]=[reset]",
SaucerHead: "[green]>[reset]",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
//bar = bar
// create subfolder per revision
pathPrefix := "output/" + timeString + "/" + serviceInfo["serviceName"] + "/"
err := os.MkdirAll(pathPrefix+"", 0755)
if err != nil {
log.Fatal(err)
}
bar.Add(10)
// create and apply YAML files
ns_err := os.WriteFile(pathPrefix+"ns.yaml", generateNamespaceSpec(out.Bytes()), 0755)
if ns_err != nil {
log.Fatal(ns_err)
}
kubectlApply(pathPrefix + "ns.yaml")
bar.Add(15)
sa_err := os.WriteFile(pathPrefix+"sa.yaml", generateServiceAccountSpec(out.Bytes()), 0755)
if sa_err != nil {
log.Fatal(sa_err)
}
kubectlApply(pathPrefix + "sa.yaml")
bar.Add(15)
deployment_err := os.WriteFile(pathPrefix+"deployment.yaml", generateDeploymentSpec(out.Bytes()), 0755)
if deployment_err != nil {
log.Fatal(deployment_err)
}
kubectlApply(pathPrefix + "deployment.yaml")
bar.Add(15)
service_err := os.WriteFile(pathPrefix+"service.yaml", generateServiceSpec(out.Bytes(), *serviceTypePtr, *servicePortPtr), 0755)
if service_err != nil {
log.Fatal(service_err)
}
kubectlApply(pathPrefix + "service.yaml")
bar.Add(15)
hpa_err := os.WriteFile(pathPrefix+"hpa.yaml", generateHorizontalPodAutoscalerSpec(out.Bytes(), *minReplicasPtr, *maxReplicasPtr), 0755)
if hpa_err != nil {
log.Fatal(hpa_err)
}
kubectlApply(pathPrefix + "hpa.yaml")
bar.Add(15)
route_err := os.WriteFile(pathPrefix+"route.yaml", generateHttpRouteSpec(out.Bytes(), *gwNamePtr, *gwNamespacePtr, 80), 0755)
if route_err != nil {
log.Fatal(route_err)
}
kubectlApply(pathPrefix + "route.yaml")
bar.Add(15)
}
fmt.Printf("\n\nResults:\n")
t.Render()
}
}