Skip to content

Commit 6214d96

Browse files
committed
fix(scheduler): if one RC fails to scale then ensure all other RCs are at the right level
Previously only the failing RC would get fixed up but now the whole state will be reverted if one RC fails
1 parent c65c508 commit 6214d96

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

rootfs/api/models/app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,21 @@ def scale(self, user, structure): # noqa
331331
'Container type {} does not exist in application'.format(container_type))
332332

333333
# merge current structure and the new items together
334-
new_structure = self.structure.copy()
334+
old_structure = self.structure
335+
new_structure = old_structure.copy()
335336
new_structure.update(structure)
336337

337338
if new_structure != self.structure:
338339
# save new structure to the database
339340
self.structure = new_structure
340341
self.save()
341342

342-
self._scale_pods(structure)
343+
try:
344+
self._scale_pods(structure)
345+
except ServiceUnavailable:
346+
# scaling failed, go back to old scaling numbers
347+
self._scale_pods(old_structure)
348+
raise
343349

344350
msg = '{} scaled pods '.format(user.username) + ' '.join(
345351
"{}={}".format(k, v) for k, v in list(structure.items()))

rootfs/scheduler/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,8 @@ def scale(self, namespace, name, image, command, **kwargs):
243243
logger.exception("Creating RC {} failed}".format(name))
244244
raise
245245

246-
try:
247-
self._scale_rc(namespace, name, replicas)
248-
except KubeException:
249-
logger.exception("Scaling failed for {}".format(name))
250-
old = self.get_rc(namespace, name).json()
251-
self._scale_rc(namespace, name, old['spec']['replicas'])
252-
raise
246+
# let the scale failure bubble up
247+
self._scale_rc(namespace, name, replicas)
253248

254249
def _build_pod_manifest(self, namespace, name, image, **kwargs):
255250
app_type = kwargs.get('app_type')

0 commit comments

Comments
 (0)