Skip to content

Commit 7020ae2

Browse files
authored
Remove randomness in package uniqueness ordering (#461)
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 617a685 commit 7020ae2

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

internal/resolution/variablesources/crd_constraints.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/operator-framework/deppy/pkg/deppy"
88
"github.com/operator-framework/deppy/pkg/deppy/input"
9+
"k8s.io/apimachinery/pkg/util/sets"
910

1011
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
1112
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
@@ -43,7 +44,9 @@ func (g *CRDUniquenessConstraintsVariableSource) GetVariables(ctx context.Contex
4344
// todo(perdasilva): better handle cases where a provided gvk is not found
4445
// not all packages will necessarily export a CRD
4546

46-
pkgToBundleMap := map[string]map[deppy.Identifier]struct{}{}
47+
bundleIDs := sets.Set[deppy.Identifier]{}
48+
packageOrder := []string{}
49+
bundleOrder := map[string][]deppy.Identifier{}
4750
for _, variable := range variables {
4851
switch v := variable.(type) {
4952
case *olmvariables.BundleVariable:
@@ -54,22 +57,22 @@ func (g *CRDUniquenessConstraintsVariableSource) GetVariables(ctx context.Contex
5457
// get bundleID package and update map
5558
packageName := bundle.Package
5659

57-
if _, ok := pkgToBundleMap[packageName]; !ok {
58-
pkgToBundleMap[packageName] = map[deppy.Identifier]struct{}{}
60+
if _, ok := bundleOrder[packageName]; !ok {
61+
packageOrder = append(packageOrder, packageName)
62+
}
63+
64+
if !bundleIDs.Has(id) {
65+
bundleIDs.Insert(id)
66+
bundleOrder[packageName] = append(bundleOrder[packageName], id)
5967
}
60-
pkgToBundleMap[packageName][id] = struct{}{}
6168
}
6269
}
6370
}
6471

6572
// create global constraint variables
66-
for packageName, bundleIDMap := range pkgToBundleMap {
67-
var bundleIDs []deppy.Identifier
68-
for bundleID := range bundleIDMap {
69-
bundleIDs = append(bundleIDs, bundleID)
70-
}
73+
for _, packageName := range packageOrder {
7174
varID := deppy.IdentifierFromString(fmt.Sprintf("%s package uniqueness", packageName))
72-
variables = append(variables, olmvariables.NewBundleUniquenessVariable(varID, bundleIDs...))
75+
variables = append(variables, olmvariables.NewBundleUniquenessVariable(varID, bundleOrder[packageName]...))
7376
}
7477

7578
return variables, nil

internal/resolution/variablesources/crd_constraints_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,13 @@ var _ = Describe("CRDUniquenessConstraintsVariableSource", func() {
284284
}
285285
// Note: As above, the 5 GVKs would appear here as GVK uniqueness constraints
286286
// if GVK Uniqueness were being accounted for.
287-
Expect(crdConstraintVariables).To(WithTransform(CollectGlobalConstraintVariableIDs, ConsistOf([]string{
288-
"another-package package uniqueness",
289-
"bar-package package uniqueness",
290-
"test-package-2 package uniqueness",
287+
Expect(crdConstraintVariables).To(WithTransform(CollectGlobalConstraintVariableIDs, Equal([]string{
291288
"test-package package uniqueness",
292289
"some-package package uniqueness",
293290
"some-other-package package uniqueness",
291+
"another-package package uniqueness",
292+
"bar-package package uniqueness",
293+
"test-package-2 package uniqueness",
294294
})))
295295
})
296296

0 commit comments

Comments
 (0)