Skip to content
This repository was archived by the owner on Oct 25, 2026. It is now read-only.

Commit a9a7e38

Browse files
authored
Merge pull request #6 from erkiaas/wildduck-operator-retry-api
wildduck-operator: retry on Wildduck API connection errors instead of crashing
2 parents 4c81a62 + ca7a6cb commit a9a7e38

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎samples/wildduck-operator/wildduck_operator.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python3
2-
from operatorlib import ClaimMixin, Operator, ReconcileError
2+
from operatorlib import ClaimMixin, MonitoringMixin, Operator, ReconcileError
33
import aiohttp
4+
import asyncio
45
import os
56

67

7-
class WildduckOperator(ClaimMixin, Operator):
8+
class WildduckOperator(ClaimMixin, MonitoringMixin, Operator):
89
OPERATOR = "wildduck-operator"
910
GROUP = "codemowers.cloud"
1011
VERSION = "v1beta1"
@@ -23,6 +24,21 @@ def get_claim_plural(cls):
2324

2425
@classmethod
2526
async def reconcile_claim(cls, api_client, co, body):
27+
# Wildduck API being temporarily unreachable (pod restart, node
28+
# reboot) is expected; retry instead of letting the connection
29+
# error propagate and kill the whole operator process
30+
backoff = 5
31+
while True:
32+
try:
33+
return await cls.reconcile_wildduck_user(api_client, co, body)
34+
except (aiohttp.ClientConnectionError, asyncio.TimeoutError) as e:
35+
print("Wildduck API unreachable, retrying in %d seconds: %s" % (
36+
backoff, e))
37+
await asyncio.sleep(backoff)
38+
backoff = min(backoff * 2, 300)
39+
40+
@classmethod
41+
async def reconcile_wildduck_user(cls, api_client, co, body):
2642
username = body["metadata"]["name"]
2743

2844
# TODO: Cleaner env var handling

0 commit comments

Comments
 (0)