Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Chubatiuk committed Nov 16, 2023
1 parent 21ea76e commit 0bc1c01
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 56 deletions.
7 changes: 3 additions & 4 deletions example/custom-delims/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions function_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 2 additions & 8 deletions input/v1beta1/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:="{{"
Expand Down
26 changes: 3 additions & 23 deletions input/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions package/input/gotemplating.fn.crossplane.io_gotemplates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bc1c01

Please sign in to comment.