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,11 @@ 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
367- planErr := stack .Apply (plan )
368- if planErr != nil {
354+ planErr := stack .Apply (plan ); if planErr != nil {
369355 log .Println (planErr )
356+ return planErr
370357 }
371358
372359 if ! prefs .SkipSealedSecrets {
@@ -389,41 +376,91 @@ func process(plan types.Plan, prefs InstallPreferences, additionalPaths []string
389376 return cloneErr
390377 }
391378
392- deployErr := deployCloudComponents (plan , additionalPaths )
393- if deployErr != nil {
379+ ofcValuesErr := writeOFCValuesYaml (plan )
380+ if ofcValuesErr != nil {
381+ return ofcValuesErr
382+ }
383+
384+ deployErr := deployCloudComponents (plan , additionalPaths ); if deployErr != nil {
394385 return deployErr
395386 }
396387
397388 return nil
398389}
399390
400- func helmRepoAdd ( name , repo string ) error {
401- log . Printf ( "Adding %s helm repo \n " , name )
391+ func writeOFCValuesYaml ( plan types. Plan ) error {
392+ ofcOptions := & types. OFCValues {}
402393
403- task := execute.ExecTask {
404- Command : "helm" ,
405- Args : []string {"repo" , "add" , name , repo },
406- StreamStdio : true ,
394+ ofcOptions .NetworkPolicies .Enabled = plan .NetworkPolicies
395+
396+
397+ if plan .EnableOAuth {
398+ ofcOptions .EdgeAuth .EnableOauth2 = true
399+ ofcOptions .EdgeAuth .OauthProvider = plan .SCM
400+ ofcOptions .EdgeAuth .ClientID = plan .OAuth .ClientId
401+ ofcOptions .EdgeAuth .OauthProviderBaseURL = plan .OAuth .OAuthProviderBaseURL
402+ } else {
403+ ofcOptions .EdgeAuth .EnableOauth2 = false
407404 }
408405
409- taskRes , taskErr := task .Execute ()
406+ ofcOptions .NetworkPolicies .Enabled = plan .NetworkPolicies
407+ ofcOptions .Global .EnableECR = plan .EnableECR
410408
411- if taskErr != nil {
412- return taskErr
409+ if plan .TLS {
410+ ofcOptions .TLS .IssuerType = plan .TLSConfig .IssuerType
411+ ofcOptions .TLS .Enabled = true
412+ ofcOptions .TLS .Email = plan .TLSConfig .Email
413+ ofcOptions .TLS .DNSService = plan .TLSConfig .DNSService
414+ switch ofcOptions .TLS .DNSService {
415+ case types .CloudDNS :
416+ ofcOptions .TLS .CloudDNS .ProjectID = plan .TLSConfig .ProjectID
417+ case types .Cloudflare :
418+ ofcOptions .TLS .Cloudflare .Email = plan .TLSConfig .Email
419+ ofcOptions .TLS .Cloudflare .ProjectID = plan .TLSConfig .ProjectID
420+ case types .Route53 :
421+ ofcOptions .TLS .Route53 .AccessKeyID = plan .TLSConfig .AccessKeyID
422+ ofcOptions .TLS .Route53 .Region = plan .TLSConfig .Region
423+ case types .DigitalOcean :
424+ // No special config for DO DNS
425+ default :
426+ log .Fatalf ("dns service not recognised: %s" , ofcOptions .TLS .DNSService )
427+ }
428+
429+ } else {
430+ ofcOptions .TLS .Enabled = false
413431 }
414432
415- if len (taskRes .Stderr ) > 0 {
416- log .Println (taskRes .Stderr )
433+ if plan .CustomersSecret {
434+ ofcOptions .Customers .CustomersSecret = true
435+ } else {
436+ if len (plan .CustomersURL ) == 0 {
437+ return errors .New ("unable to continue without a customers secret or url" )
438+ }
439+ ofcOptions .Customers .URL = plan .CustomersURL
440+ }
441+
442+
443+ ofcOptions .Global .EnableECR = plan .EnableECR
444+ ofcOptions .Global .RootDomain = plan .RootDomain
445+
446+ yamlBytes , err := yaml .Marshal (& ofcOptions )
447+ if err != nil {
448+ log .Fatalf ("error: %v" , err )
449+ }
450+ filePath := "./tmp/ofc-values.yaml"
451+ fileErr := ioutil .WriteFile (filePath , yamlBytes , 0644 ); if fileErr != nil {
452+ return fileErr
417453 }
418454
419455 return nil
420456}
421457
422- func helmRepoAddStable ( ) error {
423- log .Println ("Adding stable helm repo" )
458+ func helmRepoAdd ( name , repo string ) error {
459+ log .Printf ("Adding %s helm repo\n " , name )
424460
425461 task := execute.ExecTask {
426462 Command : "helm" ,
463+ Args : []string {"repo" , "add" , name , repo },
427464 StreamStdio : true ,
428465 }
429466
@@ -660,19 +697,6 @@ func createSecrets(plan types.Plan) error {
660697 return nil
661698}
662699
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-
676700func exportSealedSecretPubCert () string {
677701
678702 task := execute.ExecTask {
0 commit comments