Watch Stream does not show recent DELETED or MODIFIED events when restarted, only shows ADDED
What happened (please include outputs or screenshots):
The watch stream method does not show past DELETED or MODIFIED events when the watch is restarted.
If watch.Watch.stream() is running during the event it shows, but if you restart it, out of the older event only ADDED shows. So we are seeing past events, but only of type ADDED.
What you expected to happen:
I expect the DELETED and MODIFIED events to show for events that occurred before the watch was started. This is the same behaviour as kubectl get events -w.
How to reproduce it (as minimally and precisely as possible):
from kubernetes import client, config, watch
config.load_kube_config()
custom_objects_api = client.CustomObjectsApi()
w = watch.Watch()
NAMESPACE = "ncdc-015197-sit"
API_VERSION = "v1beta1"
PLURAL = "bigquerydatasets"
GROUP = "bigquery.cnrm.cloud.google.com"
for event in w.stream(
custom_objects_api.list_namespaced_custom_object,
GROUP,
API_VERSION,
NAMESPACE,
PLURAL,
):
print(
f"name: {event['object']['metadata']['name']} , type: {event['type']}")
if event["type"] == "DELETED":
print("DETECTED deleted")
Ran a short python script above titled test-events.py



I ran the script at 10:05 first opening the watch, then applying my custom resource, followed by deleting it. The ADDED, MODIFIED and DELETED events all show while the stream() is running.
reran the script at 10:06, only get the ADDED events from the past, not DELETED or MODIFIED. Contrast that to the behavior of kubectl get events -w, where I get all past events before streaming updates for new events.
reran the script at 10:15 and 10:16 to confirm the same behaviour again as above.
Anything else we need to know?:
Environment:
- Kubernetes version (
kubectl version): server version is 1.23, git_version: v1.23.9-gke.2100 - OS (e.g., MacOS 10.13.6): MacOS Monterey v12.5.1
- Python version (
python --version): 3.10.6 - Python client version (
pip list | grep kubernetes): 23.3.0
/assign @roycaihw
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs 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 or PR as fresh with
/remove-lifecycle stale - Mark this issue or PR as rotten with
/lifecycle rotten - Close this issue or PR with
/close - Offer to help out with Issue Triage
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
/remove-lifecycle stale
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
/remove-lifecycle rotten
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.