javascript
javascript copied to clipboard
watch monitors the deployment, does not end the monitoring manually, but stops monitoring by itself
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"
Added: the type and apiObj parameters in the callback branch all return undefined, and only watchObj returns data. Is this normal?
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.
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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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: 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/staleis applied- After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied- After 30d of inactivity since
lifecycle/rottenwas applied, the issue is closedYou 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.