javascript icon indicating copy to clipboard operation
javascript copied to clipboard

watch monitors the deployment, does not end the monitoring manually, but stops monitoring by itself

Open vicky-rain opened this issue 2 years ago • 5 comments

watch monitors deployment, does not end monitoring manually, stops monitoring by itself

The following is the sample code, why after running the callback branch, it will directly enter the done branch, I did not manually close the watch monitoring

The desired effect is that the watch can continuously monitor the status changes of the deployment

import * as k8s from '@kubernetes/client-node';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const watch = new k8s.Watch(kc);
const main = async () => {
    try {
	const namespace = "default";
	const templateName = "deployment-name";
        const req = await watch.watch(
            `/apis/apps/v1/namespaces/${namespace}/deployments/${templateName}`,
            {},
            (type, apiObj, watchObj) => {
                console.log(watchObj);
            },
            (done) => {
		console.log(done);
	    },
        );
    } catch (err) {
        console.error(err);
    }
};
main();

"@kubernetes/client-node": "^0.18.1"

vicky-rain avatar Aug 17 '23 03:08 vicky-rain

Added: the type and apiObj parameters in the callback branch all return undefined, and only watchObj returns data. Is this normal?

vicky-rain avatar Aug 17 '23 03:08 vicky-rain

Watch is performed on a collection (e.g. deployments) not a single instance.

If you want to watch a single instance, you can use a field selector (or other mechanism) to watch for changes to a specific resource.

There is a discussion here: https://github.com/kubernetes/kubernetes/issues/43299

Which may be useful.

There is a simple watch example here: https://github.com/kubernetes-client/javascript/blob/master/examples/typescript/watch/watch-example.ts

Which you may want to use as a starting point.

brendandburns avatar Aug 17 '23 03:08 brendandburns

I am facing the same issue I have tried executing the watch example but after printing out the current namespaces it aborts on its own....there is no monitoring happening

Ananya2001-an avatar Oct 08 '23 12:10 Ananya2001-an

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jan 29 '24 22:01 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Feb 28 '24 23:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Mar 29 '24 23:03 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 29 '24 23:03 k8s-ci-robot