Skip to content

Commit 5821726

Browse files
committed
Merge pull request #665 from helgi/faster_deploy
feat(deploy): support doing a larger number than 1 in, 1 out deployment
2 parents f15b194 + 55f4256 commit 5821726

3 files changed

Lines changed: 39 additions & 15 deletions

File tree

rootfs/api/models/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ def deploy(self, release):
341341
self.structure = self._default_structure(release)
342342
self.save()
343343

344+
# see if the app config has deploy batch preference, otherwise use global
345+
batches = release.config.values.get('DEPLOY_BATCHES', settings.DEPLOY_BATCHES)
346+
344347
# deploy application to k8s. Also handles initial scaling
345348
deploys = {}
346349
build_type = app_build_type(release)
@@ -357,7 +360,8 @@ def deploy(self, release):
357360
'build_type': build_type,
358361
'healthcheck': release.config.healthcheck(),
359362
# http://docs.deis.io/en/latest/using_deis/process-types/#web-vs-cmd-process-types
360-
'routable': True if scale_type in ['web', 'cmd'] else False
363+
'routable': True if scale_type in ['web', 'cmd'] else False,
364+
'batches': batches
361365
}
362366

363367
# Sort deploys so routable comes first

rootfs/deis/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@
268268
SLUG_BUILDER_IMAGE_PULL_POLICY = os.environ.get('SLUG_BUILDER_IMAGE_PULL_POLICY', "Always") # noqa
269269
DOCKER_BUILDER_IMAGE_PULL_POLICY = os.environ.get('DOCKER_BUILDER_IMAGE_PULL_POLICY', "Always") # noqa
270270

271+
# Define a global default on how many pods to bring up and then
272+
# take down sequentially during a deploy
273+
# Defaults to None, the default is to deploy to as many nodes as
274+
# the application has been instructed to run on
275+
# Can also be overwritten on per app basis if desired
276+
DEPLOY_BATCHES = os.environ.get('DEPLOY_BATCHES', None)
277+
271278
# How long k8s waits for a pod to finish work after a SIGTERM before sending SIGKILL
272279
KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS = int(os.environ.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', 30)) # noqa
273280

rootfs/scheduler/__init__.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -367,27 +367,40 @@ def deploy(self, namespace, name, image, command, **kwargs): # noqa
367367
desired = kwargs['replicas']
368368
logger.debug('No prior RC could be found for {}-{}'.format(namespace, app_type))
369369

370+
# see if application or global deploy batches are defined
371+
if not kwargs.get('batches', None):
372+
# figure out how many nodes the application can go on
373+
tags = kwargs.get('tags', {})
374+
steps = len(self._get_nodes(labels=tags).json()['items'])
375+
else:
376+
steps = int(kwargs.get('batches'))
377+
378+
# figure out what kind of batches the deploy is done in - 1 in, 1 out or higher
379+
if desired < steps:
380+
# do it all in one go
381+
batches = [desired]
382+
else:
383+
# figure out the stepped deploy count and then see if there is a leftover
384+
batches = [steps for n in set(range(1, (desired + 1))) if n % steps == 0]
385+
if desired - sum(batches) > 0:
386+
batches.append(desired - sum(batches))
387+
370388
try:
371-
count = 1
372-
while desired >= count:
389+
count = 0
390+
new_name = new_rc["metadata"]["name"]
391+
for batch in batches:
392+
count += batch
373393
logger.debug('scaling release {} to {} out of final {}'.format(
374-
new_rc["metadata"]["name"], count, desired
375-
))
376-
self._scale_rc(namespace, new_rc["metadata"]["name"], count)
377-
logger.debug('scaled up pod number {} for {}'.format(
378-
count, new_rc["metadata"]["name"]
394+
new_name, count, desired
379395
))
396+
self._scale_rc(namespace, new_name, count)
380397

381398
if old_rc:
399+
old_name = old_rc["metadata"]["name"]
382400
logger.debug('scaling old release {} from original {} to {}'.format(
383-
old_rc["metadata"]["name"], desired, (desired-count))
401+
old_name, desired, (desired-count))
384402
)
385-
self._scale_rc(namespace, old_rc["metadata"]["name"], (desired-count))
386-
logger.debug('scaled down pod number {} for {}'.format(
387-
count, old_rc["metadata"]["name"]
388-
))
389-
390-
count += 1
403+
self._scale_rc(namespace, old_name, (desired-count))
391404
except Exception as e:
392405
# New release is broken. Clean up
393406
logger.error('Could not scale {} to {}. Deleting and going back to old release'.format(

0 commit comments

Comments
 (0)