mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 18:10:59 +00:00
Suggested changes
This commit is contained in:
@@ -71,7 +71,7 @@ func (r *SourceRunner) runE(c *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
var inputs []kio.Reader
|
var inputs []kio.Reader
|
||||||
for _, a := range args {
|
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 {
|
if len(inputs) == 0 {
|
||||||
inputs = []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin()}}
|
inputs = []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin()}}
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ type ByteReader struct {
|
|||||||
// the read objects were originally wrapped in.
|
// the read objects were originally wrapped in.
|
||||||
WrappingKind string
|
WrappingKind string
|
||||||
|
|
||||||
// JSON indicates if the input file source is json
|
// Path indicates file path which is being read
|
||||||
JSON bool
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Reader = &ByteReader{}
|
var _ Reader = &ByteReader{}
|
||||||
@@ -123,7 +123,7 @@ func (r *ByteReader) Read() ([]*yaml.RNode, error) {
|
|||||||
index := 0
|
index := 0
|
||||||
for i := range values {
|
for i := range values {
|
||||||
value := values[i]
|
value := values[i]
|
||||||
if r.JSON {
|
if strings.HasSuffix(r.Path, JSONSuffix) {
|
||||||
value, err = yaml.ConvertJSONToYamlString(value)
|
value, err = yaml.ConvertJSONToYamlString(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
|
"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 are annotations to set on the Resources as they are read.
|
||||||
SetAnnotations map[string]string `yaml:"setAnnotations,omitempty"`
|
SetAnnotations map[string]string `yaml:"setAnnotations,omitempty"`
|
||||||
|
|
||||||
// IncludeJSON indicates if the json resources files must be included during read
|
|
||||||
IncludeJSON bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Reader = LocalPackageReader{}
|
var _ Reader = LocalPackageReader{}
|
||||||
|
|
||||||
const (
|
const JSONSuffix = ".json"
|
||||||
JSONFilePattern = "*.json"
|
|
||||||
JSONSuffix = ".json"
|
|
||||||
)
|
|
||||||
|
|
||||||
var DefaultMatch = []string{"*.yaml", "*.yml"}
|
var DefaultMatch = []string{"*.yaml", "*.yml"}
|
||||||
|
var JSONMatch = []string{"*.json"}
|
||||||
|
var MatchAll = append(DefaultMatch, JSONMatch...)
|
||||||
|
|
||||||
// Read reads the Resources.
|
// Read reads the Resources.
|
||||||
func (r LocalPackageReader) Read() ([]*yaml.RNode, error) {
|
func (r LocalPackageReader) Read() ([]*yaml.RNode, error) {
|
||||||
@@ -187,9 +182,6 @@ func (r LocalPackageReader) Read() ([]*yaml.RNode, error) {
|
|||||||
r.PackagePath = filepath.ToSlash(r.PackagePath)
|
r.PackagePath = filepath.ToSlash(r.PackagePath)
|
||||||
if len(r.MatchFilesGlob) == 0 {
|
if len(r.MatchFilesGlob) == 0 {
|
||||||
r.MatchFilesGlob = DefaultMatch
|
r.MatchFilesGlob = DefaultMatch
|
||||||
if r.IncludeJSON {
|
|
||||||
r.MatchFilesGlob = append(r.MatchFilesGlob, JSONFilePattern)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var operand ResourceNodeSlice
|
var operand ResourceNodeSlice
|
||||||
@@ -255,7 +247,7 @@ func (r *LocalPackageReader) readFile(path string, _ os.FileInfo) ([]*yaml.RNode
|
|||||||
Reader: f,
|
Reader: f,
|
||||||
OmitReaderAnnotations: r.OmitReaderAnnotations,
|
OmitReaderAnnotations: r.OmitReaderAnnotations,
|
||||||
SetAnnotations: r.SetAnnotations,
|
SetAnnotations: r.SetAnnotations,
|
||||||
JSON: strings.HasSuffix(path, JSONSuffix),
|
Path: path,
|
||||||
}
|
}
|
||||||
return rr.Read()
|
return rr.Read()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user