Skip to content

Commit ad7fc55

Browse files
authored
fix(app): rollback all process types to previous version when one (or more) process type fails a deploy (#1027)
Previously only the failed process type would roll itself back, resulting in a scenario where worker may be on v6 and web on v5 This moves away from using the built in rollback functionality in Deployments and rather deploys the previous release again to get the same effect. Rollback in Deployments was taking it to the last good known deployment, in this case that'd be the latest for some types... knowing the revision of the last deploy would be hard as well. The way it works when deploying the old release is an identical replicaset (and thus identical template pod hash is generated) so things will very much so look like a native rollback. If the Controller has done any changes to how it constructs the pod manifest then this could generate a totally new ReplicaSet but that is also fine as it will be booting the previous release from DB Fixes #1013
1 parent 3f3a228 commit ad7fc55

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

rootfs/api/models/app.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def _scale_pods(self, scale_types):
470470
self.log(err, logging.ERROR)
471471
raise ServiceUnavailable(err) from e
472472

473-
def deploy(self, release, force_deploy=False):
473+
def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa
474474
"""
475475
Deploy a new release to this application
476476
@@ -569,8 +569,22 @@ def deploy(self, release, force_deploy=False):
569569
) for scale_type, kwargs in deploys.items()
570570
]
571571

572-
async_run(tasks)
572+
try:
573+
async_run(tasks)
574+
except KubeException as e:
575+
if rollback_on_failure:
576+
err = 'There was a problem deploying {}. Rolling back process types to release {}.'.format(version, "v{}".format(release.previous().version)) # noqa
577+
# This goes in the log before the rollback starts
578+
self.log(err, logging.ERROR)
579+
# revert all process types to old release
580+
self.deploy(release.previous(), force_deploy=True, rollback_on_failure=False)
581+
# let it bubble up
582+
raise DeisException('{}\n{}'.format(err, str(e))) from e
583+
584+
# otherwise just re-raise
585+
raise
573586
except Exception as e:
587+
# This gets shown to the end user
574588
err = '(app::deploy): {}'.format(e)
575589
self.log(err, logging.ERROR)
576590
raise ServiceUnavailable(err) from e

rootfs/scheduler/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,8 @@ def deploy(self, namespace, name, image, entrypoint, command, **kwargs): # noqa
181181
namespace, name, image, entrypoint, command, **kwargs
182182
)
183183
except KubeException as e:
184-
# rollback to the previous Deployment
185-
kwargs['rollback'] = True
186-
self.deployment.update(
187-
namespace, name, image, entrypoint, command, **kwargs
188-
)
189-
190184
raise KubeException(
191185
'There was a problem while deploying {} of {}-{}. '
192-
'Going back to the previous release. '
193186
"Additional information:\n{}".format(version, namespace, app_type, str(e))
194187
) from e
195188

0 commit comments

Comments
 (0)