Skip to content

Commit b11bd79

Browse files
committed
fixup! refactor: Address review feedback
1 parent 8af941a commit b11bd79

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

common/pkg/capi/clustertopology/handlers/mutation/meta.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

common/pkg/capi/clustertopology/handlers/mutation/meta_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ func TestMergeVariableDefinitions(t *testing.T) {
463463
t.Run(tt.name, func(t *testing.T) {
464464
t.Parallel()
465465
g := gomega.NewWithT(t)
466-
got, err := mergeVariableDefinitions(tt.args.vars, tt.args.globalVars)
466+
got, err := mergeVariableOverridesWithGlobal(tt.args.vars, tt.args.globalVars)
467467
if tt.wantErr {
468468
g.Expect(err).To(gomega.HaveOccurred())
469469
g.Expect(err.Error()).To(gomega.ContainSubstring(tt.errString))

0 commit comments

Comments
 (0)