44package cmd
55
66import (
7+ "errors"
78 "fmt"
9+ "github.com/openfaas-incubator/ofc-bootstrap/pkg/stack"
810 "io/ioutil"
911 "log"
1012 "os"
@@ -18,13 +20,10 @@ import (
1820 execute "github.com/alexellis/go-execute/pkg/v1"
1921 "github.com/alexellis/k3sup/pkg/config"
2022 "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"
2423 "github.com/openfaas-incubator/ofc-bootstrap/pkg/validators"
2524
2625 "github.com/openfaas-incubator/ofc-bootstrap/pkg/types"
27- yaml "gopkg.in/yaml.v2"
26+ "gopkg.in/yaml.v2"
2827)
2928
3029func init () {
@@ -141,7 +140,7 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
141140 "faas-cli version" ,
142141 }
143142
144- validateToolsErr := validateTools (tools , additionalPaths )
143+ validateToolsErr := validateTools (tools )
145144
146145 if validateToolsErr != nil {
147146 panic (validateToolsErr )
@@ -184,7 +183,7 @@ type Vars struct {
184183 YamlFile string
185184}
186185
187- func taskGivesStdout (tool string , additionalPaths [] string ) error {
186+ func taskGivesStdout (tool string ) error {
188187
189188 parts := strings .Split (tool , " " )
190189
@@ -210,10 +209,10 @@ func taskGivesStdout(tool string, additionalPaths []string) error {
210209 return nil
211210}
212211
213- func validateTools (tools []string , additionalPaths [] string ) error {
212+ func validateTools (tools []string ) error {
214213
215214 for _ , tool := range tools {
216- err := taskGivesStdout (tool , additionalPaths )
215+ err := taskGivesStdout (tool )
217216 if err != nil {
218217 return err
219218 }
@@ -350,23 +349,12 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
350349 }
351350 }
352351
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-
365352 fmt .Println ("Creating stack.yml" )
366353
367354 planErr := stack .Apply (plan )
368355 if planErr != nil {
369356 log .Println (planErr )
357+ return planErr
370358 }
371359
372360 if ! prefs .SkipSealedSecrets {
@@ -389,6 +377,11 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
389377 return cloneErr
390378 }
391379
380+ ofcValuesErr := writeOFCValuesYaml (plan )
381+ if ofcValuesErr != nil {
382+ return ofcValuesErr
383+ }
384+
392385 deployErr := deployCloudComponents (plan , additionalPaths )
393386 if deployErr != nil {
394387 return deployErr
@@ -397,33 +390,80 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
397390 return nil
398391}
399392
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 {}
402395
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
407405 }
408406
409- taskRes , taskErr := task .Execute ()
407+ ofcOptions .NetworkPolicies .Enabled = plan .NetworkPolicies
408+ ofcOptions .Global .EnableECR = plan .EnableECR
410409
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
413432 }
414433
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
417456 }
418457
419458 return nil
420459}
421460
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 )
424463
425464 task := execute.ExecTask {
426465 Command : "helm" ,
466+ Args : []string {"repo" , "add" , name , repo },
427467 StreamStdio : true ,
428468 }
429469
@@ -660,19 +700,6 @@ func createSecrets(plan types.Plan) error {
660700 return nil
661701}
662702
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-
676703func exportSealedSecretPubCert () string {
677704
678705 task := execute.ExecTask {
0 commit comments