mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
add option to continue pipeline when the input is empty
This commit is contained in:
@@ -77,6 +77,6 @@ func (r *SourceRunner) runE(c *cobra.Command, args []string) error {
|
||||
inputs = []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin()}}
|
||||
}
|
||||
|
||||
err := kio.Pipeline{Inputs: inputs, Outputs: outputs}.Execute()
|
||||
err := kio.Pipeline{Inputs: inputs, Outputs: outputs, ContinueIfInputEmpty: true}.Execute()
|
||||
return handleError(c, err)
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ type Pipeline struct {
|
||||
|
||||
// Outputs are where the transformed Resource Configuration is written.
|
||||
Outputs []Writer `yaml:"outputs,omitempty"`
|
||||
|
||||
// ContinueIfInputEmpty indicates should pipeline continue when the
|
||||
// the input result is empty. This is useful when we want to run outputs
|
||||
// even the input is empty.
|
||||
ContinueIfInputEmpty bool
|
||||
}
|
||||
|
||||
// Execute executes each step in the sequence, returning immediately after encountering
|
||||
@@ -99,7 +104,7 @@ func (p Pipeline) ExecuteWithCallback(callback PipelineExecuteCallbackFunc) erro
|
||||
}
|
||||
result = append(result, nodes...)
|
||||
}
|
||||
if len(result) == 0 {
|
||||
if len(result) == 0 && !p.ContinueIfInputEmpty {
|
||||
// no inputs to operate on
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
package kio_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -75,3 +77,34 @@ func TestPipelineWithCallback(t *testing.T) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContinueIfInputEmpty(t *testing.T) {
|
||||
actual := &bytes.Buffer{}
|
||||
output := ByteWriter{
|
||||
Sort: true,
|
||||
WrappingKind: ResourceListKind,
|
||||
WrappingAPIVersion: ResourceListAPIVersion,
|
||||
}
|
||||
output.Writer = actual
|
||||
|
||||
p := Pipeline{
|
||||
Outputs: []Writer{output},
|
||||
ContinueIfInputEmpty: true,
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user