Skip to content

Integration of expectations #2750

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

Open
csviri opened this issue Apr 2, 2025 · 2 comments
Open

Integration of expectations #2750

csviri opened this issue Apr 2, 2025 · 2 comments
Milestone

Comments

@csviri
Copy link
Collaborator

csviri commented Apr 2, 2025

See references and description of expectations here:
https://ahmet.im/blog/controller-pitfalls/#expectations-pattern

This does not seems to be supported in controller runtime either:
kubernetes-sigs/controller-runtime#644

We should investigate how we could support this in different layers of the framework.

@csviri csviri added this to the 5.1 milestone Apr 2, 2025
@csviri csviri changed the title Integration of expectation Integration of expectations Apr 2, 2025
@csviri
Copy link
Collaborator Author

csviri commented Apr 25, 2025

What I could imaging is to have an API that looks something like this:

UpdateControl reconcile(Primary primary, Context<Primary> context) {

// omit reconcile details

  return UpdateControl.expect((context,primary)-> {
     var resources = context.getSecondaryResources(MyResource.class)
     return checkIfResourcesInexpectedState(resources) 
   },Duration.ofSeconds(5))

}

In other words, that the reconcile could return an expectation with a timeout, and the reconciliation would not be triggered until that expectation predicate is true or it timeouts.

While this sounds nice, and might provide a benefit for the users, execution, we won't have too much space to optimize it, so in terms of execution, it would have to be done anyway in the executor service thread that we use now for reconciliation. So this can be directly transformed to something like this:

UpdateControl reconcile(Primary primary, Context<Primary> context) {
  var resources = context.getSecondaryResources(MyResource.class)
   if (!checkIfResourcesInexpectedState(resources)) {
      return UpdateControl.noUpdate()
   } 
}

Except the timeout for which user might have to track hat in a ConcurrentHashMap or such.

It would be a completely different story if this worked as a cross-cutting filter, where all the event source caches are available.

It would worth to make a prototype, how that would look like, but for that we would need a new abstraction, probably a subset of Context to access secondary resources from the cache and directly event sources in case.

@csviri
Copy link
Collaborator Author

csviri commented Apr 25, 2025

cc @xstefank @metacosm @shawkins, maybe something to discuss in the next community meeting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant