6
6
7
7
"github.com/operator-framework/deppy/pkg/deppy"
8
8
"github.com/operator-framework/deppy/pkg/deppy/input"
9
+ "k8s.io/apimachinery/pkg/util/sets"
9
10
10
11
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
11
12
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
@@ -43,7 +44,9 @@ func (g *CRDUniquenessConstraintsVariableSource) GetVariables(ctx context.Contex
43
44
// todo(perdasilva): better handle cases where a provided gvk is not found
44
45
// not all packages will necessarily export a CRD
45
46
46
- pkgToBundleMap := map [string ]map [deppy.Identifier ]struct {}{}
47
+ bundleIDs := sets.Set [deppy.Identifier ]{}
48
+ packageOrder := []string {}
49
+ bundleOrder := map [string ][]deppy.Identifier {}
47
50
for _ , variable := range variables {
48
51
switch v := variable .(type ) {
49
52
case * olmvariables.BundleVariable :
@@ -54,22 +57,22 @@ func (g *CRDUniquenessConstraintsVariableSource) GetVariables(ctx context.Contex
54
57
// get bundleID package and update map
55
58
packageName := bundle .Package
56
59
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 )
59
67
}
60
- pkgToBundleMap [packageName ][id ] = struct {}{}
61
68
}
62
69
}
63
70
}
64
71
65
72
// 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 {
71
74
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 ] ... ))
73
76
}
74
77
75
78
return variables , nil
0 commit comments