diff --git a/pkg/scaffold/template/gotpl.go b/pkg/scaffold/template/gotpl.go index 0c01dfd8b..3b7ba35ca 100644 --- a/pkg/scaffold/template/gotpl.go +++ b/pkg/scaffold/template/gotpl.go @@ -4,9 +4,10 @@ import ( "bytes" "github.com/imdario/mergo" + "gopkg.in/yaml.v2" + "github.com/pluralsh/plural/pkg/template" "github.com/pluralsh/plural/pkg/utils" - "gopkg.in/yaml.v2" ) func FromGoTemplate(vals map[string]interface{}, globals map[string]interface{}, output map[string]map[string]interface{}, chartName, tplate string) error { @@ -26,7 +27,10 @@ func FromGoTemplate(vals map[string]interface{}, globals map[string]interface{}, if err := yaml.Unmarshal(buf.Bytes(), &subVals); err != nil { return err } - subVals["enabled"] = true + + if _, exists := subVals["enabled"]; !exists { + subVals["enabled"] = true + } // need to handle globals in a dedicated way if glob, ok := subVals["global"]; ok { diff --git a/pkg/scaffold/template/lua.go b/pkg/scaffold/template/lua.go index 92e495f53..3e5359c38 100644 --- a/pkg/scaffold/template/lua.go +++ b/pkg/scaffold/template/lua.go @@ -5,10 +5,11 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/imdario/mergo" - "github.com/pluralsh/plural/pkg/template" - "github.com/pluralsh/plural/pkg/utils" lua "github.com/yuin/gopher-lua" luar "layeh.com/gopher-luar" + + "github.com/pluralsh/plural/pkg/template" + "github.com/pluralsh/plural/pkg/utils" ) func ExecuteLua(vals map[string]interface{}, tplate string) (map[string]interface{}, error) { @@ -41,11 +42,15 @@ func ExecuteLua(vals map[string]interface{}, tplate string) (map[string]interfac } func FromLuaTemplate(vals map[string]interface{}, globals map[string]interface{}, output map[string]map[string]interface{}, chartName, tplate string) error { + var subVals map[string]interface{} subVals, err := ExecuteLua(vals, tplate) if err != nil { return err } - subVals["enabled"] = true + + if _, exists := subVals["enabled"]; !exists { + subVals["enabled"] = true + } // need to handle globals in a dedicated way if glob, ok := subVals["global"]; ok { diff --git a/pkg/scaffold/template/lua_test.go b/pkg/scaffold/template/lua_test.go index 3739ff618..95b8ebba8 100644 --- a/pkg/scaffold/template/lua_test.go +++ b/pkg/scaffold/template/lua_test.go @@ -5,12 +5,13 @@ import ( "path" "testing" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v2" + "github.com/pluralsh/plural/pkg/config" "github.com/pluralsh/plural/pkg/scaffold/template" pluraltest "github.com/pluralsh/plural/pkg/test" "github.com/pluralsh/plural/pkg/utils/git" - "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v2" ) func TestFromLuaTemplateComplex(t *testing.T) { @@ -417,6 +418,41 @@ test: CYPRESS_BASE_URL: https://console.onplural.sh/ CYPRESS_EMAIL: test@plural.sh CYPRESS_PASSWORD: xyz +`, + }, + { + name: `test enabled flag set to false`, + vals: map[string]interface{}{ + "enabled": false, + }, + script: `output={ + enabled=Var.enabled + }`, + expectedResponse: `global: {} +test: + enabled: false +`, + }, + { + name: `test enabled flag defaulting`, + vals: map[string]interface{}{}, + script: `output={}`, + expectedResponse: `global: {} +test: + enabled: true +`, + }, + { + name: `test enabled flag set to true`, + vals: map[string]interface{}{ + "enabled": true, + }, + script: `output={ + enabled=Var.enabled + }`, + expectedResponse: `global: {} +test: + enabled: true `, }, }