mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Error for null files while reading
This commit is contained in:
@@ -72,15 +72,8 @@ func (w ByteWriter) Write(nodes []*yaml.RNode) error {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(pwittrock): factor this into a a common module for pruning empty values
|
||||
_, err := nodes[i].Pipe(yaml.Lookup("metadata"), yaml.FieldClearer{
|
||||
Name: "annotations", IfEmpty: true})
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
_, err = nodes[i].Pipe(yaml.FieldClearer{Name: "metadata", IfEmpty: true})
|
||||
if err != nil {
|
||||
return errors.Wrap(err)
|
||||
if err := yaml.ClearEmptyAnnotations(nodes[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if w.Style != 0 {
|
||||
|
||||
@@ -71,6 +71,17 @@ g:
|
||||
- j
|
||||
`)
|
||||
|
||||
var readFileC = []byte(`---
|
||||
a: b #third
|
||||
metadata:
|
||||
annotations:
|
||||
`)
|
||||
|
||||
var readFileD = []byte(`---
|
||||
a: b #forth
|
||||
metadata:
|
||||
`)
|
||||
|
||||
var pkgFile = []byte(``)
|
||||
|
||||
func TestLocalPackageReader_Read_empty(t *testing.T) {
|
||||
@@ -87,6 +98,8 @@ func TestLocalPackageReader_Read_pkg(t *testing.T) {
|
||||
defer s.clean()
|
||||
s.writeFile(t, filepath.Join("a_test.yaml"), readFileA)
|
||||
s.writeFile(t, filepath.Join("b_test.yaml"), readFileB)
|
||||
s.writeFile(t, filepath.Join("c_test.yaml"), readFileC)
|
||||
s.writeFile(t, filepath.Join("d_test.yaml"), readFileD)
|
||||
|
||||
paths := []struct {
|
||||
path string
|
||||
@@ -101,7 +114,7 @@ func TestLocalPackageReader_Read_pkg(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if !assert.Len(t, nodes, 3) {
|
||||
if !assert.Len(t, nodes, 5) {
|
||||
return
|
||||
}
|
||||
expected := []string{
|
||||
@@ -127,6 +140,18 @@ metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'b_test.yaml'
|
||||
`,
|
||||
`a: b #third
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'c_test.yaml'
|
||||
`,
|
||||
`a: b #forth
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'd_test.yaml'
|
||||
`,
|
||||
}
|
||||
for i := range nodes {
|
||||
|
||||
Reference in New Issue
Block a user