Java Operator SDK — Introduction to Event Sources

The Definition of the Problem

  1. When we create a dependent resource, the duration while it’s successfully created and gets into a target state can take a long time (Think provisioning a databse for example). So we have two options, synchronously waiting in the controller — blocking the thread — until it’s created or asynchronous react on the changes of the dependent resource. Thus execute the controller again on changes of the dependent resource and continue in the workflow.
  2. Let’s consider we are in a state where all the dependent resources are created, but suddenly one of the dependent resources is destroyed — let’s say (for sake of simplicity) a pod is crashed. Until now we had no way to react on such event, until next time the controller is executed (or it was quite cumbersome to hack it into our operators). Until now we usually just executed the controller when the custom resource was changed. We could put there some timer (what we support also now) to periodically execute the controller and poll the state of the dependent resource. This works, be it’s not ideal, in case we have hundreds of custom resource instances, polling all the related APIs is not efficient. What we want is a way to get notified, in other words trigger the controller where there are some changes in the resources that we manage.

Event Sources

  • The CustomResourceEvenSource event source is a special one, which sends events regarding changes of our custom resource, this is an event source which is always registered for every controller by default.
  • An event is always related to a custom resource, so our API did not change: UpdateControl<R> createOrUpdateResource(R resource, Context<R> context);
    We receive however, the event(s) which triggered the controller execution in context object.
  • Concurrency is still handled for you, thus we still guarantee that there is no concurrent execution of the controller for the same custom resource (there is parallel execution if an event is related to another custom resource instance).
    Note that if we receive multiple events while a controller is being executed, we buffer those events and execute the controller again, when the previous execution finished.

Best Practices

Using Events Only as Triggers

Caching

Filtering events

Closing Note

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Java Generics — Advanced Cases

Google | L3 (New Grad) | Taiwan | Nov 2021 [Offer]

Calculating readability for a given piece of text

Which Bootcamp Is Best for You?

Python method vs

MS Power Automate HTTP Request Action Authentication Types

How to write efficient Regular Expression in Python

20 VSCode Extensions For Every Front-End Developer

VS Code

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Attila Mészáros

Attila Mészáros

More from Medium

Decoding the Encodings (01) — The Beginning!

How we migrated from RDS MySql to RDS Aurora and stopped suffering from lags

Design 101 : Why do we need Abstract Factory Pattern now?

How to parse Dynamic JSON String?