Skip to content

Commit e9df6a6

Browse files
committed
ref(scheduler): separate deploy batch / step calculations into functions
1 parent 9001382 commit e9df6a6

2 files changed

Lines changed: 28 additions & 17 deletions

File tree

rootfs/api/models/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def deploy(self, release):
457457
'build_type': release.build.type,
458458
'healthcheck': release.config.healthcheck,
459459
'routable': routable,
460-
'batches': batches
460+
'deploy_batches': batches
461461
}
462462

463463
# Sort deploys so routable comes first

rootfs/scheduler/__init__.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,10 @@ def deploy(self, namespace, name, image, command, **kwargs): # noqa
124124
logger.info('No prior RC could be found for {}-{}'.format(namespace, app_type))
125125

126126
# see if application or global deploy batches are defined
127-
if not kwargs.get('batches', None):
128-
# figure out how many nodes the application can go on
129-
tags = kwargs.get('tags', {})
130-
steps = len(self.get_nodes(labels=tags).json()['items'])
131-
else:
132-
steps = int(kwargs.get('batches'))
133-
134-
# figure out what kind of batches the deploy is done in - 1 in, 1 out or higher
135-
if desired < steps:
136-
# do it all in one go
137-
batches = [desired]
138-
else:
139-
# figure out the stepped deploy count and then see if there is a leftover
140-
batches = [steps for n in set(range(1, (desired + 1))) if n % steps == 0]
141-
if desired - sum(batches) > 0:
142-
batches.append(desired - sum(batches))
127+
batches = kwargs.get('deploy_batches', None)
128+
tags = kwargs.get('tags', {})
129+
steps = self._get_deploy_steps(batches, tags)
130+
batches = self._get_deploy_batches(steps, desired)
143131

144132
try:
145133
count = 0
@@ -199,6 +187,29 @@ def cleanup_release(self, namespace, controller):
199187

200188
self.delete_pod(namespace, pod['metadata']['name'])
201189

190+
def _get_deploy_steps(self, batches, tags):
191+
# if there is no batch information available default to available nodes for app
192+
if not batches:
193+
# figure out how many nodes the application can go on
194+
steps = len(self.get_nodes(labels=tags).json()['items'])
195+
else:
196+
steps = int(batches)
197+
198+
return steps
199+
200+
def _get_deploy_batches(self, steps, desired):
201+
# figure out what kind of batches the deploy is done in - 1 in, 1 out or higher
202+
if desired < steps:
203+
# do it all in one go
204+
batches = [desired]
205+
else:
206+
# figure out the stepped deploy count and then see if there is a leftover
207+
batches = [steps for n in set(range(1, (desired + 1))) if n % steps == 0]
208+
if desired - sum(batches) > 0:
209+
batches.append(desired - sum(batches))
210+
211+
return batches
212+
202213
def _update_application_service(self, namespace, name, app_type, port, routable=False):
203214
"""Update application service with all the various required information"""
204215
service = self.get_service(namespace, namespace).json()

0 commit comments

Comments
 (0)