Skip to content

Commit

Permalink
Catch resource too old error.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhellander committed Apr 22, 2024
1 parent 0ee8756 commit a54c7fc
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,50 @@ def sync_all_statuses():
def init_event_listener():
resource_version = ""
while True:
for event in w.stream(
api.list_namespaced_pod,
namespace=namespace,
label_selector=label_selector,
timeout_seconds=20,
resource_version=resource_version,
):
pod = event["object"]

resource_version = pod.metadata.resource_version
status = get_status(pod)

logging.info(f"Synchronizing status: {status}")

# status = pod.status.phase
release = pod.metadata.labels["release"]

event_type = event["type"]

if latest_status.get(release) == status:
logging.info("Status not changed, skipping...")

latest_status[release] = status

if event_type != "DELETED":
logging.info(f"EVENT_TYPE: {event_type}")
logging.info(f"STATUS: {status}")

data = {
"release": release,
"status": status,
}

post(APP_STATUS_URL, data=data)
try:
for event in w.stream(
api.list_namespaced_pod,
namespace=namespace,
label_selector=label_selector,
timeout_seconds=20,
resource_version=resource_version,
):
pod = event["object"]

resource_version = pod.metadata.resource_version
status = get_status(pod)

logging.info(f"Synchronizing status: {status}")

# status = pod.status.phase
release = pod.metadata.labels["release"]

event_type = event["type"]

if latest_status.get(release) == status:
logging.info("Status not changed, skipping...")

latest_status[release] = status

if event_type != "DELETED":
logging.info(f"EVENT_TYPE: {event_type}")
logging.info(f"STATUS: {status}")

data = {
"release": release,
"status": status,
}

post(APP_STATUS_URL, data=data)
except client.exceptions.ApiException as e:
if e.status == 410:
# If the resource version is too old, log the issue and reset resource_version
logging.error("Resource version expired, restarting watch from latest version.")
resource_version = None
else:
logging.error(f"An error occurred: {e}")
continue



def get_status(pod):
Expand Down

0 comments on commit a54c7fc

Please sign in to comment.