From a0204212ad177ab4ceaa75b10b51b24fd12d031b Mon Sep 17 00:00:00 2001 From: Robert Stein Date: Tue, 16 May 2023 14:55:01 +0200 Subject: [PATCH 1/2] chore(#393): handle namespace creation error --- client/gefyra/cluster/manager.py | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/client/gefyra/cluster/manager.py b/client/gefyra/cluster/manager.py index c86f883a..fe84948d 100644 --- a/client/gefyra/cluster/manager.py +++ b/client/gefyra/cluster/manager.py @@ -28,19 +28,31 @@ def handle_serviceaccount( config: ClientConfiguration, serviceaccount: V1ServiceAccount ): - try: - config.K8S_CORE_API.create_namespaced_service_account( - body=serviceaccount, namespace=config.NAMESPACE - ) - except ApiException as e: - if e.status == 409: - pass - elif e.status == 403: - raise RuntimeError( - f"You're not allowed to create a serviceaccount in namespace {config.NAMESPACE}." + retries = 5 + wait = 5 + counter = 0 + while counter < retries: + try: + config.K8S_CORE_API.create_namespaced_service_account( + body=serviceaccount, namespace=config.NAMESPACE ) - else: - raise e + break + except ApiException as e: + if e.status == 409: + pass + elif e.status == 403: + # this sometimes happens when to cluster in terminating the gefyra namespace + # due to a previous `gefyra down`. As long as it is terminating this error occurs. + if counter > retries: + raise RuntimeError( + f"You're not allowed to create a serviceaccount in namespace {config.NAMESPACE}." + ) + else: + counter += 1 + time.sleep(wait) + continue + else: + raise e def handle_clusterrole(config: ClientConfiguration, clusterrole: V1ClusterRole): From c04bbcfe2b1c90aa17cfb3bb4c27ff3f6f11ff52 Mon Sep 17 00:00:00 2001 From: Robert Stein Date: Tue, 16 May 2023 15:30:55 +0200 Subject: [PATCH 2/2] fix: missing break --- client/gefyra/cluster/manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/gefyra/cluster/manager.py b/client/gefyra/cluster/manager.py index fe84948d..1c06feb7 100644 --- a/client/gefyra/cluster/manager.py +++ b/client/gefyra/cluster/manager.py @@ -39,7 +39,7 @@ def handle_serviceaccount( break except ApiException as e: if e.status == 409: - pass + break elif e.status == 403: # this sometimes happens when to cluster in terminating the gefyra namespace # due to a previous `gefyra down`. As long as it is terminating this error occurs.