From 0967b1612f4046b7c50a3fb5d059c133e45d7f70 Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 9 Jul 2024 12:08:46 +0200 Subject: [PATCH 1/2] Retry kustomize execution misc: add simple retry mechanism for kustomize run --- make_argocd_fly/application.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/make_argocd_fly/application.py b/make_argocd_fly/application.py index 9442ecf..8423a25 100644 --- a/make_argocd_fly/application.py +++ b/make_argocd_fly/application.py @@ -132,19 +132,23 @@ def __init__(self, app_name: str, env_name: str, app_viewer: ResourceViewer = No log.debug('Created application {} of type {} for environment {}'.format(app_name, __class__.__name__, env_name)) - async def _run_kustomize(self, dir_path: str) -> str: - proc = await asyncio.create_subprocess_shell( - 'kustomize build --enable-helm {}'.format(dir_path), - stdout=asyncio.subprocess.PIPE, - stderr=asyncio.subprocess.PIPE) + async def _run_kustomize(self, dir_path: str, retries: int = 3) -> str: + for attempt in range(retries): + proc = await asyncio.create_subprocess_shell( + 'kustomize build --enable-helm {}'.format(dir_path), + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE) - stdout, stderr = await proc.communicate() + stdout, stderr = await proc.communicate() - if stderr: - log.error('Kustomize error: {}'.format(stderr)) - raise Exception + if stderr: + log.error('Kustomize error: {}'.format(stderr)) + log.info('Retrying {}/{}'.format(attempt + 1, retries)) + continue - return stdout.decode("utf-8") + return stdout.decode("utf-8") + else: + raise Exception('Kustomize run failed') async def prepare(self) -> str: config = get_config() From 5d14bb45641dff04dc1de3903d3454aa86da54a8 Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 9 Jul 2024 12:12:17 +0200 Subject: [PATCH 2/2] misc: use for/else properly --- make_argocd_fly/application.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/make_argocd_fly/application.py b/make_argocd_fly/application.py index 8423a25..a06dd5c 100644 --- a/make_argocd_fly/application.py +++ b/make_argocd_fly/application.py @@ -145,11 +145,12 @@ async def _run_kustomize(self, dir_path: str, retries: int = 3) -> str: log.error('Kustomize error: {}'.format(stderr)) log.info('Retrying {}/{}'.format(attempt + 1, retries)) continue - - return stdout.decode("utf-8") + break else: raise Exception('Kustomize run failed') + return stdout.decode("utf-8") + async def prepare(self) -> str: config = get_config() tmp_dir = config.get_tmp_dir()