javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Watching individual custom resource not working correctly

Open eoifoe opened this issue 4 years ago • 4 comments

Hey guys, hope you all are well! From kube docs, it seems like a watch can be specified on any arbitrary resource, not just lists. I'm just curious if this is a misconception of mine, but whenever I try to put a watch on a specific resource, I get an error from the client.

Thanks for your help!

Describe the bug When I try to watch a specifc namespaced scoped custom resource via watch api with url of /apis/GROUP/VERSION/namespaces/NAMESPACE/RESOURCETYPE/NAME, I get an error of undefined.

Client Version 0.16.3

Server Version v1.22.9

To Reproduce Create a CRD, create a CR of kind CRD, and try to use watch on the object.

Expected behavior A watch is started for the specific resource

Example Code

import * as k8s from '@kubernetes/client-node';

const kc = new k8s.KubeConfig();
kc.loadFromOptions({...snip});

const watch = new k8s.Watch(kc);
watch.watch(`/apis/${GROUP}/${VERSION}/namespaces/${NAMESPACE}/${PLURAL}/${CR_NAME}`,
  {},
  onEvent,
  onDone,
);

...snip

Environment (please complete the following information):

  • OS: MacOS 12.4
  • NodeJS Version: 18
  • Runtime: Kind cluster

Additional context n/a

eoifoe avatar Jun 18 '22 20:06 eoifoe

Can you send the stack trace that you see?

brendandburns avatar Jun 20 '22 14:06 brendandburns

Hello there. I can confirm that this is not actually happening from an error, and is actually happening from a close event being emitted on the stream, therefore, there is no trace. I'm suspecting it's something on my end with setting up a watch on a specific CR. Maybe that can be looked more into? Does this seem right?

watch.watch(`/apis/${GROUP}/${VERSION}/namespaces/${NAMESPACE}/${PLURAL}/${CR_NAME}`,
  {},
  onEvent,
  onDone,
);

eoifoe avatar Jun 21 '22 11:06 eoifoe

@eoifoe

I was curious about this issue and looked into it. Individual resource watch was closed as you say. But that is the same situation for native resources, not just CR. It seems that individual resource watch is deprecated. (I have not checked whether individual resource WATCH endpoints currently exist or not.) Please refer to the documentation. https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#watch-pod-v1-core

If you use the fieldSelector in the Watch List instead, it should work fine.

watch.watch(`/apis/${GROUP}/${VERSION}/namespaces/${NAMESPACE}/${PLURAL}`,
  {fieldSelector: `metadata.name=${CR_NAME}`}
  onEvent,
  onDone,
);

uesyn avatar Jun 23 '22 11:06 uesyn

@eoifoe

I was curious about this issue and looked into it. Individual resource watch was closed as you say. But that is the same situation for native resources, not just CR. It seems that individual resource watch is deprecated. (I have not checked whether individual resource WATCH endpoints currently exist or not.) Please refer to the documentation. https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#watch-pod-v1-core

If you use the fieldSelector in the Watch List instead, it should work fine.

watch.watch(`/apis/${GROUP}/${VERSION}/namespaces/${NAMESPACE}/${PLURAL}`,
  {fieldSelector: `metadata.name=${CR_NAME}`}
  onEvent,
  onDone,
);

Ahh thank you very much 🙏. I suppose then the Kube docs I was linking earlier was outdated.

Cheers! 😄

eoifoe avatar Jun 23 '22 11:06 eoifoe