operator-framework / java-operator-sdk

Java SDK for building Kubernetes Operators
https://javaoperatorsdk.io/
Apache License 2.0
800 stars 215 forks source link

NullPointer exception after implementing the Updater interface in a Dependent resource #1611

Closed juangon closed 1 year ago

juangon commented 1 year ago

Bug Report

What did you do?

After implementing the Updater interface in a DependentResource, I see a NulllPointer:

2022-11-18 09:46:00,207 ERROR [io.fab.kub.cli.inf.cac.SharedProcessor] (OkHttp https://10.0.0.1/...) Failed invoking io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource@50aa0bf5 event handler: null: java.lang.NullPointerException
    at io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource.lambda$temporaryCacheHasResourceWithSameVersionAs$2(InformerEventSource.java:177)
    at java.base/java.util.Optional.map(Optional.java:265)
    at io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource.temporaryCacheHasResourceWithSameVersionAs(InformerEventSource.java:175)
    at io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource.onAddOrUpdate(InformerEventSource.java:152)
    at io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource.onUpdate(InformerEventSource.java:126)
    at io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource.onUpdate(InformerEventSource.java:67)
    at io.fabric8.kubernetes.client.informers.cache.ProcessorListener$UpdateNotification.handle(ProcessorListener.java:85)
    at io.fabric8.kubernetes.client.informers.cache.ProcessorListener.add(ProcessorListener.java:47)
    at io.fabric8.kubernetes.client.informers.cache.SharedProcessor.lambda$distribute$0(SharedProcessor.java:79)
    at io.fabric8.kubernetes.client.informers.cache.SharedProcessor.lambda$distribute$1(SharedProcessor.java:101)
    at io.fabric8.kubernetes.client.utils.SerialExecutor.lambda$execute$0(SerialExecutor.java:40)
    at io.fabric8.kubernetes.client.utils.SerialExecutor.scheduleNext(SerialExecutor.java:52)
    at io.fabric8.kubernetes.client.utils.SerialExecutor.execute(SerialExecutor.java:46)
    at io.fabric8.kubernetes.client.informers.cache.SharedProcessor.distribute(SharedProcessor.java:98)
    at io.fabric8.kubernetes.client.informers.cache.SharedProcessor.distribute(SharedProcessor.java:79)
    at io.fabric8.kubernetes.client.informers.cache.ProcessorStore.update(ProcessorStore.java:67)
    at io.fabric8.kubernetes.client.informers.cache.ProcessorStore.update(ProcessorStore.java:31)
    at io.fabric8.kubernetes.client.informers.cache.Reflector$ReflectorWatcher.eventReceived(Reflector.java:164)
    at io.fabric8.kubernetes.client.informers.cache.Reflector$ReflectorWatcher.eventReceived(Reflector.java:143)
    at io.fabric8.kubernetes.client.utils.WatcherToggle.eventReceived(WatcherToggle.java:49)
    at io.fabric8.kubernetes.client.dsl.internal.AbstractWatchManager.eventReceived(AbstractWatchManager.java:210)
    at io.fabric8.kubernetes.client.dsl.internal.AbstractWatchManager.onMessage(AbstractWatchManager.java:316)
    at io.fabric8.kubernetes.client.dsl.internal.WatcherWebSocketListener.onMessage(WatcherWebSocketListener.java:68)
    at io.fabric8.kubernetes.client.okhttp.OkHttpWebSocketImpl$BuilderImpl$1.onMessage(OkHttpWebSocketImpl.java:97)
    at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.java:322)
    at okhttp3.internal.ws.WebSocketReader.readMessageFrame(WebSocketReader.java:219)
    at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:105)
    at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:273)
    at okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:209)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

This is in a ConfigMap DependentResource. when updating somewhere else through KubernetesClient edit method it throws this error. When updating the configmap manually it works fine.

What did you expect to see?

No errors

What did you see instead? Under which circumstances?

A NullPointerException

Environment

Kubernetes cluster type:

Vanilla

$ Mention java-operator-sdk version from pom.xml file

4.0.5

$ java -version

11

$ kubectl version

Possible Solution

Additional context

juangon commented 1 year ago

Interesting, it works the first time I update the Dependent ConfigMap, it happens the second time I update it. I think I don't touch resourceVersion...

juangon commented 1 year ago

Should I increase resourceVersion or something?

juangon commented 1 year ago

Gonna close this issue. It was caused by my wrong code in Updater.update method in dependent resource. Basically I was getting the configmap from the "desired" ConfigMap which has a null resourceVersion.