mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
fix error message
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"errors"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
@@ -117,6 +119,14 @@ func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelect
|
|||||||
var t *yaml.RNode
|
var t *yaml.RNode
|
||||||
var err error
|
var err error
|
||||||
if target.Options != nil && target.Options.Create {
|
if target.Options != nil && target.Options.Create {
|
||||||
|
// create option is not supported in a wildcard matching.
|
||||||
|
// Because, PathMatcher is not supported create option.
|
||||||
|
// So, if create option is set, we fallback to PathGetter.
|
||||||
|
for _, f := range fieldPath {
|
||||||
|
if f == "*" {
|
||||||
|
return errors.New("cannot support create option in a multi-value target")
|
||||||
|
}
|
||||||
|
}
|
||||||
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
|
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
|
||||||
} else {
|
} else {
|
||||||
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath})
|
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath})
|
||||||
|
|||||||
@@ -1671,7 +1671,7 @@ spec:
|
|||||||
options:
|
options:
|
||||||
create: true
|
create: true
|
||||||
`,
|
`,
|
||||||
expectedErr: "cannot support create option in a multi-value target now",
|
expectedErr: "cannot support create option in a multi-value target",
|
||||||
},
|
},
|
||||||
"multiple field paths in target": {
|
"multiple field paths in target": {
|
||||||
input: `apiVersion: v1
|
input: `apiVersion: v1
|
||||||
|
|||||||
@@ -542,8 +542,8 @@ func (l PathGetter) getFilter(part, nextPart string, fieldPath *[]string) (Filte
|
|||||||
// part is a hyphen
|
// part is a hyphen
|
||||||
return GetElementByIndex(-1), nil
|
return GetElementByIndex(-1), nil
|
||||||
case part == "*":
|
case part == "*":
|
||||||
// part is a asterisk
|
// PathGetter is not support for wildcard matching
|
||||||
return nil, errors.Errorf("cannot support create option in a multi-value target now")
|
return nil, errors.Errorf("wildcard is not supported in PathGetter")
|
||||||
case IsListIndex(part):
|
case IsListIndex(part):
|
||||||
// part is surrounded by brackets
|
// part is surrounded by brackets
|
||||||
return l.elemFilter(part)
|
return l.elemFilter(part)
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ func TestLookup_Fn_create_with_wildcard_error(t *testing.T) {
|
|||||||
node, err := Parse(s)
|
node, err := Parse(s)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = node.Pipe(LookupCreate(yaml.MappingNode, "a", "b", "*", "t"))
|
_, err = node.Pipe(LookupCreate(yaml.MappingNode, "a", "b", "*", "t"))
|
||||||
assert.Error(t, err, "cannot support create option in a multi-value target now")
|
assert.Error(t, err, "wildcard is not supported in PathGetter")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLookup(t *testing.T) {
|
func TestLookup(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user