Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution error message is not deterministic #459

Closed
m1kola opened this issue Oct 13, 2023 · 2 comments · Fixed by #547
Closed

Resolution error message is not deterministic #459

m1kola opened this issue Oct 13, 2023 · 2 comments · Fixed by #547
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@m1kola
Copy link
Member

m1kola commented Oct 13, 2023

I noticed that we iterate over maps here:

for packageName, bundleIDMap := range pkgToBundleMap {
var bundleIDs []deppy.Identifier
for bundleID := range bundleIDMap {
bundleIDs = append(bundleIDs, bundleID)
}
varID := deppy.IdentifierFromString(fmt.Sprintf("%s package uniqueness", packageName))
variables = append(variables, olmvariables.NewBundleUniquenessVariable(varID, bundleIDs...))
}

I believe this results in randomised order of variables.

Tests do not flag this because they use ConsistOf which ignores order:

// Note: As above, the 5 GVKs would appear here as GVK uniqueness constraints
// if GVK Uniqueness were being accounted for.
Expect(crdConstraintVariables).To(WithTransform(CollectGlobalConstraintVariableIDs, ConsistOf([]string{
"another-package package uniqueness",
"bar-package package uniqueness",
"test-package-2 package uniqueness",
"test-package package uniqueness",
"some-package package uniqueness",
"some-other-package package uniqueness",
})))

It likely contributes to what was reported in operator-framework/deppy#142:

It turns out the assertion is flaky because the content of the message changes from run to run, only in terms of the order in which the individual constraint messages appear. This is problematic when this error message is written to a kubernetes status object because it results in a reconcile -> update status -> reconcile -> update status loop until we get "lucky" and deppy returns the same message two reconciles in a row.

@m1kola m1kola added the kind/bug Categorizes issue or PR as related to a bug. label Oct 13, 2023
@m1kola m1kola changed the title Non deterministic order of variables created by CRDUniquenessConstraintsVariableSource Resolution error message is not deterministic Oct 13, 2023
@m1kola
Copy link
Member Author

m1kola commented Oct 16, 2023

#461 gets rid of randomness in package uniqueness ordering.

I would still like to keep this issue open so we can get rid of this function:

// TODO: This can be removed when operator controller bumps to a
// version of deppy that contains a fix for this issue:
// https://github.com/operator-framework/deppy/issues/142
// prettyUnsatMessage ensures that the unsat message is deterministic and
// human-readable. It sorts the individual constraint strings lexicographically
// and joins them with a semicolon (rather than a comma, which the unsat.Error()
// function does). This function also has the side effect of sorting the items
// in the unsat slice.
func prettyUnsatMessage(unsat deppy.NotSatisfiable) string {
sort.Slice(unsat, func(i, j int) bool {
return unsat[i].String() < unsat[j].String()
})
msgs := make([]string, 0, len(unsat))
for _, c := range unsat {
msgs = append(msgs, c.String())
}
return fmt.Sprintf("constraints not satisfiable: %s", strings.Join(msgs, "; "))
}

This will require:

  • Change to error formating on deppy side (replace comma with semicolon)
  • Additional tests for OperatorReconciler to make sure that ordering is stable

@m1kola
Copy link
Member Author

m1kola commented Nov 14, 2023

This will require:

  • Change to error formating on deppy side (replace comma with semicolon)
  • Additional tests for OperatorReconciler to make sure that ordering is stable

We updated separators in operator-framework/deppy#158. There is operator-framework/deppy#159 now open to deal with non deterministic output from Deppy solver.

Once we have a new release of Deppy which contains operator-framework/deppy#159, remaining steps on operator-controller side will be:

  1. Update deppy
  2. Remove prettyUnsatMessage function

@m1kola m1kola self-assigned this Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant