You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When developing Controller it should be able to resolve (reconcile) objects from all namespaces.
Actual Behaviour
The Controller implementation is not able to fetch object using provided OperatorResourceLister.
The following exception is thrown:
19:39:49.742 [all-namespaces-pod-operator-controller-1] INFO o.f.b.AllNamespacesReconciler - Reconciler for request: Request{name='local-path-provisioner-957fdf8bc-2dxj2', namespace='kube-system'}
19:39:49.743 [all-namespaces-pod-operator-controller-2] ERROR c.c.n.o.p.o.AllNamespacesReconciler - Reconciler failed
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 org.foo.bar.AllNamespacesReconciler.reconcile(AllNamespacesReconciler.java:33)
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)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1623)
The problem lies in implementation of get method in OperatorResourceLister class.
It will try to fetch or compute shared index informer. But informer is registered for all namespaces ("").
The request if for a particular object in a namespace. Which will result in non existing shared index informer, hence the NullPointerException.
Steps To Reproduce
Simple operator to listen for pods in all namespaces.
@Operator(
name = "all-namespaces-pod-operator",
informer = @Informer(apiType = V1Pod.class, apiListType = V1PodList.class, namespace = Informer.ALL_NAMESPACES))
public class AllNamespacesReconciler implements ResourceReconciler<V1Pod> {
private static final Logger log = LoggerFactory.getLogger(AllNamespacesReconciler.class);
@Override
public @NonNull Result reconcile(@NonNull Request request, @NonNull OperatorResourceLister<V1Pod> lister) {
try {
log.info("Reconciler for request: " + request);
var pod = lister.get(request);
log.info("Pod\n" + pod);
return new Result(false, null);
} catch (Exception e) {
log.error("Reconciler failed", e);
return new Result(true, Duration.ofSeconds(5));
}
}
}
The text was updated successfully, but these errors were encountered:
tired-old-man
changed the title
Controller for all namespaces can't fetch resource from indexer
Controller for all namespaces can't get object from indexer using provided OperatorResourceLister
Sep 18, 2023
Expected Behavior
When developing Controller it should be able to resolve (reconcile) objects from all namespaces.
Actual Behaviour
The Controller implementation is not able to fetch object using provided OperatorResourceLister.
The following exception is thrown:
The problem lies in implementation of get method in OperatorResourceLister class.
It will try to fetch or compute shared index informer. But informer is registered for all namespaces ("").
The request if for a particular object in a namespace. Which will result in non existing shared index informer, hence the NullPointerException.
Steps To Reproduce
Simple operator to listen for pods in all namespaces.
Environment Information
OS: Windows 11 / WSL 2 (Ubuntu)
Example Application
No response
Version
4.1.1
The text was updated successfully, but these errors were encountered: