mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
support mapping values with '.' in replacements fieldpaths
This commit is contained in:
@@ -1357,7 +1357,14 @@ metadata:
|
|||||||
fieldPaths:
|
fieldPaths:
|
||||||
- metadata.annotations.[f.g.h/i-j]
|
- metadata.annotations.[f.g.h/i-j]
|
||||||
`,
|
`,
|
||||||
expectedErr: "list path element must contain fieldName=fieldValue for element to match",
|
expected: `apiVersion: v1
|
||||||
|
kind: Custom
|
||||||
|
metadata:
|
||||||
|
name: custom
|
||||||
|
annotations:
|
||||||
|
a.b.c/d-e: source
|
||||||
|
f.g.h/i-j: source
|
||||||
|
`,
|
||||||
},
|
},
|
||||||
"list index contains '.' character": {
|
"list index contains '.' character": {
|
||||||
input: `apiVersion: v1
|
input: `apiVersion: v1
|
||||||
|
|||||||
@@ -23,12 +23,17 @@ func PathSplitter(path string, delimiter string) []string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmarterPathSplitter splits a path, retaining bracketed list entry identifiers.
|
// SmarterPathSplitter splits a path, retaining bracketed elements.
|
||||||
// E.g. [name=com.foo.someapp] survives as one thing after splitting
|
// If the element is a list entry identifier (defined by the '='),
|
||||||
|
// it will retain the brackets.
|
||||||
|
// E.g. "[name=com.foo.someapp]" survives as one thing after splitting
|
||||||
// "spec.template.spec.containers.[name=com.foo.someapp].image"
|
// "spec.template.spec.containers.[name=com.foo.someapp].image"
|
||||||
// See kyaml/yaml/match.go for use of list entry identifiers.
|
// See kyaml/yaml/match.go for use of list entry identifiers.
|
||||||
// This function uses `PathSplitter`, so it respects list entry identifiers
|
// If the element is a mapping entry identifier, it will remove the
|
||||||
// and escaped delimiters.
|
// brackets.
|
||||||
|
// E.g. "a.b.c" survives as one thing after splitting
|
||||||
|
// "metadata.annotations.[a.b.c]
|
||||||
|
// This function uses `PathSplitter`, so it also respects escaped delimiters.
|
||||||
func SmarterPathSplitter(path string, delimiter string) []string {
|
func SmarterPathSplitter(path string, delimiter string) []string {
|
||||||
var result []string
|
var result []string
|
||||||
split := PathSplitter(path, delimiter)
|
split := PathSplitter(path, delimiter)
|
||||||
@@ -45,7 +50,12 @@ func SmarterPathSplitter(path string, delimiter string) []string {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = append(result, strings.Join(bracketed, delimiter))
|
bracketedStr := strings.Join(bracketed, delimiter)
|
||||||
|
if strings.Contains(bracketedStr, "=") {
|
||||||
|
result = append(result, bracketedStr)
|
||||||
|
} else {
|
||||||
|
result = append(result, strings.Trim(bracketedStr, "[]"))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
result = append(result, elem)
|
result = append(result, elem)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ func TestSmarterPathSplitter(t *testing.T) {
|
|||||||
input: "spec.data.[name=f.i.[r.s.t..key",
|
input: "spec.data.[name=f.i.[r.s.t..key",
|
||||||
expected: []string{"spec", "data", "[name=f.i.[r.s.t..key"},
|
expected: []string{"spec", "data", "[name=f.i.[r.s.t..key"},
|
||||||
},
|
},
|
||||||
|
"mapping value with .": {
|
||||||
|
input: "metadata.annotations.[a.b.c/d.e.f-g.]",
|
||||||
|
expected: []string{"metadata", "annotations", "a.b.c/d.e.f-g."},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for tn, tc := range testCases {
|
for tn, tc := range testCases {
|
||||||
t.Run(tn, func(t *testing.T) {
|
t.Run(tn, func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user