Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes client extension: JsonMappingException in native mode #3077

Closed
fstab opened this issue Jul 3, 2019 · 9 comments · Fixed by #3085
Closed

Kubernetes client extension: JsonMappingException in native mode #3077

fstab opened this issue Jul 3, 2019 · 9 comments · Fixed by #3085
Assignees
Labels
kind/bug Something isn't working
Milestone

Comments

@fstab
Copy link
Contributor

fstab commented Jul 3, 2019

I created a minimal project with the new Fabric8 Kubernetes Client extension. When I watch Pods, I get the following error:

Could not deserialize watch event: ...
com.fasterxml.jackson.databind.JsonMappingException: No resource type found for:v1#Pod
 at [Source: (String)"{"type":"ADDED","object":{"kind":"Pod","apiVersion":"v1","metadata":{"name":"operator-example-7fb6446744-969t5","generateName":"operator-example-7fb6446744-","namespace":"default","selfLink":"/api/v1/namespaces/default/pods/operator-example-7fb6446744-969t5","uid":"2d6e35d4-9d6a-11e9-ab7b-0242e3a6ea5b","resourceVersion":"4772","creationTimestamp":"2019-07-03T08:11:36Z","labels":{"app":"operator-example","pod-template-hash":"7fb6446744"},"ownerReferences":[{"apiVersion":"apps/v1","kind":"ReplicaS"[truncated 2069 chars]; line: 1, column: 2567] (through reference chain: io.fabric8.kubernetes.api.model.WatchEvent["object"])
        at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:1718)
        at io.fabric8.kubernetes.internal.KubernetesDeserializer.deserialize(KubernetesDeserializer.java:78)
        at io.fabric8.kubernetes.internal.KubernetesDeserializer.deserialize(KubernetesDeserializer.java:32)
        at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004)
        at io.fabric8.kubernetes.client.dsl.internal.WatchHTTPManager.readWatchEvent(WatchHTTPManager.java:293)
        at io.fabric8.kubernetes.client.dsl.internal.WatchConnectionManager$1.onMessage(WatchConnectionManager.java:224)
        at okhttp3.internal.ws.RealWebSocket.onReadMessage(RealWebSocket.java:323)
        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:274)
        at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:214)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:206)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)

This is reproducable with the following minimal Java code:

package com.instana.operator.example;

import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.Watcher;
import io.quarkus.runtime.StartupEvent;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;

@ApplicationScoped
public class PodWatcher {

  void onStartup(@Observes StartupEvent _ev) {
    new Thread(this::watchPods).start();
  }

  private void watchPods() {
    KubernetesClient client = new DefaultKubernetesClient().inNamespace("default");
    client.pods().watch(new Watcher<Pod>() {
      @Override
      public void eventReceived(Action action, Pod pod) {
        System.out.println("Received " + action + " event for Pod " + pod.getMetadata().getName());
      }

      @Override
      public void onClose(KubernetesClientException e) {
        e.printStackTrace();
        System.exit(-1);
      }
    });
  }
}

The code works when I run it on the JVM instead of native mode.

@fstab fstab added the kind/bug Something isn't working label Jul 3, 2019
@fstab
Copy link
Contributor Author

fstab commented Jul 3, 2019

pod-watcher.tar.gz
Attaching the example project to reproduce. The deploy/ directory contains the necessary deployment yamls.

@gsmet
Copy link
Member

gsmet commented Jul 3, 2019

@geoand this one is for you :).

@geoand
Copy link
Contributor

geoand commented Jul 3, 2019

I'll take a look!

@geoand
Copy link
Contributor

geoand commented Jul 3, 2019

It looks like a "problem" in the Kubernetes Client which tries to dynamically load classes upon deserialization.
I'll see if we can fix it here with some kind of substitution, otherwise we'll need to take care of it upstream.

@geoand
Copy link
Contributor

geoand commented Jul 3, 2019

@fstab #3085 should take care of your issue (I tested it with your reproducer)

@fstab
Copy link
Contributor Author

fstab commented Jul 3, 2019

Great, thanks!

@geoand
Copy link
Contributor

geoand commented Jul 3, 2019

You are welcome!

geoand added a commit to geoand/quarkus that referenced this issue Jul 4, 2019
geoand added a commit to geoand/quarkus that referenced this issue Jul 4, 2019
geoand added a commit to geoand/quarkus that referenced this issue Jul 8, 2019
geoand added a commit to geoand/quarkus that referenced this issue Jul 8, 2019
geoand added a commit to geoand/quarkus that referenced this issue Jul 8, 2019
gsmet added a commit that referenced this issue Jul 9, 2019
Ensure that Kubernetes Watchers work properly
@gsmet gsmet added this to the 0.19.0 milestone Jul 9, 2019
@calohmn
Copy link

calohmn commented Aug 11, 2021

I've encountered this issue in a multi module maven project.
The Watcher<Pod> is defined in a base module, without any quarkus dependencies.
That module gets used in the module with the quarkus application.

When building the quarkus module with -Dorg.slf4j.simpleLogger.log.io.quarkus.maven.BuildMojo=debug, I see that the found "Watched classes" are empty:

[DEBUG] [io.quarkus.kubernetes.client.deployment.KubernetesClientProcessor] Watched Classes:

.

When I add a dummy Watcher<Pod> in the quarkus application, the build output is as expected:

[DEBUG] [io.quarkus.kubernetes.client.deployment.KubernetesClientProcessor] Watched Classes:
io.fabric8.kubernetes.api.model.Pod

and also the Watcher from the base module works as expected.

@geoand Is this a known limitation here or is there another way to make this work?

@geoand
Copy link
Contributor

geoand commented Aug 11, 2021

I would suggest opening a new issue with a reproducer project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants