Skip to content

Commit 06530f2

Browse files
authored
Modify override merging to ignore blocks with an incompatible version (#15297)
1 parent d2e1e4a commit 06530f2

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

mmv1/api/product.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,20 @@ func (p Product) Lineage() string {
282282
return p.Name
283283
}
284284

285-
func Merge(self, otherObj reflect.Value) {
286-
285+
func Merge(self, otherObj reflect.Value, version string) {
287286
selfObj := reflect.Indirect(self)
287+
288+
// Skip merge if otherObj targets a higher version than what is being generated
289+
for i := 0; i < otherObj.NumField(); i++ {
290+
if otherObj.Type().Field(i).Name == "MinVersion" {
291+
for j := slices.Index(product.ORDER, version) + 1; j < len(product.ORDER); j++ {
292+
if otherObj.Field(i).String() == product.ORDER[j] {
293+
return
294+
}
295+
}
296+
}
297+
}
298+
288299
for i := 0; i < selfObj.NumField(); i++ {
289300

290301
// skip if the override is the "empty" value
@@ -295,14 +306,14 @@ func Merge(self, otherObj reflect.Value) {
295306
}
296307

297308
if selfObj.Field(i).Kind() == reflect.Slice {
298-
DeepMerge(selfObj.Field(i), otherObj.Field(i))
309+
DeepMerge(selfObj.Field(i), otherObj.Field(i), version)
299310
} else {
300311
selfObj.Field(i).Set(otherObj.Field(i))
301312
}
302313
}
303314
}
304315

305-
func DeepMerge(arr1, arr2 reflect.Value) {
316+
func DeepMerge(arr1, arr2 reflect.Value, version string) {
306317
if arr1.Len() == 0 {
307318
arr1.Set(arr2)
308319
return
@@ -341,7 +352,7 @@ func DeepMerge(arr1, arr2 reflect.Value) {
341352
}
342353
}
343354
if otherVal.IsValid() {
344-
Merge(currentVal, otherVal)
355+
Merge(currentVal, otherVal, version)
345356
}
346357
}
347358

mmv1/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func GenerateProduct(version, providerName, productName, outputPath string, prod
195195
overrideApiProduct := &api.Product{}
196196
api.Compile(productOverridePath, overrideApiProduct, overrideDirectory)
197197

198-
api.Merge(reflect.ValueOf(productApi), reflect.ValueOf(*overrideApiProduct))
198+
api.Merge(reflect.ValueOf(productApi), reflect.ValueOf(*overrideApiProduct), version)
199199
} else {
200200
api.Compile(productOverridePath, productApi, overrideDirectory)
201201
}
@@ -265,7 +265,7 @@ func GenerateProduct(version, providerName, productName, outputPath string, prod
265265
api.Compile(baseResourcePath, resource, overrideDirectory)
266266
overrideResource := &api.Resource{}
267267
api.Compile(overrideYamlPath, overrideResource, overrideDirectory)
268-
api.Merge(reflect.ValueOf(resource), reflect.ValueOf(*overrideResource))
268+
api.Merge(reflect.ValueOf(resource), reflect.ValueOf(*overrideResource), version)
269269
resource.SourceYamlFile = baseResourcePath
270270
} else {
271271
api.Compile(overrideYamlPath, resource, overrideDirectory)

0 commit comments

Comments
 (0)