Skip to content

Commit 2c1ae82

Browse files
author
Gabriel Monroy
committed
fix(controller): add retries on container creation
1 parent f5d86a7 commit 2c1ae82

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

controller/scheduler/coreos.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
MATCH = re.compile(
1313
'(?P<app>[a-z0-9-]+)_?(?P<version>v[0-9]+)?\.?(?P<c_type>[a-z-_]+)?.(?P<c_num>[0-9]+)')
14+
RETRIES = 3
1415

1516

1617
class UHTTPConnection(httplib.HTTPConnection):
@@ -133,8 +134,14 @@ def _create_container(self, name, image, command, unit, **kwargs):
133134
tagset = ' '.join(['"{}={}"'.format(k, v) for k, v in tags.items()])
134135
unit.append({"section": "X-Fleet", "name": "MachineMetadata",
135136
"value": tagset})
136-
# post unit to fleet
137-
self._put_unit(name, {"desiredState": "launched", "options": unit})
137+
# post unit to fleet and retry
138+
for attempt in range(RETRIES):
139+
try:
140+
self._put_unit(name, {"desiredState": "launched", "options": unit})
141+
break
142+
except:
143+
if attempt == (RETRIES - 1): # account for 0 indexing
144+
raise
138145

139146
def start(self, name):
140147
"""Start a container"""
@@ -153,7 +160,7 @@ def _wait_for_container(self, name):
153160
raise RuntimeError('container failed to start')
154161
time.sleep(1)
155162
else:
156-
raise RuntimeError('container failed to start')
163+
raise RuntimeError('container timeout on start')
157164

158165
def _wait_for_destroy(self, name):
159166
for _ in range(30):

0 commit comments

Comments
 (0)