Skip to content

Commit

Permalink
(from AES) Retry apply_kube_artifacts at most one time
Browse files Browse the repository at this point in the history
  • Loading branch information
esmet committed Apr 8, 2021
1 parent 1135121 commit 066fabf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions python/tests/kubeutils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tempfile

from runutils import run_and_assert
from runutils import run_with_retry

def meta_action_kube_artifacts(namespace, artifacts, action):
def meta_action_kube_artifacts(namespace, artifacts, action, retries=0):
temp_file = tempfile.NamedTemporaryFile()
temp_file.write(artifacts.encode())
temp_file.flush()
Expand All @@ -14,12 +14,12 @@ def meta_action_kube_artifacts(namespace, artifacts, action):
if namespace is not None:
command.extend(['-n', namespace])

run_and_assert(command)
run_with_retry(command, retries=retries)
temp_file.close()


def apply_kube_artifacts(namespace, artifacts):
meta_action_kube_artifacts(namespace=namespace, artifacts=artifacts, action='apply')
meta_action_kube_artifacts(namespace=namespace, artifacts=artifacts, action='apply', retries=1)


def delete_kube_artifacts(namespace, artifacts):
Expand Down
5 changes: 3 additions & 2 deletions python/tests/runutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def run_and_assert(command, communicate=True):
return stdout.decode("utf-8") if stdout is not None else None
return None

def run_with_retry(command):
def run_with_retry(command, retries=0):
print(f"Running command {command}")
returncode = -1
decoded = ""
tries = 0
while returncode != 0 and tries < 3:
max_tries = retries + 1
while returncode != 0 and tries < max_tries:
output = subprocess.Popen(command, stdout=subprocess.PIPE)
if tries > 0:
print('SLEEPING 5 seconds, TRIES=%d' % tries)
Expand Down

0 comments on commit 066fabf

Please sign in to comment.