mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
support slash in path
This commit is contained in:
@@ -37,7 +37,7 @@ func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
|
|||||||
if match, err := isMatchGVK(fltr.FieldSpec, obj); !match || err != nil {
|
if match, err := isMatchGVK(fltr.FieldSpec, obj); !match || err != nil {
|
||||||
return obj, errors.Wrap(err)
|
return obj, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
fltr.path = strings.Split(fltr.FieldSpec.Path, "/")
|
fltr.path = splitPath(fltr.FieldSpec.Path)
|
||||||
if err := fltr.filter(obj); err != nil {
|
if err := fltr.filter(obj); err != nil {
|
||||||
s, _ := obj.String()
|
s, _ := obj.String()
|
||||||
return nil, errors.WrapPrefixf(err,
|
return nil, errors.WrapPrefixf(err,
|
||||||
@@ -159,3 +159,18 @@ func isMatchGVK(fs types.FieldSpec, obj *yaml.RNode) (bool, error) {
|
|||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitPath(path string) []string {
|
||||||
|
ps := strings.Split(path, "/")
|
||||||
|
var res []string
|
||||||
|
res = append(res, ps[0])
|
||||||
|
for i := 1; i < len(ps); i++ {
|
||||||
|
lastIndex := len(res) - 1
|
||||||
|
if strings.HasSuffix(res[lastIndex], "\\") {
|
||||||
|
res[lastIndex] = strings.TrimSuffix(res[lastIndex], "\\") + "/" + ps[i]
|
||||||
|
} else {
|
||||||
|
res = append(res, ps[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|||||||
@@ -435,6 +435,60 @@ spec:
|
|||||||
},
|
},
|
||||||
error: "obj '' at path 'spec/containers/image': expected sequence or mapping node",
|
error: "obj '' at path 'spec/containers/image': expected sequence or mapping node",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "filedname with slash '/'",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b\/c/d
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d: foo
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d: bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filedname with multiple '/'",
|
||||||
|
fieldSpec: `
|
||||||
|
path: a/b\/c/d\/e/f
|
||||||
|
version: v1
|
||||||
|
kind: Bar
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d/e:
|
||||||
|
f: foo
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b/c:
|
||||||
|
d/e:
|
||||||
|
f: bar
|
||||||
|
`,
|
||||||
|
filter: fieldspec.Filter{
|
||||||
|
SetValue: filtersutil.SetScalar("bar"),
|
||||||
|
CreateKind: yaml.ScalarNode,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilter_Filter(t *testing.T) {
|
func TestFilter_Filter(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user