Micronaut: k8s operator for all namespaces

152 views Asked by At

I'm trying to create a Kubernetes Operator in Micronaut using micronaut-kubernetes-operator that listens to Pod events in all namespaces on my cluster. However I can't get my code to work for any / all namespaces.

Listening to a defined namespace works with the following code:

@Operator(
  informer = Informer(
    apiType = V1Pod::class,
    apiListType = V1PodList::class,
    resourcePlural = "pods",
    namespace = "my_namespace"
  )
) //
class NetpolReconciler : ResourceReconciler<V1Pod> {

  override fun reconcile(
    request: Request,
    lister: OperatorResourceLister<V1Pod>,
  ): Result {
   ...

Setting namespace to Informer#ALL_NAMESPACES or "" results in a NullPointerException when receiving a request:

09:30:43.942 [OperatorV1Pod-controller-12] [traceId:,spanId:] ERROR i.k.c.e.controller.DefaultController - Reconciler aborted unexpectedly
java.lang.NullPointerException: Cannot invoke "io.kubernetes.client.informer.SharedIndexInformer.getIndexer()" because "sharedIndexInformer" is null
    at io.micronaut.kubernetes.client.operator.OperatorResourceLister.get(OperatorResourceLister.java:66)
    at operator.NetpolReconciler.reconcile(NetpolReconciler.kt:31)
    at io.micronaut.kubernetes.client.operator.controller.DefaultControllerBuilder.lambda$build$1(DefaultControllerBuilder.java:108)
    at io.kubernetes.client.extended.controller.DefaultController.worker(DefaultController.java:207)
    at io.kubernetes.client.extended.controller.DefaultController.lambda$run$1(DefaultController.java:154)

Can this even be achieved with micronaut-kubernetes-operator?

0

There are 0 answers