Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Ingress default values #491

Merged
merged 11 commits into from
Apr 15, 2019
5 changes: 1 addition & 4 deletions app/fissile.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,7 @@ func (f *Fissile) GenerateKube(settings kube.ExportSettings) error {
}

if settings.CreateHelmChart {
values, err := kube.MakeValues(settings)
if err != nil {
return err
}
values := kube.MakeValues(settings)
err = f.writeHelmNode(settings.OutputDir, "values.yaml", values)
if err != nil {
return err
Expand Down
12 changes: 9 additions & 3 deletions kube/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func formattedExample(example string) string {
return example
}

// MakeValues returns a Mapping with all default values for the Helm chart
func MakeValues(settings ExportSettings) (helm.Node, error) {
// MakeValues returns a Mapping with all default values for the Helm chart.
func MakeValues(settings ExportSettings) helm.Node {
values := MakeBasicValues()
env := helm.NewMapping()
secrets := helm.NewMapping()
Expand Down Expand Up @@ -265,5 +265,11 @@ func MakeValues(settings ExportSettings) (helm.Node, error) {
}
values.Add("enable", enable.Sort())

return values, nil
ingress := helm.NewMapping()
ingress.Add("annotations", helm.NewMapping(), helm.Comment("ingress.annotations allows specifying custom ingress annotations that gets merged to the default annotations."))
ingress.Add("enabled", false, helm.Comment("ingress.enabled enables ingress support - working ingress controller necessary."))
ingress.Add("tls", helm.NewMapping(), helm.Comment("ingress.tls.crt and ingress.tls.key, when specified, are used by the TLS secret for the Ingress resource."))
values.Add("ingress", ingress.Sort())
f0rmiga marked this conversation as resolved.
Show resolved Hide resolved

return values
}
100 changes: 55 additions & 45 deletions kube/values_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package kube

import (
"io/ioutil"
"os"
"testing"

"code.cloudfoundry.org/fissile/model"
Expand All @@ -14,14 +12,9 @@ import (
func TestMakeValues(t *testing.T) {
t.Parallel()

outDir, err := ioutil.TempDir("", "fissile-generate-auth-")
require.NoError(t, err)
defer os.RemoveAll(outDir)

t.Run("Capabilities", func(t *testing.T) {
t.Parallel()
settings := ExportSettings{
OutputDir: outDir,
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{
&model.InstanceGroup{
Expand All @@ -35,15 +28,11 @@ func TestMakeValues(t *testing.T) {
},
}

node, err := MakeValues(settings)

assert.NotNil(t, node)
assert.NoError(t, err)
node := MakeValues(settings)
require.NotNil(t, node)

actual, err := RoundtripKube(node)
if !assert.NoError(t, err) {
return
}
require.NoError(t, err)
testhelpers.IsYAMLSubsetString(assert.New(t), `---
sizing:
arole:
Expand All @@ -54,7 +43,6 @@ func TestMakeValues(t *testing.T) {
t.Run("Sizing", func(t *testing.T) {
t.Parallel()
settings := ExportSettings{
OutputDir: outDir,
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{
&model.InstanceGroup{
Expand All @@ -68,8 +56,7 @@ func TestMakeValues(t *testing.T) {
},
}

node, err := MakeValues(settings)
assert.NoError(t, err)
node := MakeValues(settings)
require.NotNil(t, node)

sizing := node.Get("sizing")
Expand All @@ -80,16 +67,14 @@ func TestMakeValues(t *testing.T) {
t.Run("Check Default Registry", func(t *testing.T) {
t.Parallel()
settings := ExportSettings{
OutputDir: outDir,
RoleManifest: &model.RoleManifest{InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
},
}

node, err := MakeValues(settings)

assert.NotNil(t, node)
assert.NoError(t, err)
node := MakeValues(settings)
require.NotNil(t, node)

registry := node.Get("kube").Get("registry").Get("hostname")

Expand All @@ -99,18 +84,16 @@ func TestMakeValues(t *testing.T) {
t.Run("Check Custom Registry", func(t *testing.T) {
t.Parallel()
settings := ExportSettings{
OutputDir: outDir,
RoleManifest: &model.RoleManifest{InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
},
}

settings.Registry = "example.com"

node, err := MakeValues(settings)

assert.NotNil(t, node)
assert.NoError(t, err)
node := MakeValues(settings)
require.NotNil(t, node)

registry := node.Get("kube").Get("registry").Get("hostname")

Expand All @@ -120,16 +103,14 @@ func TestMakeValues(t *testing.T) {
t.Run("Check Default Auth", func(t *testing.T) {
t.Parallel()
settings := ExportSettings{
OutputDir: outDir,
RoleManifest: &model.RoleManifest{InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
},
}

node, err := MakeValues(settings)

assert.NotNil(t, node)
assert.NoError(t, err)
node := MakeValues(settings)
require.NotNil(t, node)

auth := node.Get("kube").Get("auth")

Expand All @@ -139,23 +120,52 @@ func TestMakeValues(t *testing.T) {
t.Run("Check Custom Auth", func(t *testing.T) {
t.Parallel()
settings := ExportSettings{
OutputDir: outDir,
RoleManifest: &model.RoleManifest{InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
},
}

authString := "foo"

settings.AuthType = authString

node, err := MakeValues(settings)

assert.NotNil(t, node)
assert.NoError(t, err)
node := MakeValues(settings)
require.NotNil(t, node)

auth := node.Get("kube").Get("auth")

assert.Equal(t, auth.String(), authString)
})

t.Run("Ingress", func(t *testing.T) {
t.Parallel()

expected := `---

# ingress.annotations allows specifying custom ingress annotations that gets
# merged to the default annotations.
annotations: {}

# ingress.enabled enables ingress support - working ingress controller
# necessary.
enabled: false

# ingress.tls.crt and ingress.tls.key, when specified, are used by the TLS
# secret for the Ingress resource.
tls: {}
`

settings := ExportSettings{
RoleManifest: &model.RoleManifest{
InstanceGroups: model.InstanceGroups{},
Configuration: &model.Configuration{},
},
}
node := MakeValues(settings)
require.NotNil(t, node)
actual := node.Get("ingress").String()

assert.Exactly(t, expected, actual)
})
}