Skip to content

Commit 5ed96a3

Browse files
committed
rename IsMatchEveryIndex to IsWildcard
1 parent 22f9daa commit 5ed96a3

File tree

4 files changed

+79
-8
lines changed

4 files changed

+79
-8
lines changed

api/filters/replacement/replacement.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelect
119119
if target.Options != nil && target.Options.Create {
120120
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
121121
} else {
122-
// t, err = node.Pipe(yaml.Lookup(fieldPath...))
123122
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath})
124123
}
125124
if err != nil {

api/filters/replacement/replacement_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,78 @@ spec:
14311431
name: second
14321432
version: latest
14331433
property: second`,
1434+
},
1435+
"one replacements target has multiple value": {
1436+
input: `apiVersion: apps/v1
1437+
kind: Deployment
1438+
metadata:
1439+
labels:
1440+
app: sample-deploy
1441+
name: sample-deploy
1442+
spec:
1443+
replicas: 1
1444+
selector:
1445+
matchLabels:
1446+
app: sample-deploy
1447+
template:
1448+
metadata:
1449+
labels:
1450+
app: sample-deploy
1451+
spec:
1452+
containers:
1453+
- image: nginx
1454+
name: main
1455+
env:
1456+
- name: deployment-name
1457+
value: XXXXX
1458+
- name: foo
1459+
value: bar
1460+
- image: nginx
1461+
name: sidecar
1462+
env:
1463+
- name: deployment-name
1464+
value: YYYYY
1465+
`,
1466+
replacements: `replacements:
1467+
- source:
1468+
kind: Deployment
1469+
name: sample-deploy
1470+
fieldPath: metadata.name
1471+
targets:
1472+
- select:
1473+
kind: Deployment
1474+
fieldPaths:
1475+
- spec.template.spec.containers.[image=nginx].env.[name=deployment-name].value
1476+
`,
1477+
expected: `apiVersion: apps/v1
1478+
kind: Deployment
1479+
metadata:
1480+
labels:
1481+
app: sample-deploy
1482+
name: sample-deploy
1483+
spec:
1484+
replicas: 1
1485+
selector:
1486+
matchLabels:
1487+
app: sample-deploy
1488+
template:
1489+
metadata:
1490+
labels:
1491+
app: sample-deploy
1492+
spec:
1493+
containers:
1494+
- image: nginx
1495+
name: main
1496+
env:
1497+
- name: deployment-name
1498+
value: sample-deploy
1499+
- name: foo
1500+
value: bar
1501+
- image: nginx
1502+
name: sidecar
1503+
env:
1504+
- name: deployment-name
1505+
value: sample-deploy`,
14341506
},
14351507
"index contains '*' character": {
14361508
input: `apiVersion: apps/v1

kyaml/yaml/fns.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ func IsIdxNumber(p string) bool {
789789
return err == nil && idx >= 0
790790
}
791791

792+
// IsWildcard returns true if p is matching every elements.
793+
// e.g. "*"
794+
func IsWildcard(p string) bool {
795+
return p == "*"
796+
}
797+
792798
// SplitIndexNameValue splits a lookup part Val index into the field name
793799
// and field value to match.
794800
// e.g. splits [name=nginx] into (name, nginx)
@@ -803,12 +809,6 @@ func SplitIndexNameValue(p string) (string, string, error) {
803809
return parts[0], parts[1], nil
804810
}
805811

806-
// IsMatchEveryIndex returns true if p is matching every elements.
807-
// e.g. "*"
808-
func IsMatchEveryIndex(p string) bool {
809-
return p == "*"
810-
}
811-
812812
// IncrementFieldIndex increments i to point to the next field name element in
813813
// a slice of Contents.
814814
func IncrementFieldIndex(i int) int {

kyaml/yaml/match.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (p *PathMatcher) filter(rn *RNode) (*RNode, error) {
9090
return p.doSeq(rn)
9191
}
9292

93-
if IsMatchEveryIndex(p.Path[0]) {
93+
if IsWildcard(p.Path[0]) {
9494
// match every elements (*)
9595
return p.doMatchEvery(rn)
9696
}

0 commit comments

Comments
 (0)