Skip to content

Commit

Permalink
Merge pull request #394 from gefyrahq/#393
Browse files Browse the repository at this point in the history
chore(#393): handle namespace creation error
  • Loading branch information
SteinRobert committed May 16, 2023
2 parents a1a6c02 + c04bbcf commit 1c7ef33
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions client/gefyra/cluster/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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.
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):
Expand Down

0 comments on commit 1c7ef33

Please sign in to comment.