Skip to content

Support for expectations pattern #2750

Open
@csviri

Description

@csviri
Collaborator

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.

Activity

added this to the 5.1 milestone on Apr 2, 2025
changed the title [-]Integration of expectation[/-] [+]Integration of expectations[/+] on Apr 2, 2025
csviri

csviri commented on Apr 25, 2025

@csviri
CollaboratorAuthor

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

csviri commented on Apr 25, 2025

@csviri
CollaboratorAuthor

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

modified the milestones: 5.1, 5.2 on May 14, 2025
self-assigned this
on Jun 26, 2025
linked a pull request that will close this issuefeat: expectations #2840on Jun 26, 2025
changed the title [-]Integration of expectations[/-] [+]Support for expectations pattern[/+] on Jul 8, 2025
csviri

csviri commented on Jul 8, 2025

@csviri
CollaboratorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @csviri

    Issue actions

      Support for expectations pattern · Issue #2750 · operator-framework/java-operator-sdk