Kubernetes-client: Cannot watch Ingresses with api version networking.k8s.io/v1beta1

Created on 24 May 2020  路  5Comments  路  Source: fabric8io/kubernetes-client

Watching ingresses with api version networking.k8s.io/v1beta1 results in a ClassCastException.

The issue seems to be in io.fabric8.kubernetes.internal.KubernetesDeserializer.getTypeForKey("networking.k8s.io/v1beta1#Ingress") which removes the api version, then call getInternalTypeForName("Ingress") which naively iterates through all the packages in search of a class called Ingress found in io.fabric8.kubernetes.api.model.extensions which happens to be in the packages list before io.fabric8.kubernetes.api.model.networking .

Code in question

    # key value: networking.k8s.io/v1beta1#Ingress

    private static Class getTypeForKey(String key) {
        Class<? extends KubernetesResource> result = MAP.get(key);
        if (result == null) {
            String name = key != null && key.contains(KEY_SEPARATOR) ?
                key.substring(key.indexOf(KEY_SEPARATOR) + 1) :
                key;

            result = getInternalTypeForName(name);
        }

        if (result != null) {
            MAP.put(key, result);
        }
        return result;
    }

    private static Class getInternalTypeForName(String name) {

      for (String aPackage : PACKAGES) {
        Class result = loadClassIfExists(aPackage + name);
        if (result != null) {
          return result;
        }
      }

        return null;
    } 

Stacktrace

java.lang.ClassCastException: io.fabric8.kubernetes.api.model.extensions.Ingress cannot be cast to io.fabric8.kubernetes.api.model.networking.v1beta1.Ingress
    at com.example.IngressWatcher.eventReceived(IngressWatcher.java:29)
    at io.fabric8.kubernetes.client.utils.WatcherToggle.eventReceived(WatcherToggle.java:49)
    at io.fabric8.kubernetes.client.dsl.internal.WatchConnectionManager$1.onMessage(WatchConnectionManager.java:237)
    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.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)

Kubernetes client version

4.10.1

Most helpful comment

@rohanKanojia confirming that the issue is fixed. Thanks

All 5 comments

Umm, strange. Could you please share code you used to reproduce this error?

This somehow seems related to https://github.com/fabric8io/kubernetes-client/issues/2251 . Need to check what's wrong in KubernetesDeserializer;

@jumal : I just checked with v4.10.2 and I couldn't reproduce this issue. Could you please check with new released version?

Closing this issue. Feel free to reopen if you face this issue on 4.10.2

@rohanKanojia confirming that the issue is fixed. Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangyang0918 picture wangyang0918  路  33Comments

jsimao71 picture jsimao71  路  15Comments

chenchun picture chenchun  路  28Comments

sleshchenko picture sleshchenko  路  24Comments

rainer-maierhofer picture rainer-maierhofer  路  20Comments