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
0 commit comments