Skip to content

Commit 2c1ac8d

Browse files
committed
Fix race condition in creating subscriptions
1 parent c85db82 commit 2c1ac8d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/mas/devops/olm.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,18 @@ def applySubscription(dynClient: DynamicClient, namespace: str, packageName: str
193193
catalog_namespace=catalogSourceNamespace
194194
)
195195
subscription = yaml.safe_load(renderedTemplate)
196-
subscriptionsAPI.apply(body=subscription, namespace=namespace)
196+
197+
# apply should work regardless of if the subscription already exists or not,
198+
# however if two parallel processes call it at the same time it can result
199+
# in a 409 error in that case trying again will resolve the issue
200+
try:
201+
subscriptionsAPI.apply(body=subscription, namespace=namespace)
202+
except Exception as e:
203+
if "409" in str(e) or "AlreadyExists" in str(e):
204+
logger.warning(f"Subscription {name} already exists and produced a conflict, retrying the apply")
205+
subscriptionsAPI.apply(body=subscription, namespace=namespace)
206+
else:
207+
raise
197208

198209
# Wait for InstallPlan to be created
199210
logger.debug(f"Waiting for {packageName}.{namespace} InstallPlans")

0 commit comments

Comments
 (0)