Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 417795a

Browse files
committed
Replace templating and custom deployment with Helm
This commit replaces the custom OFC installation scripts (shell script and golang) with the OFC Helm chart which is pulled from the OFC release specified in the init.yaml. This has been tested using my init.yaml taken from a working cluster and applied to a new cluster (same init.yaml) with the new deployment method using the chart Signed-off-by: Alistair Hey <alistair@heyal.co.uk>
1 parent 2953be6 commit 417795a

18 files changed

+140
-932
lines changed

cmd/apply.go

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package cmd
55

66
import (
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

3029
func 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-
676700
func exportSealedSecretPubCert() string {
677701

678702
task := execute.ExecTask{

pkg/ingress/ingress.go

Lines changed: 0 additions & 98 deletions
This file was deleted.

pkg/ingress/ingress_test.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

pkg/stack/stack.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type awsConfig struct {
5050
ECRRegion string
5151
}
5252

53-
// Apply creates `templates/gateway_config.yml` to be referenced by stack.yml
5453
func Apply(plan types.Plan) error {
5554
scheme := "http"
5655
if plan.TLS {
@@ -67,7 +66,6 @@ func Apply(plan types.Plan) error {
6766
Registry: plan.Registry,
6867
RootDomain: plan.RootDomain,
6968
CustomersURL: plan.CustomersURL,
70-
Scheme: scheme,
7169
S3: plan.S3,
7270
CustomTemplates: plan.Deployment.FormatCustomTemplates(),
7371
EnableDockerfileLang: plan.EnableDockerfileLang,
@@ -105,26 +103,6 @@ func Apply(plan types.Plan) error {
105103
return dashboardConfigErr
106104
}
107105

108-
if plan.EnableOAuth {
109-
ofCustomersSecretPath := ""
110-
if plan.CustomersSecret {
111-
ofCustomersSecretPath = "/var/secrets/of-customers/of-customers"
112-
}
113-
114-
if ofAuthDepErr := generateTemplate("edge-auth-dep", plan, authConfig{
115-
RootDomain: plan.RootDomain,
116-
ClientId: plan.OAuth.ClientId,
117-
CustomersURL: plan.CustomersURL,
118-
Scheme: scheme,
119-
OAuthProvider: plan.SCM,
120-
OAuthProviderBaseURL: plan.OAuth.OAuthProviderBaseURL,
121-
OFCustomersSecretPath: ofCustomersSecretPath,
122-
TLSEnabled: plan.TLS,
123-
}); ofAuthDepErr != nil {
124-
return ofAuthDepErr
125-
}
126-
}
127-
128106
isGitHub := plan.SCM == "github"
129107
if stackErr := generateTemplate("stack", plan, stackConfig{
130108
GitHub: isGitHub,
@@ -133,12 +111,6 @@ func Apply(plan types.Plan) error {
133111
return stackErr
134112
}
135113

136-
if builderErr := generateTemplate("of-builder-dep", plan, builderConfig{
137-
ECR: plan.EnableECR,
138-
}); builderErr != nil {
139-
return builderErr
140-
}
141-
142114
if ecrErr := generateTemplate("aws", plan, awsConfig{
143115
ECRRegion: plan.ECRConfig.ECRRegion,
144116
}); ecrErr != nil {

pkg/tls/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)