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


Filtering events

Closing Note




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

Recommended from Medium

What is Web Hosting for Beginners?

Connecter + Server = Better Way to Work as a Team

Android Data Binding: Say no with findViewById, RxBinding!

Parallel and Concurrent Programming (Using Java) — Part I

El rol del top management en la motivación y comunicación

Twitter sentiment analysis using Zookeeper, Kafka and PySpark live-streaming on Windows 10 in 2022

Postgres Index stats and Query Optimization

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

Hypothesis testing

JDK 18 and the UTF-8 as default charset

Implement a Cache Service using Redis in Java

Java features from version — 8 to 18