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

Commit 56918a2

Browse files
committed
Expose custom_templates to end-users
- this change allows end-users provisioning ofc to opt into which template repos they want to use - tested with kind - git-tar showed the correct overridden list in the expected format Signed-off-by: Alex Ellis <alexellis2@gmail.com>
1 parent 85bb43e commit 56918a2

File tree

5 files changed

+87
-11
lines changed

5 files changed

+87
-11
lines changed

example.init.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ root_domain: "myfaas.club"
153153
## Keep active if using a cluster with a LoadBalancer available.
154154
ingress: loadbalancer
155155

156+
deployment:
157+
custom_templates:
158+
- "https://github.com/openfaas-incubator/node8-express-template.git"
159+
- "https://github.com/openfaas-incubator/golang-http-template.git"
160+
- "https://github.com/openfaas-incubator/node10-express-template.git"
161+
156162
scm: github
157163
# scm: gitlab
158164

pkg/stack/stack.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import (
1010
)
1111

1212
type gatewayConfig struct {
13-
Registry string
14-
RootDomain string
15-
CustomersURL string
16-
Scheme string
17-
S3 types.S3
13+
Registry string
14+
RootDomain string
15+
CustomersURL string
16+
Scheme string
17+
S3 types.S3
18+
CustomTemplates string
1819
}
1920

2021
type authConfig struct {
@@ -34,12 +35,14 @@ func Apply(plan types.Plan) error {
3435
}
3536

3637
gwConfigErr := generateTemplate("gateway_config", plan, gatewayConfig{
37-
Registry: plan.Registry,
38-
RootDomain: plan.RootDomain,
39-
CustomersURL: plan.CustomersURL,
40-
Scheme: scheme,
41-
S3: plan.S3,
38+
Registry: plan.Registry,
39+
RootDomain: plan.RootDomain,
40+
CustomersURL: plan.CustomersURL,
41+
Scheme: scheme,
42+
S3: plan.S3,
43+
CustomTemplates: plan.Deployment.FormatCustomTemplates(),
4244
})
45+
4346
if gwConfigErr != nil {
4447
return gwConfigErr
4548
}

pkg/types/deployment_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package types
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestFormatCustomTemplates_None(t *testing.T) {
8+
9+
d := Deployment{
10+
CustomTemplate: []string{},
11+
}
12+
13+
want := ""
14+
got := d.FormatCustomTemplates()
15+
if got != want {
16+
t.Errorf("FormatCustomTemplates want: %s, got %s", want, got)
17+
t.Fail()
18+
}
19+
}
20+
21+
func TestFormatCustomTemplates_Single(t *testing.T) {
22+
23+
d := Deployment{
24+
CustomTemplate: []string{"https://w.com/repo1"},
25+
}
26+
27+
want := d.CustomTemplate[0]
28+
got := d.FormatCustomTemplates()
29+
if got != want {
30+
t.Errorf("FormatCustomTemplates want: %s, got %s", want, got)
31+
t.Fail()
32+
}
33+
}
34+
35+
func TestFormatCustomTemplates_Two(t *testing.T) {
36+
37+
d := Deployment{
38+
CustomTemplate: []string{
39+
"https://w.com/repo1",
40+
"https://w.com/repo2",
41+
},
42+
}
43+
44+
want := d.CustomTemplate[0] + ", " + d.CustomTemplate[1]
45+
got := d.FormatCustomTemplates()
46+
if got != want {
47+
t.Errorf("FormatCustomTemplates want: %s, got %s", want, got)
48+
t.Fail()
49+
}
50+
}

pkg/types/types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ type Plan struct {
5050
TLSConfig TLSConfig `yaml:"tls_config"`
5151
Slack Slack `yaml:"slack"`
5252
Ingress string `yaml:"ingress"`
53+
Deployment Deployment `yaml:"deployment"`
54+
}
55+
56+
// Deployment is the deployment section of YAML concerning
57+
// functions as deployed
58+
type Deployment struct {
59+
CustomTemplate []string `yaml:"custom_templates"`
60+
}
61+
62+
// FormatCustomTemplates are formatted in a CSV format with a space after each comma
63+
func (d Deployment) FormatCustomTemplates() string {
64+
val := ""
65+
for _, templateURL := range d.CustomTemplate {
66+
val = val + templateURL + ", "
67+
}
68+
69+
return strings.TrimRight(val, " ,")
5370
}
5471

5572
type KeyValueTuple struct {

templates/gateway_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ environment:
88
gateway_pretty_url: {{.Scheme}}://user.{{.RootDomain}}/function
99
# Add your custom templates by adding a coma separated URL, i.e. extend the current value with:
1010
# ", https://github.com/custom/template.git, https://github.com/custom/template2.git"
11-
custom_templates: "https://github.com/openfaas-incubator/node8-express-template.git, https://github.com/openfaas-incubator/golang-http-template.git, https://github.com/openfaas-incubator/node10-express-template.git"
11+
custom_templates: {{ .CustomTemplates }}
1212

1313
# Security
1414
customers_url: "{{.CustomersURL}}"

0 commit comments

Comments
 (0)