diff --git a/fn.go b/fn.go index e5a8afb..2393578 100644 --- a/fn.go +++ b/fn.go @@ -57,7 +57,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ return rsp, nil } - tmpl, err := GetNewTemplateWithFunctionMaps().Parse(tg.GetTemplates()) + tmpl, err := GetNewTemplateWithFunctionMaps(in).Parse(tg.GetTemplates()) if err != nil { response.Fatal(rsp, errors.Wrap(err, "invalid function input: cannot parse the provided templates")) return rsp, nil diff --git a/function_maps.go b/function_maps.go index 1243ef5..f5f1a6c 100644 --- a/function_maps.go +++ b/function_maps.go @@ -6,6 +6,7 @@ import ( "time" sprig "github.com/Masterminds/sprig/v3" + "github.com/crossplane-contrib/function-go-templating/input/v1beta1" ) var funcMaps = []template.FuncMap{ @@ -18,8 +19,14 @@ var funcMaps = []template.FuncMap{ }, } -func GetNewTemplateWithFunctionMaps() *template.Template { - tpl := template.New("manifests") +func GetNewTemplateWithFunctionMaps(in *v1beta1.GoTemplate) *template.Template { + if in.LeftDelims == "" { + in.LeftDelims = "{{" + } + if in.RightDelims == "" { + in.RightDelims = "}}" + } + tpl := template.New("manifests").Delims(in.LeftDelims, in.RightDelims) for _, f := range funcMaps { tpl.Funcs(f) diff --git a/input/v1beta1/input.go b/input/v1beta1/input.go index 853d26d..d335fed 100644 --- a/input/v1beta1/input.go +++ b/input/v1beta1/input.go @@ -19,6 +19,10 @@ type GoTemplate struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` + // Template start characters + LeftDelims string `json:"leftDelims,omitempty"` + // Template end characters + RightDelims string `json:"rightDelims,omitempty"` // Source specifies the different types of input sources that can be used with this function Source TemplateSource `json:"source"` // Inline is the inline form input of the templates diff --git a/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml b/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml index 7e449c8..215395f 100644 --- a/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml +++ b/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml @@ -43,8 +43,14 @@ spec: object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string + leftDelims: + description: Template start characters + type: string metadata: type: object + rightDelims: + description: Template end characters + type: string source: description: Source specifies the different types of input sources that can be used with this function