Skip to content

Commit

Permalink
Merge pull request #59 from ezgidemirel/cp-skip-hidden
Browse files Browse the repository at this point in the history
Chery pick of "skip hidden dirs for FileSource"
  • Loading branch information
ezgidemirel authored Jan 16, 2024
2 parents 3207722 + 54e9de6 commit a57f1fd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
12 changes: 11 additions & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions testdata/templates/..shouldBeSkipped/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "common-labels" -}}
testLabel: "testValue"
{{- end }}
23 changes: 23 additions & 0 deletions testdata/templates/..shouldBeSkipped/resource.yaml
Original file line number Diff line number Diff line change
@@ -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: []

0 comments on commit a57f1fd

Please sign in to comment.