diff --git a/example/custom-delims/composition.yaml b/example/custom-delims/composition.yaml index 715e2f4..c60dd55 100644 --- a/example/custom-delims/composition.yaml +++ b/example/custom-delims/composition.yaml @@ -14,10 +14,9 @@ spec: input: apiVersion: gotemplating.fn.crossplane.io/v1beta1 kind: GoTemplate - config: - delims: - left: '[[' - right: ']]' + delims: + left: '[[' + right: ']]' source: Inline inline: template: | diff --git a/fn.go b/fn.go index 2cb8b8e..31d2f33 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(in.Config).Parse(tg.GetTemplates()) + tmpl, err := GetNewTemplateWithFunctionMaps(in.Delims).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 fe7a9d5..2533880 100644 --- a/function_maps.go +++ b/function_maps.go @@ -48,14 +48,12 @@ var funcMaps = []template.FuncMap{ }, } -func GetNewTemplateWithFunctionMaps(cfg *v1beta1.Config) *template.Template { +func GetNewTemplateWithFunctionMaps(delims *v1beta1.Delims) *template.Template { tpl := template.New("manifests") - if cfg != nil { - if cfg.Delims != nil { - if cfg.Delims.Left != nil && cfg.Delims.Right != nil { - tpl = tpl.Delims(*cfg.Delims.Left, *cfg.Delims.Right) - } + if delims != nil { + if delims.Left != nil && delims.Right != nil { + tpl = tpl.Delims(*delims.Left, *delims.Right) } } diff --git a/input/v1beta1/input.go b/input/v1beta1/input.go index 71490c0..77f88fa 100644 --- a/input/v1beta1/input.go +++ b/input/v1beta1/input.go @@ -18,9 +18,9 @@ import ( type GoTemplate struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - // Go Template Config + // Template delimiters // +optional - Config *Config `json:"config,omitempty"` + Delims *Delims `json:"delims,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 @@ -47,12 +47,6 @@ type TemplateSourceFileSystem struct { DirPath string `json:"dirPath,omitempty"` } -type Config struct { - // Template delimiters - // +optional - Delims *Delims `json:"delims,omitempty"` -} - type Delims struct { // Template start characters // +kubebuilder:default:="{{" diff --git a/input/v1beta1/zz_generated.deepcopy.go b/input/v1beta1/zz_generated.deepcopy.go index 948384e..443d5cc 100644 --- a/input/v1beta1/zz_generated.deepcopy.go +++ b/input/v1beta1/zz_generated.deepcopy.go @@ -8,26 +8,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Config) DeepCopyInto(out *Config) { - *out = *in - if in.Delims != nil { - in, out := &in.Delims, &out.Delims - *out = new(Delims) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. -func (in *Config) DeepCopy() *Config { - if in == nil { - return nil - } - out := new(Config) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Delims) DeepCopyInto(out *Delims) { *out = *in @@ -58,9 +38,9 @@ func (in *GoTemplate) DeepCopyInto(out *GoTemplate) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - if in.Config != nil { - in, out := &in.Config, &out.Config - *out = new(Config) + if in.Delims != nil { + in, out := &in.Delims, &out.Delims + *out = new(Delims) (*in).DeepCopyInto(*out) } if in.Inline != nil { diff --git a/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml b/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml index 367202f..28abe44 100644 --- a/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml +++ b/package/input/gotemplating.fn.crossplane.io_gotemplates.yaml @@ -26,21 +26,17 @@ spec: of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string - config: - description: Go Template Config + delims: + description: Template delimiters properties: - delims: - description: Template delimiters - properties: - left: - default: '{{' - description: Template start characters - type: string - right: - default: '}}' - description: Template end characters - type: string - type: object + left: + default: '{{' + description: Template start characters + type: string + right: + default: '}}' + description: Template end characters + type: string type: object fileSystem: description: FileSystem is the folder path where the templates are located