Skip to content

Commit

Permalink
Do not error for empty matches (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed Aug 24, 2021
1 parent 2e6ded1 commit 1356105
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
3 changes: 0 additions & 3 deletions functions/go/apply-setters/applysetters/apply_setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ type Result struct {

// Filter implements Set as a yaml.Filter
func (as *ApplySetters) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
if len(as.Setters) == 0 {
return nodes, fmt.Errorf("input setters list cannot be empty")
}
for i := range nodes {
filePath, _, err := kioutil.GetFileAnnotations(nodes[i])
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ spec:
`,
},
{
name: "error: no input",
name: "do not error if no input",
config: `
data: {}
`,
Expand Down Expand Up @@ -366,7 +366,6 @@ spec:
- name: nginx
image: nginx:1.7.9 # kpt-set: ${image}:${tag}
`,
errMsg: `input setters list cannot be empty`,
},
{
name: "set empty values",
Expand Down
5 changes: 4 additions & 1 deletion functions/go/apply-setters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func getSetters(fc *kyaml.RNode) (applysetters.ApplySetters, error) {
func resultsToItems(sr applysetters.ApplySetters) ([]framework.ResultItem, error) {
var items []framework.ResultItem
if len(sr.Results) == 0 {
return nil, fmt.Errorf("no matches for the input list of setters")
items = append(items, framework.ResultItem{
Message: "no matches for input setter(s)",
})
return items, nil
}
for _, res := range sr.Results {
items = append(items, framework.ResultItem{
Expand Down
2 changes: 1 addition & 1 deletion tests/apply-setters/no-matches-error/.expected/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
runCount: 2
exitCode: 1
exitCode: 0
9 changes: 3 additions & 6 deletions tests/apply-setters/no-matches-error/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ apiVersion: kpt.dev/v1
kind: FunctionResultList
metadata:
name: fnresults
exitCode: 1
exitCode: 0
items:
- image: gcr.io/kpt-fn/apply-setters:unstable
stderr: |
no matches for the input list of settersno matches for the input list of setters
exitCode: 1
exitCode: 0
results:
- message: 'failed to apply setters: no matches for the input list of setters'
severity: error
- message: no matches for input setter(s)

0 comments on commit 1356105

Please sign in to comment.