Include json files for fn source

This commit is contained in:
Phani Teja Marupaka
2020-05-27 17:45:15 -07:00
parent fb6830c98a
commit 4cd3944860
6 changed files with 93 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
@@ -162,10 +163,18 @@ type LocalPackageReader struct {
// SetAnnotations are annotations to set on the Resources as they are read.
SetAnnotations map[string]string `yaml:"setAnnotations,omitempty"`
// IncludeJSON indicates if the json resources files must be included during read
IncludeJSON bool
}
var _ Reader = LocalPackageReader{}
const (
JSONFilePattern = "*.json"
JSONSuffix = ".json"
)
var DefaultMatch = []string{"*.yaml", "*.yml"}
// Read reads the Resources.
@@ -178,6 +187,9 @@ func (r LocalPackageReader) Read() ([]*yaml.RNode, error) {
r.PackagePath = filepath.ToSlash(r.PackagePath)
if len(r.MatchFilesGlob) == 0 {
r.MatchFilesGlob = DefaultMatch
if r.IncludeJSON {
r.MatchFilesGlob = append(r.MatchFilesGlob, JSONFilePattern)
}
}
var operand ResourceNodeSlice
@@ -243,6 +255,7 @@ func (r *LocalPackageReader) readFile(path string, _ os.FileInfo) ([]*yaml.RNode
Reader: f,
OmitReaderAnnotations: r.OmitReaderAnnotations,
SetAnnotations: r.SetAnnotations,
JSON: strings.HasSuffix(path, JSONSuffix),
}
return rr.Read()
}