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

Commit dde768f

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 <[email protected]>
1 parent 49f2251 commit dde768f

20 files changed

+147
-958
lines changed

cmd/apply.go

+73-46
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,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-
676703
func exportSealedSecretPubCert() string {
677704

678705
task := execute.ExecTask{

example.init.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,7 @@ enable_ingress_operator: false
333333
### Usage: release tag, a SHA or branch name
334334
openfaas_cloud_version: 0.14.2
335335

336+
## Settings for the ingress records
337+
ingress_config:
338+
max_connections: 20
339+
requests_per_minute: 600

pkg/ingress/ingress.go

-98
This file was deleted.

pkg/ingress/ingress_test.go

-29
This file was deleted.

pkg/stack/stack.go

-28
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 {

0 commit comments

Comments
 (0)