Skip to content

Commit af8db22

Browse files
joelanfordPer Goncalves da Silva
authored andcommitted
sort lists of identifiers and conflict messages to reduce SAT solver non-determinism (#3491)
Signed-off-by: Joe Lanford <[email protected]> Upstream-repository: operator-lifecycle-manager Upstream-commit: 451e775ea03eb9280399ba0abaf19bd237df167c Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 0372b14 commit af8db22

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

staging/operator-lifecycle-manager/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
github.com/spf13/cobra v1.7.0
3636
github.com/spf13/pflag v1.0.5
3737
github.com/stretchr/testify v1.8.4
38+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
3839
golang.org/x/net v0.34.0
3940
golang.org/x/sync v0.10.0
4041
golang.org/x/time v0.3.0
@@ -216,7 +217,6 @@ require (
216217
go.uber.org/multierr v1.6.0 // indirect
217218
go.uber.org/zap v1.24.0 // indirect
218219
golang.org/x/crypto v0.32.0 // indirect
219-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
220220
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
221221
golang.org/x/mod v0.17.0 // indirect
222222
golang.org/x/oauth2 v0.14.0 // indirect

staging/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/solver"
1818
"github.com/operator-framework/operator-registry/pkg/api"
1919
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
20+
21+
"golang.org/x/exp/slices"
2022
)
2123

2224
// constraintProvider knows how to provide solver constraints for a given cache entry.
@@ -513,11 +515,13 @@ func (r *Resolver) addInvariants(namespacedCache cache.MultiCatalogOperatorFinde
513515
}
514516

515517
for gvk, is := range gvkConflictToVariable {
518+
slices.Sort(is)
516519
s := NewSingleAPIProviderVariable(gvk.Group, gvk.Version, gvk.Kind, is)
517520
variables[s.Identifier()] = s
518521
}
519522

520523
for pkg, is := range packageConflictToVariable {
524+
slices.Sort(is)
521525
s := NewSinglePackageInstanceVariable(pkg, is)
522526
variables[s.Identifier()] = s
523527
}

staging/operator-lifecycle-manager/pkg/controller/registry/resolver/solver/lit_mapping.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"github.com/go-air/gini/inter"
88
"github.com/go-air/gini/logic"
99
"github.com/go-air/gini/z"
10+
11+
"golang.org/x/exp/slices"
1012
)
1113

1214
type DuplicateIdentifier Identifier
@@ -203,5 +205,17 @@ func (d *litMapping) Conflicts(g inter.Assumable) []AppliedConstraint {
203205
as = append(as, a)
204206
}
205207
}
208+
slices.SortFunc(as, func(a, b AppliedConstraint) int {
209+
return strCmp(a.String(), b.String())
210+
})
206211
return as
207212
}
213+
214+
func strCmp(str1, str2 string) int {
215+
if str1 < str2 {
216+
return -1
217+
} else if str1 > str2 {
218+
return 1
219+
}
220+
return 0
221+
}

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/resolver.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/solver/lit_mapping.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)