@@ -130,7 +130,7 @@ func (mgp metaGeneratePatches) GeneratePatches(
130130 // Merge the global variables to the current resource vars. This allows the handlers to access
131131 // the variables defined in the cluster class or cluster configuration and use these correctly when
132132 // overrides are specified on machine deployment or control plane configuration.
133- mergedVars , err := mergeVariableDefinitions (vars , globalVars )
133+ mergedVars , err := mergeVariableOverridesWithGlobal (vars , globalVars )
134134 if err != nil {
135135 log .Error (err , "Failed to merge global variables" )
136136 return err
@@ -139,7 +139,7 @@ func (mgp metaGeneratePatches) GeneratePatches(
139139 for i , h := range mgp .mutators {
140140 mutatorType := fmt .Sprintf ("%T" , h )
141141 log .V (5 ).
142- Info ("Running mutator" , "index" , i , "handler" , mutatorType , "vars" , vars )
142+ Info ("Running mutator" , "index" , i , "handler" , mutatorType , "vars" , mergedVars )
143143
144144 if err := h .Mutate (
145145 ctx ,
@@ -162,10 +162,12 @@ func (mgp metaGeneratePatches) GeneratePatches(
162162 )
163163}
164164
165- func mergeVariableDefinitions (
166- vars , globalVars map [string ]apiextensionsv1.JSON ,
165+ // mergeVariableOverridesWithGlobal merges the provided variable overrides with the global variables.
166+ // It performs a deep merge, ensuring that if a variable exists in both maps, the value from the overrides is used.
167+ func mergeVariableOverridesWithGlobal (
168+ overrideVars , globalVars map [string ]apiextensionsv1.JSON ,
167169) (map [string ]apiextensionsv1.JSON , error ) {
168- mergedVars := maps .Clone (vars )
170+ mergedVars := maps .Clone (overrideVars )
169171
170172 for k , v := range globalVars {
171173 // If the value of v is nil, skip it.
0 commit comments