From a158eeaaff15880447cff46e2ebd038d6092aeeb Mon Sep 17 00:00:00 2001 From: Phani Teja Marupaka Date: Thu, 28 May 2020 15:46:58 -0700 Subject: [PATCH] Suggested changes --- cmd/config/internal/commands/source.go | 2 +- kyaml/kio/byteio_reader.go | 6 +++--- kyaml/kio/pkgio_reader.go | 16 ++++------------ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/cmd/config/internal/commands/source.go b/cmd/config/internal/commands/source.go index 555e2d660..7873956ce 100644 --- a/cmd/config/internal/commands/source.go +++ b/cmd/config/internal/commands/source.go @@ -71,7 +71,7 @@ func (r *SourceRunner) runE(c *cobra.Command, args []string) error { var inputs []kio.Reader for _, a := range args { - inputs = append(inputs, kio.LocalPackageReader{PackagePath: a, IncludeJSON: true}) + inputs = append(inputs, kio.LocalPackageReader{PackagePath: a, MatchFilesGlob: kio.MatchAll}) } if len(inputs) == 0 { inputs = []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin()}} diff --git a/kyaml/kio/byteio_reader.go b/kyaml/kio/byteio_reader.go index 662f04437..c91ea5183 100644 --- a/kyaml/kio/byteio_reader.go +++ b/kyaml/kio/byteio_reader.go @@ -102,8 +102,8 @@ type ByteReader struct { // the read objects were originally wrapped in. WrappingKind string - // JSON indicates if the input file source is json - JSON bool + // Path indicates file path which is being read + Path string } var _ Reader = &ByteReader{} @@ -123,7 +123,7 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) { index := 0 for i := range values { value := values[i] - if r.JSON { + if strings.HasSuffix(r.Path, JSONSuffix) { value, err = yaml.ConvertJSONToYamlString(value) if err != nil { return nil, err diff --git a/kyaml/kio/pkgio_reader.go b/kyaml/kio/pkgio_reader.go index 0392949d6..17fc81fa8 100644 --- a/kyaml/kio/pkgio_reader.go +++ b/kyaml/kio/pkgio_reader.go @@ -7,7 +7,6 @@ import ( "fmt" "os" "path/filepath" - "strings" "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/kio/kioutil" @@ -163,19 +162,15 @@ 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" -) +const JSONSuffix = ".json" var DefaultMatch = []string{"*.yaml", "*.yml"} +var JSONMatch = []string{"*.json"} +var MatchAll = append(DefaultMatch, JSONMatch...) // Read reads the Resources. func (r LocalPackageReader) Read() ([]*yaml.RNode, error) { @@ -187,9 +182,6 @@ 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 @@ -255,7 +247,7 @@ func (r *LocalPackageReader) readFile(path string, _ os.FileInfo) ([]*yaml.RNode Reader: f, OmitReaderAnnotations: r.OmitReaderAnnotations, SetAnnotations: r.SetAnnotations, - JSON: strings.HasSuffix(path, JSONSuffix), + Path: path, } return rr.Read() }