Suggested changes

This commit is contained in:
Phani Teja Marupaka
2020-05-28 15:46:58 -07:00
parent 4cd3944860
commit a158eeaaff
3 changed files with 8 additions and 16 deletions

View File

@@ -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()}}

View File

@@ -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

View File

@@ -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()
}