@@ -130,7 +130,7 @@ func (mgp metaGeneratePatches) GeneratePatches(
130
130
// Merge the global variables to the current resource vars. This allows the handlers to access
131
131
// the variables defined in the cluster class or cluster configuration and use these correctly when
132
132
// overrides are specified on machine deployment or control plane configuration.
133
- mergedVars , err := mergeVariableDefinitions (vars , globalVars )
133
+ mergedVars , err := mergeVariableOverridesWithGlobal (vars , globalVars )
134
134
if err != nil {
135
135
log .Error (err , "Failed to merge global variables" )
136
136
return err
@@ -139,7 +139,7 @@ func (mgp metaGeneratePatches) GeneratePatches(
139
139
for i , h := range mgp .mutators {
140
140
mutatorType := fmt .Sprintf ("%T" , h )
141
141
log .V (5 ).
142
- Info ("Running mutator" , "index" , i , "handler" , mutatorType , "vars" , vars )
142
+ Info ("Running mutator" , "index" , i , "handler" , mutatorType , "vars" , mergedVars )
143
143
144
144
if err := h .Mutate (
145
145
ctx ,
@@ -162,10 +162,12 @@ func (mgp metaGeneratePatches) GeneratePatches(
162
162
)
163
163
}
164
164
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 ,
167
169
) (map [string ]apiextensionsv1.JSON , error ) {
168
- mergedVars := maps .Clone (vars )
170
+ mergedVars := maps .Clone (overrideVars )
169
171
170
172
for k , v := range globalVars {
171
173
// If the value of v is nil, skip it.
0 commit comments