4
4
package cmd
5
5
6
6
import (
7
+ "errors"
7
8
"fmt"
9
+ "github.com/openfaas-incubator/ofc-bootstrap/pkg/stack"
8
10
"io/ioutil"
9
11
"log"
10
12
"os"
@@ -18,13 +20,10 @@ import (
18
20
execute "github.com/alexellis/go-execute/pkg/v1"
19
21
"github.com/alexellis/k3sup/pkg/config"
20
22
"github.com/alexellis/k3sup/pkg/env"
21
- "github.com/openfaas-incubator/ofc-bootstrap/pkg/ingress"
22
- "github.com/openfaas-incubator/ofc-bootstrap/pkg/stack"
23
- "github.com/openfaas-incubator/ofc-bootstrap/pkg/tls"
24
23
"github.com/openfaas-incubator/ofc-bootstrap/pkg/validators"
25
24
26
25
"github.com/openfaas-incubator/ofc-bootstrap/pkg/types"
27
- yaml "gopkg.in/yaml.v2"
26
+ "gopkg.in/yaml.v2"
28
27
)
29
28
30
29
func init () {
@@ -141,7 +140,7 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
141
140
"faas-cli version" ,
142
141
}
143
142
144
- validateToolsErr := validateTools (tools , additionalPaths )
143
+ validateToolsErr := validateTools (tools )
145
144
146
145
if validateToolsErr != nil {
147
146
panic (validateToolsErr )
@@ -184,7 +183,7 @@ type Vars struct {
184
183
YamlFile string
185
184
}
186
185
187
- func taskGivesStdout (tool string , additionalPaths [] string ) error {
186
+ func taskGivesStdout (tool string ) error {
188
187
189
188
parts := strings .Split (tool , " " )
190
189
@@ -210,10 +209,10 @@ func taskGivesStdout(tool string, additionalPaths []string) error {
210
209
return nil
211
210
}
212
211
213
- func validateTools (tools []string , additionalPaths [] string ) error {
212
+ func validateTools (tools []string ) error {
214
213
215
214
for _ , tool := range tools {
216
- err := taskGivesStdout (tool , additionalPaths )
215
+ err := taskGivesStdout (tool )
217
216
if err != nil {
218
217
return err
219
218
}
@@ -350,23 +349,12 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
350
349
}
351
350
}
352
351
353
- ingressErr := ingress .Apply (plan )
354
- if ingressErr != nil {
355
- log .Println (ingressErr )
356
- }
357
-
358
- if plan .TLS {
359
- tlsErr := tls .Apply (plan )
360
- if tlsErr != nil {
361
- log .Println (tlsErr )
362
- }
363
- }
364
-
365
352
fmt .Println ("Creating stack.yml" )
366
353
367
354
planErr := stack .Apply (plan )
368
355
if planErr != nil {
369
356
log .Println (planErr )
357
+ return planErr
370
358
}
371
359
372
360
if ! prefs .SkipSealedSecrets {
@@ -389,6 +377,11 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
389
377
return cloneErr
390
378
}
391
379
380
+ ofcValuesErr := writeOFCValuesYaml (plan )
381
+ if ofcValuesErr != nil {
382
+ return ofcValuesErr
383
+ }
384
+
392
385
deployErr := deployCloudComponents (plan , additionalPaths )
393
386
if deployErr != nil {
394
387
return deployErr
@@ -397,33 +390,80 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
397
390
return nil
398
391
}
399
392
400
- func helmRepoAdd ( name , repo string ) error {
401
- log . Printf ( "Adding %s helm repo \n " , name )
393
+ func writeOFCValuesYaml ( plan types. Plan ) error {
394
+ ofcOptions := & types. OFCValues {}
402
395
403
- task := execute.ExecTask {
404
- Command : "helm" ,
405
- Args : []string {"repo" , "add" , name , repo },
406
- StreamStdio : true ,
396
+ ofcOptions .NetworkPolicies .Enabled = plan .NetworkPolicies
397
+
398
+ if plan .EnableOAuth {
399
+ ofcOptions .EdgeAuth .EnableOauth2 = true
400
+ ofcOptions .EdgeAuth .OauthProvider = plan .SCM
401
+ ofcOptions .EdgeAuth .ClientID = plan .OAuth .ClientId
402
+ ofcOptions .EdgeAuth .OauthProviderBaseURL = plan .OAuth .OAuthProviderBaseURL
403
+ } else {
404
+ ofcOptions .EdgeAuth .EnableOauth2 = false
407
405
}
408
406
409
- taskRes , taskErr := task .Execute ()
407
+ ofcOptions .NetworkPolicies .Enabled = plan .NetworkPolicies
408
+ ofcOptions .Global .EnableECR = plan .EnableECR
410
409
411
- if taskErr != nil {
412
- return taskErr
410
+ if plan .TLS {
411
+ ofcOptions .TLS .IssuerType = plan .TLSConfig .IssuerType
412
+ ofcOptions .TLS .Enabled = true
413
+ ofcOptions .TLS .Email = plan .TLSConfig .Email
414
+ ofcOptions .TLS .DNSService = plan .TLSConfig .DNSService
415
+ switch ofcOptions .TLS .DNSService {
416
+ case types .CloudDNS :
417
+ ofcOptions .TLS .CloudDNS .ProjectID = plan .TLSConfig .ProjectID
418
+ case types .Cloudflare :
419
+ ofcOptions .TLS .Cloudflare .Email = plan .TLSConfig .Email
420
+ ofcOptions .TLS .Cloudflare .ProjectID = plan .TLSConfig .ProjectID
421
+ case types .Route53 :
422
+ ofcOptions .TLS .Route53 .AccessKeyID = plan .TLSConfig .AccessKeyID
423
+ ofcOptions .TLS .Route53 .Region = plan .TLSConfig .Region
424
+ case types .DigitalOcean :
425
+ // No special config for DO DNS
426
+ default :
427
+ log .Fatalf ("dns service not recognised: %s" , ofcOptions .TLS .DNSService )
428
+ }
429
+
430
+ } else {
431
+ ofcOptions .TLS .Enabled = false
413
432
}
414
433
415
- if len (taskRes .Stderr ) > 0 {
416
- log .Println (taskRes .Stderr )
434
+ if plan .CustomersSecret {
435
+ ofcOptions .Customers .CustomersSecret = true
436
+ } else {
437
+ if len (plan .CustomersURL ) == 0 {
438
+ return errors .New ("unable to continue without a customers secret or url" )
439
+ }
440
+ ofcOptions .Customers .URL = plan .CustomersURL
441
+ }
442
+
443
+ ofcOptions .Global .EnableECR = plan .EnableECR
444
+ ofcOptions .Global .RootDomain = plan .RootDomain
445
+
446
+ ofcOptions .Ingress .MaxConnections = plan .IngressConfig .MaxConnections
447
+ ofcOptions .Ingress .RequestsPerMinute = plan .IngressConfig .RequestsPerMinute
448
+ yamlBytes , err := yaml .Marshal (& ofcOptions )
449
+ if err != nil {
450
+ log .Fatalf ("error: %v" , err )
451
+ }
452
+ filePath := "./tmp/ofc-values.yaml"
453
+ fileErr := ioutil .WriteFile (filePath , yamlBytes , 0644 )
454
+ if fileErr != nil {
455
+ return fileErr
417
456
}
418
457
419
458
return nil
420
459
}
421
460
422
- func helmRepoAddStable ( ) error {
423
- log .Println ("Adding stable helm repo" )
461
+ func helmRepoAdd ( name , repo string ) error {
462
+ log .Printf ("Adding %s helm repo\n " , name )
424
463
425
464
task := execute.ExecTask {
426
465
Command : "helm" ,
466
+ Args : []string {"repo" , "add" , name , repo },
427
467
StreamStdio : true ,
428
468
}
429
469
@@ -660,19 +700,6 @@ func createSecrets(plan types.Plan) error {
660
700
return nil
661
701
}
662
702
663
- func sealedSecretsReady () bool {
664
-
665
- task := execute.ExecTask {
666
- Command : "./scripts/get-sealedsecretscontroller.sh" ,
667
- Shell : true ,
668
- StreamStdio : true ,
669
- }
670
-
671
- res , err := task .Execute ()
672
- fmt .Println ("sealedsecretscontroller" , res .ExitCode , res .Stdout , res .Stderr , err )
673
- return res .Stdout == "1"
674
- }
675
-
676
703
func exportSealedSecretPubCert () string {
677
704
678
705
task := execute.ExecTask {
0 commit comments