kubernetes-client/java

Issue Creating A Watcher To List All Namespace Events

Closed this issue · 3 comments

This is almost certainly a misuse/misread of the API on my end (and I'll definitely close the ticket) but was wondering if I could get some guidance on this:

This is my code snippet/attempt at creating a watcher to list all namespace events in my cluster:

Call v1NamespaceListCall = coreV1Api.listEventForAllNamespacesCall(BOOKMARK_ENABLED, null,
                null, null, null, NO_PRETTY_PRINT, null, null, WATCH_ENABLED, null);
                
Watch<V1Event> watch = Watch.createWatch(coreApi.getApiClient(), v1NamespaceListCall,
                new TypeToken<Response<V1Event>>(){}.getType());

I'm getting an API exception when creating a Watcher:
Caused by: io.kubernetes.client.openapi.ApiException: at io.kubernetes.client.util.Watch.createWatch(Watch.java:105) without much more detail in the stack trace.

Am I creating a Watch of the incorrect type? I have a similar pod watcher that works fine but can't seem to be getting it to work for namespace events across a cluster.

You can use ApiException.getResponseBody() to hopefully get more details, the exception should also include a status code, which may give you some explanation about what is going wrong.

I'm honestly not sure if you can watch all namespaces, because that represents a bunch of different HTTP paths, so it's quite possible that watching all namespaces doesn't actually work at all.

What does the listEventForAllNamespacesCall accomplish then if I'm not able to watch the events of the cluster/all namespaces. I think I might be misunderstanding how Watchers work

Response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"events is forbidden: User \"beelau\" cannot watch resource \"events\" in API group \"\" at the cluster scope","reason":"Forbidden","details":{"kind":"events"},"code":403}

This is the response body. Have to look to RBAC