diff --git a/fn.go b/fn.go index 31d2f33..6400124 100644 --- a/fn.go +++ b/fn.go @@ -57,6 +57,8 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ return rsp, nil } + f.log.Debug("template", "template", 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")) diff --git a/template.go b/template.go index 990741b..ccfa4c1 100644 --- a/template.go +++ b/template.go @@ -83,11 +83,21 @@ func newFileSource(in *v1beta1.GoTemplate) (*FileSource, error) { func readTemplates(dir string) (string, error) { tmpl := "" - if err := filepath.Walk(dir, func(path string, info os.FileInfo, e error) error { + if err := filepath.WalkDir(dir, func(path string, dirEntry os.DirEntry, e error) error { if e != nil { return e } + // skip hidden directories + if dirEntry.IsDir() && dirEntry.Name()[0] == dotCharacter { + return filepath.SkipDir + } + + info, err := dirEntry.Info() + if err != nil { + return err + } + // check for directory and hidden files/folders if info.IsDir() || info.Name()[0] == dotCharacter { return nil diff --git a/testdata/templates/..shouldBeSkipped/_helpers.tpl b/testdata/templates/..shouldBeSkipped/_helpers.tpl new file mode 100644 index 0000000..765d3f5 --- /dev/null +++ b/testdata/templates/..shouldBeSkipped/_helpers.tpl @@ -0,0 +1,3 @@ +{{- define "common-labels" -}} +testLabel: "testValue" +{{- end }} \ No newline at end of file diff --git a/testdata/templates/..shouldBeSkipped/resource.yaml b/testdata/templates/..shouldBeSkipped/resource.yaml new file mode 100644 index 0000000..bbe31ab --- /dev/null +++ b/testdata/templates/..shouldBeSkipped/resource.yaml @@ -0,0 +1,23 @@ +apiVersion: kubernetes.crossplane.io/v1alpha1 +kind: Object +metadata: + annotations: + gotemplating.fn.crossplane.io/composition-resource-name: test + labels: + {{- include "common-labels" . | nindent 4}} +spec: + providerConfigRef: + name: default + forProvider: + manifest: + apiVersion: v1 + kind: ConfigMap + metadata: + name: test-001 + namespace: test + labels: + {{- include "common-labels" . | nindent 10}} + data: + test: | + spec: + resources: [] \ No newline at end of file