Description
EventSources
for basic Kubernetes resources like Deployment, Pod, etc shouldn't have to be part of an Operator but should be provided by the SDK.
Case in point: DeploymentEventSource
in the tomcat-sample
.
This is not as easy however as moving that class into a new package in the operator-framework
. The DeploymentEventSource
makes assumptions about how the Deployment
is connected to the Tomcat
object. Those assumptions are partly encoded in the TomcatController
as it is responsible for adding the right labels and ownerReferences
to the newly created Deployment
. So currently the DeploymentEventSource
is tighly coupled to the TomcatController
.
This all still feels like there should be a default implementation coming from the framework as it's pretty complicated and even though there are different ways one could implement the functionality it's
Activity
metacosm commentedon Dec 17, 2020
In https://github.com/halkyonio/operator-framework, we defined the notion of dependent resources, which I've discussed already with @csviri. The idea is that, very often, a controller, when it reconciles the state of the main custom resource it deals with, needs, in fact, to check the status of several other resources that influence the status of the main resource. The framework we developed took care of simplifying the experience by making that dependency explicit and making it possible to compute an aggregated state for the main resource based on the status of each dependent resource. The framework also took care of creating/updating/deleting all the dependent resources associated with a main resource. It also provided support for often-declared dependent resources such as Secret / ServiceAccount…
I think we should look into implementing something similar here, particularly, because, based on discussions with the operator-sdk team, it seems to be something that kubebuilder takes into account as well.
csviri commentedon Dec 17, 2020
@metacosm yes, I agree that we need also a higher abstraction. I would wait with this until we meet with operator SDK team.
Also would be probably quite easy to migrate event sources to this notion. I prepared some prototype how a higher level abstraction could look like. We can take a look also on that together.
jmesnil commentedon Jan 26, 2021
That is something that I would need in my operator and that I'm able to achieve in Golang by watching secondary resources owned by my custom resources:
https://github.com/wildfly/wildfly-operator/blob/1989b113ec70cc550f60428590de61171e8eb8dd/pkg/controller/wildflyserver/wildflyserver_controller.go#L81-L88
This will trigger a call to my custom resource code handling so that I can reconcile its status based on these secondary resources.
This relies on making sure that any secondary resources that are created by my operator is properly flagged with a
ownerReference
(something like https://github.com/jmesnil/wildfly-operator/blob/c24f0d1b37889c9184a400821de12ff09a92f8f8/src/main/java/org/wildfly/operator/resources/Resources.java#L29-L39).Related to this, I'm more interested by "watching" these resources and be notified periodically (in addition to events sources) so that my custom reference can periodically update its status based on these secondary resources's statues (that may not trigger any event when their status changes).
adam-sandor commentedon Jan 27, 2021
@jmesnil I'm not sure if you're aware but this is already possible (see tomcat sample). The missing thing now is that the framework doesn't do as much as it could to help. You have to create your own EventSource even for standard Kubernetes objects (see DeploymentEventSource) and you have to manage owner references yourself.
jmesnil commentedon Jan 27, 2021
@adam-sandor sorry, if I was not clear.
I saw the tomcat sample but this requires lots of boilerplate code that should be provided (or helped) by the SDK.
The key word in this RFE is "out-of-the-box" :)
csviri commentedon Nov 10, 2021
this is done, see InformerEventSource,
see usage: #659
metacosm commentedon Nov 10, 2021
This isn't addressed by the
InformerEventSource
. This issue is about providing generic event sources for native kubernetes resources such asDeployment
orSecret
. TheInformerEventSource
makes it easier but this isn't really what this issue is about… at least, if I understood properly. 😄csviri commentedon Nov 10, 2021
Sorry, you are right, I just read the title probably closed it and 10 minutes later I actually created an issue for this topic because I was not able to find this issue :D
csviri commentedon Nov 11, 2021
Ohh sorry checked on this again, but I think it is. Take a look here, we are covering this way all the k8s resources:
https://github.com/java-operator-sdk/java-operator-sdk/blob/f23a78d009a4d693d5bff6a7ba2dfdb51c094c6b/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/TomcatController.java#L45-L58
andreaTP commentedon Jan 13, 2022
I think this issue is still relevant, and having to manually deal with injecting
ownerReferences
manually when creating resources and extracting them in the Informer is something that the SDK can, eventually, take care of.Probably by somehow not injecting the plain
kubernetes-client
but wrapping it into an higher level abstraction.This would enable multiple conveniences, e.g.: injecting labels/annotations etc. to all the resources created by a
Controller
.metacosm commentedon Jan 13, 2022
The dependent resources PR takes care of owner references automatically for example.
csviri commentedon Jul 8, 2022
Closing this issue since I don't see anything that is not covered:
InformerEventSource
is about watching the resources, now it is covered automatically to watch by owner reference (or annotation if that is not possible)DependentResources cover automatic owner reference management. But also fabric8 client provide an out of the box convinience method.