@@ -191,7 +191,7 @@ func copyValueToTarget(target *yaml.RNode, value *yaml.RNode, selector *types.Ta
191191 }
192192
193193 // Check if this fieldPath contains structured data access
194- if err := setValueInStructuredData (target , value , fp , createKind ); err == nil {
194+ if err := setValueInStructuredData (target , value , fp , selector . Options ); err == nil {
195195 // Successfully handled as structured data
196196 continue
197197 }
@@ -258,7 +258,7 @@ func setFieldValue(options *types.FieldOptions, targetField *yaml.RNode, value *
258258}
259259
260260// setValueInStructuredData handles setting values within structured data (JSON/YAML) in scalar fields
261- func setValueInStructuredData (target * yaml.RNode , value * yaml.RNode , fieldPath string , createKind yaml. Kind ) error {
261+ func setValueInStructuredData (target * yaml.RNode , value * yaml.RNode , fieldPath string , options * types. FieldOptions ) error {
262262 pathParts := kyaml_utils .SmarterPathSplitter (fieldPath , "." )
263263 if len (pathParts ) < 2 {
264264 return fmt .Errorf ("not a structured data path" )
@@ -309,6 +309,11 @@ func setValueInStructuredData(target *yaml.RNode, value *yaml.RNode, fieldPath s
309309
310310 structuredData := yaml .NewRNode (& parsedNode )
311311
312+ createKind := yaml .Kind (0 ) // do not create
313+ if options != nil && options .Create {
314+ createKind = value .YNode ().Kind
315+ }
316+
312317 // Navigate to the target location within the structured data
313318 targetInStructured , err := structuredData .Pipe (& yaml.PathMatcher {
314319 Path : structuredDataPath ,
@@ -329,10 +334,9 @@ func setValueInStructuredData(target *yaml.RNode, value *yaml.RNode, fieldPath s
329334
330335 // Set the value in the structured data
331336 for _ , t := range targetFields {
332- if t .YNode ().Kind == yaml .ScalarNode {
333- t .YNode ().Value = value .YNode ().Value
334- } else {
335- t .SetYNode (value .YNode ())
337+ err = setFieldValue (options , t , value )
338+ if err != nil {
339+ return err
336340 }
337341 }
338342
0 commit comments