feat: add PatchArgs API type to populate patch options

This commit converts the Options section of a patch into an object instead of map.
This allows better clarification of the available options.
This commit is contained in:
Adoram Shoval
2025-05-23 14:28:43 -04:00
parent 2859474e3c
commit 9043c223d4
8 changed files with 93 additions and 143 deletions

View File

@@ -241,7 +241,7 @@ func constructTargets(file string, node *kyaml.RNode, fieldPaths []string,
}
if patch, ok := patchTarget[file]; ok {
if !patch.Options["allowNameChange"] || !patch.Options["allowKindChange"] {
if patch.Options == nil || (!patch.Options.AllowNameChange || !patch.Options.AllowKindChange) {
return writePatchTargets(patch, node, fieldPaths, options)
}
}
@@ -299,11 +299,13 @@ func writePatchTargets(patch types.Patch, node *kyaml.RNode, fieldPaths []string
if options[i].String() != "" {
target.Options = options[i]
}
if patch.Options["allowNameChange"] {
target.Select.ResId.Name = node.GetName()
}
if patch.Options["allowKindChange"] {
target.Select.ResId.Kind = node.GetKind()
if patch.Options != nil {
if patch.Options.AllowNameChange {
target.Select.ResId.Name = node.GetName()
}
if patch.Options.AllowKindChange {
target.Select.ResId.Kind = node.GetKind()
}
}
if node.GetNamespace() != "" {
target.Select.ResId.Namespace = node.GetNamespace()