mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
rename IsMatchEveryIndex to IsWildcard
This commit is contained in:
@@ -119,7 +119,6 @@ func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelect
|
||||
if target.Options != nil && target.Options.Create {
|
||||
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
|
||||
} else {
|
||||
// t, err = node.Pipe(yaml.Lookup(fieldPath...))
|
||||
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath})
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -1431,6 +1431,78 @@ spec:
|
||||
name: second
|
||||
version: latest
|
||||
property: second`,
|
||||
},
|
||||
"one replacements target has multiple value": {
|
||||
input: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: sample-deploy
|
||||
name: sample-deploy
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: sample-deploy
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: sample-deploy
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: main
|
||||
env:
|
||||
- name: deployment-name
|
||||
value: XXXXX
|
||||
- name: foo
|
||||
value: bar
|
||||
- image: nginx
|
||||
name: sidecar
|
||||
env:
|
||||
- name: deployment-name
|
||||
value: YYYYY
|
||||
`,
|
||||
replacements: `replacements:
|
||||
- source:
|
||||
kind: Deployment
|
||||
name: sample-deploy
|
||||
fieldPath: metadata.name
|
||||
targets:
|
||||
- select:
|
||||
kind: Deployment
|
||||
fieldPaths:
|
||||
- spec.template.spec.containers.[image=nginx].env.[name=deployment-name].value
|
||||
`,
|
||||
expected: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: sample-deploy
|
||||
name: sample-deploy
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: sample-deploy
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: sample-deploy
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: main
|
||||
env:
|
||||
- name: deployment-name
|
||||
value: sample-deploy
|
||||
- name: foo
|
||||
value: bar
|
||||
- image: nginx
|
||||
name: sidecar
|
||||
env:
|
||||
- name: deployment-name
|
||||
value: sample-deploy`,
|
||||
},
|
||||
"index contains '*' character": {
|
||||
input: `apiVersion: apps/v1
|
||||
|
||||
@@ -789,6 +789,12 @@ func IsIdxNumber(p string) bool {
|
||||
return err == nil && idx >= 0
|
||||
}
|
||||
|
||||
// IsWildcard returns true if p is matching every elements.
|
||||
// e.g. "*"
|
||||
func IsWildcard(p string) bool {
|
||||
return p == "*"
|
||||
}
|
||||
|
||||
// SplitIndexNameValue splits a lookup part Val index into the field name
|
||||
// and field value to match.
|
||||
// e.g. splits [name=nginx] into (name, nginx)
|
||||
@@ -803,12 +809,6 @@ func SplitIndexNameValue(p string) (string, string, error) {
|
||||
return parts[0], parts[1], nil
|
||||
}
|
||||
|
||||
// IsMatchEveryIndex returns true if p is matching every elements.
|
||||
// e.g. "*"
|
||||
func IsMatchEveryIndex(p string) bool {
|
||||
return p == "*"
|
||||
}
|
||||
|
||||
// IncrementFieldIndex increments i to point to the next field name element in
|
||||
// a slice of Contents.
|
||||
func IncrementFieldIndex(i int) int {
|
||||
|
||||
@@ -90,7 +90,7 @@ func (p *PathMatcher) filter(rn *RNode) (*RNode, error) {
|
||||
return p.doSeq(rn)
|
||||
}
|
||||
|
||||
if IsMatchEveryIndex(p.Path[0]) {
|
||||
if IsWildcard(p.Path[0]) {
|
||||
// match every elements (*)
|
||||
return p.doMatchEvery(rn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user