mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Merge pull request #2864 from Shell32-Natsu/fn-source-empty-dir
add option to continue pipeline when the input is empty
This commit is contained in:
@@ -99,10 +99,6 @@ func (p Pipeline) ExecuteWithCallback(callback PipelineExecuteCallbackFunc) erro
|
||||
}
|
||||
result = append(result, nodes...)
|
||||
}
|
||||
if len(result) == 0 {
|
||||
// no inputs to operate on
|
||||
return nil
|
||||
}
|
||||
|
||||
// apply operations
|
||||
var err error
|
||||
@@ -112,6 +108,9 @@ func (p Pipeline) ExecuteWithCallback(callback PipelineExecuteCallbackFunc) erro
|
||||
callback(op)
|
||||
}
|
||||
result, err = op.Filter(result)
|
||||
// TODO (issue 2872): This len(result) == 0 should be removed and empty result list should be
|
||||
// handled by outputs. However currently some writer like LocalPackageReadWriter
|
||||
// will clear the output directory and which will cause unpredictable results
|
||||
if len(result) == 0 || err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
package kio_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -75,3 +77,75 @@ func TestPipelineWithCallback(t *testing.T) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyInput(t *testing.T) {
|
||||
actual := &bytes.Buffer{}
|
||||
output := ByteWriter{
|
||||
Sort: true,
|
||||
WrappingKind: ResourceListKind,
|
||||
WrappingAPIVersion: ResourceListAPIVersion,
|
||||
}
|
||||
output.Writer = actual
|
||||
|
||||
p := Pipeline{
|
||||
Outputs: []Writer{output},
|
||||
}
|
||||
|
||||
err := p.Execute()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := `
|
||||
apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items: []
|
||||
`
|
||||
|
||||
if !assert.Equal(t,
|
||||
strings.TrimSpace(expected), strings.TrimSpace(actual.String())) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyInputWithFilter(t *testing.T) {
|
||||
actual := &bytes.Buffer{}
|
||||
output := ByteWriter{
|
||||
Sort: true,
|
||||
WrappingKind: ResourceListKind,
|
||||
WrappingAPIVersion: ResourceListAPIVersion,
|
||||
}
|
||||
output.Writer = actual
|
||||
|
||||
filters := []Filter{
|
||||
FilterFunc(func(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
nodes = append(nodes, yaml.NewMapRNode(&map[string]string{
|
||||
"foo": "bar",
|
||||
}))
|
||||
return nodes, nil
|
||||
}),
|
||||
FilterFunc(func(nodes []*yaml.RNode) ([]*yaml.RNode, error) { return nodes, nil }),
|
||||
}
|
||||
|
||||
p := Pipeline{
|
||||
Outputs: []Writer{output},
|
||||
Filters: filters,
|
||||
}
|
||||
|
||||
err := p.Execute()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := `
|
||||
apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- foo: bar
|
||||
`
|
||||
|
||||
if !assert.Equal(t,
|
||||
strings.TrimSpace(expected), strings.TrimSpace(actual.String())) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user