mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: patch any key using retainKeys strategy (#2280)
This commit is contained in:
@@ -103,8 +103,8 @@ func listMergeProcess(field *ast.Field, key string, baseList, patchList *ast.Lis
|
||||
|
||||
func strategyPatchHandle(baseNode ast.Node) interceptor {
|
||||
return func(lnode ast.Node) (ast.Node, error) {
|
||||
walker := newWalker(func(node ast.Node, ctx walkCtx) {
|
||||
field, ok := node.(*ast.Field)
|
||||
walker := newWalker(func(patchNode ast.Node, ctx walkCtx) {
|
||||
field, ok := patchNode.(*ast.Field)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func strategyPatchHandle(baseNode ast.Node) interceptor {
|
||||
}
|
||||
listMergeProcess(field, key, baselist, val)
|
||||
|
||||
case *ast.StructLit:
|
||||
default:
|
||||
if !isStrategyRetainKeys(field) {
|
||||
return
|
||||
}
|
||||
@@ -148,20 +148,19 @@ func strategyPatchHandle(baseNode ast.Node) interceptor {
|
||||
for _, elt := range v.Elts {
|
||||
if fe, ok := elt.(*ast.Field); ok &&
|
||||
labelStr(fe.Label) == labelStr(field.Label) {
|
||||
fe.Value = ast.NewStruct()
|
||||
fe.Value = field.Value
|
||||
}
|
||||
}
|
||||
case *ast.File:
|
||||
case *ast.File: // For the top level element
|
||||
for _, decl := range v.Decls {
|
||||
if fe, ok := decl.(*ast.Field); ok &&
|
||||
labelStr(fe.Label) == labelStr(field.Label) {
|
||||
fe.Value = ast.NewStruct()
|
||||
fe.Value = field.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
walker.walk(lnode)
|
||||
return lnode, nil
|
||||
|
||||
@@ -428,8 +428,32 @@ spec: {
|
||||
envs: [{
|
||||
name: "e1"
|
||||
value: "v2"
|
||||
}]
|
||||
}]
|
||||
}, ...]
|
||||
}, ...]
|
||||
}
|
||||
`}, {
|
||||
base: `
|
||||
kind: "Old"
|
||||
metadata: {
|
||||
name: "Old"
|
||||
labels: keep: "true"
|
||||
}
|
||||
`,
|
||||
patch: `// +patchStrategy=retainKeys
|
||||
kind: "New"
|
||||
metadata: {
|
||||
// +patchStrategy=retainKeys
|
||||
name: "New"
|
||||
}
|
||||
`,
|
||||
result: ` // +patchStrategy=retainKeys
|
||||
kind: "New"
|
||||
metadata: {
|
||||
// +patchStrategy=retainKeys
|
||||
name: "New"
|
||||
labels: {
|
||||
keep: "true"
|
||||
}
|
||||
}
|
||||
`},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user