diff --git a/provisioner/template.go b/provisioner/template.go index 061568ca..96975387 100644 --- a/provisioner/template.go +++ b/provisioner/template.go @@ -131,6 +131,7 @@ func renderTemplate(context *templateContext, file string) (string, error) { "indent": sprig.GenericFuncMap()["indent"], "dict": dict, "list": list, + "append": strAppend, "scaleQuantity": scaleQuantity, "instanceTypeCPUQuantity": func(instanceType string) (string, error) { return instanceTypeCPUQuantity(context, instanceType) @@ -283,6 +284,10 @@ func list(args ...interface{}) []interface{} { return args } +func strAppend(list []string, items ...string) []string { + return append(list, items...) +} + func eksID(id string) string { parts := strings.Split(id, ":") return parts[len(parts)-1] diff --git a/provisioner/template_test.go b/provisioner/template_test.go index d67b5ed5..69d76ef7 100644 --- a/provisioner/template_test.go +++ b/provisioner/template_test.go @@ -1309,6 +1309,40 @@ func TestJoin(t *testing.T) { } } +func TestStrAppend(t *testing.T) { + for _, tc := range []struct { + name string + template string + data interface{} + expected string + }{ + { + name: "append to list", + template: `{{ append .Values.data.items .Values.data.item }}`, + data: map[string]interface{}{ + "items": []string{"a", "b"}, + "item": "c", + }, + expected: "[a b c]", + }, { + name: "append multiple items to list", + template: `{{ append .Values.data.items .Values.data.item .Values.data.item2 }}`, + data: map[string]interface{}{ + "items": []string{"a", "b"}, + "item": "c", + "item2": "d", + }, + expected: "[a b c d]", + }, + } { + t.Run(tc.name, func(t *testing.T) { + res, err := renderSingle(t, tc.template, tc.data) + require.NoError(t, err) + require.Equal(t, tc.expected, res) + }) + } +} + func TestScaleQuantity(t *testing.T) { for _, tc := range []struct { name string