Skip to content

Commit 67c5471

Browse files
authored
chore(scheduler): move lower level deploy helpers into their respective resources (#1092)
1 parent 9baa3d3 commit 67c5471

3 files changed

Lines changed: 59 additions & 59 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -348,59 +348,5 @@ def run(self, namespace, name, image, entrypoint, command, **kwargs):
348348
# cleanup
349349
self.pod.delete(namespace, name)
350350

351-
def _get_deploy_steps(self, batches, tags):
352-
# if there is no batch information available default to available nodes for app
353-
if not batches:
354-
# figure out how many nodes the application can go on
355-
steps = len(self.node.get(labels=tags).json()['items'])
356-
else:
357-
steps = int(batches)
358-
359-
return steps
360-
361-
def _get_deploy_batches(self, steps, desired):
362-
# figure out what kind of batches the deploy is done in - 1 in, 1 out or higher
363-
if desired < steps:
364-
# do it all in one go
365-
batches = [desired]
366-
else:
367-
# figure out the stepped deploy count and then see if there is a leftover
368-
batches = [steps for n in set(range(1, (desired + 1))) if n % steps == 0]
369-
if desired - sum(batches) > 0:
370-
batches.append(desired - sum(batches))
371-
372-
return batches
373-
374-
def _deploy_probe_timeout(self, timeout, namespace, labels, containers):
375-
"""
376-
Added in additional timeouts based on readiness and liveness probe
377-
378-
Uses the max of the two instead of combining them as the checks are stacked.
379-
"""
380-
381-
container_name = '{}-{}'.format(labels['app'], labels['type'])
382-
container = self.pod.find_container(container_name, containers)
383-
384-
# get health info from container
385-
added_timeout = []
386-
if 'readinessProbe' in container:
387-
# If there is initial delay on the readiness check then timeout needs to be higher
388-
# this is to account for kubernetes having readiness check report as failure until
389-
# the initial delay period is up
390-
added_timeout.append(int(container['readinessProbe'].get('initialDelaySeconds', 50)))
391-
392-
if 'livenessProbe' in container:
393-
# If there is initial delay on the readiness check then timeout needs to be higher
394-
# this is to account for kubernetes having liveness check report as failure until
395-
# the initial delay period is up
396-
added_timeout.append(int(container['livenessProbe'].get('initialDelaySeconds', 50)))
397-
398-
if added_timeout:
399-
delay = max(added_timeout)
400-
self.log(namespace, "adding {}s on to the original {}s timeout to account for the initial delay specified in the liveness / readiness probe".format(delay, timeout)) # noqa
401-
timeout += delay
402-
403-
return timeout
404-
405351

406352
SchedulerClient = KubeHTTPClient

rootfs/scheduler/resources/deployment.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def scale(self, namespace, name, image, entrypoint, command, **kwargs):
171171
kwargs['previous_replicas'] = current
172172
self.wait_until_ready(namespace, name, **kwargs)
173173

174-
def in_progress(self, namespace, name, deploy_timeout, batches, replicas, tags):
174+
def in_progress(self, namespace, name, timeout, batches, replicas, tags):
175175
"""
176176
Determine if a Deployment has a deploy in progress
177177
@@ -207,7 +207,7 @@ def in_progress(self, namespace, name, deploy_timeout, batches, replicas, tags):
207207
containers = deployment['spec']['template']['spec']['containers']
208208

209209
# calculate base deploy timeout
210-
deploy_timeout = self._deploy_probe_timeout(deploy_timeout, namespace, labels, containers)
210+
deploy_timeout = self.pod.deploy_probe_timeout(timeout, namespace, labels, containers)
211211

212212
# a rough calculation that figures out an overall timeout
213213
steps = self._get_deploy_steps(batches, tags)
@@ -304,7 +304,7 @@ def wait_until_ready(self, namespace, name, **kwargs):
304304

305305
current = int(kwargs.get('previous_replicas', 0))
306306
batches = kwargs.get('deploy_batches', None)
307-
deploy_timeout = kwargs.get('deploy_timeout', 120)
307+
timeout = kwargs.get('deploy_timeout', 120)
308308
tags = kwargs.get('tags', {})
309309
steps = self._get_deploy_steps(batches, tags)
310310
batches = self._get_deploy_batches(steps, replicas)
@@ -320,7 +320,7 @@ def wait_until_ready(self, namespace, name, **kwargs):
320320
return
321321

322322
# calculate base deploy timeout
323-
deploy_timeout = self._deploy_probe_timeout(deploy_timeout, namespace, labels, containers)
323+
deploy_timeout = self.pod.deploy_probe_timeout(timeout, namespace, labels, containers)
324324

325325
# a rough calculation that figures out an overall timeout
326326
timeout = len(batches) * deploy_timeout
@@ -351,3 +351,26 @@ def wait_until_ready(self, namespace, name, **kwargs):
351351
ready, _ = self.are_replicas_ready(namespace, name)
352352
if not ready:
353353
self.pod._handle_not_ready_pods(namespace, labels)
354+
355+
def _get_deploy_steps(self, batches, tags):
356+
# if there is no batch information available default to available nodes for app
357+
if not batches:
358+
# figure out how many nodes the application can go on
359+
steps = len(self.node.get(labels=tags).json()['items'])
360+
else:
361+
steps = int(batches)
362+
363+
return steps
364+
365+
def _get_deploy_batches(self, steps, desired):
366+
# figure out what kind of batches the deploy is done in - 1 in, 1 out or higher
367+
if desired < steps:
368+
# do it all in one go
369+
batches = [desired]
370+
else:
371+
# figure out the stepped deploy count and then see if there is a leftover
372+
batches = [steps for n in set(range(1, (desired + 1))) if n % steps == 0]
373+
if desired - sum(batches) > 0:
374+
batches.append(desired - sum(batches))
375+
376+
return batches

rootfs/scheduler/resources/pod.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def wait_until_ready(self, namespace, containers, labels, desired, timeout): #
624624
if desired == 0:
625625
return
626626

627-
timeout = self._deploy_probe_timeout(timeout, namespace, labels, containers)
627+
timeout = self.deploy_probe_timeout(timeout, namespace, labels, containers)
628628
self.log(namespace, "waiting for {} pods in {} namespace to be in services ({}s timeout)".format(desired, namespace, timeout)) # noqa
629629

630630
# Ensure the minimum desired number of pods are available
@@ -694,3 +694,34 @@ def _handle_not_ready_pods(self, namespace, labels):
694694
raise KubeException(message)
695695

696696
return None
697+
698+
def deploy_probe_timeout(self, timeout, namespace, labels, containers):
699+
"""
700+
Added in additional timeouts based on readiness and liveness probe
701+
702+
Uses the max of the two instead of combining them as the checks are stacked.
703+
"""
704+
705+
container_name = '{}-{}'.format(labels['app'], labels['type'])
706+
container = self.pod.find_container(container_name, containers)
707+
708+
# get health info from container
709+
added_timeout = []
710+
if 'readinessProbe' in container:
711+
# If there is initial delay on the readiness check then timeout needs to be higher
712+
# this is to account for kubernetes having readiness check report as failure until
713+
# the initial delay period is up
714+
added_timeout.append(int(container['readinessProbe'].get('initialDelaySeconds', 50)))
715+
716+
if 'livenessProbe' in container:
717+
# If there is initial delay on the readiness check then timeout needs to be higher
718+
# this is to account for kubernetes having liveness check report as failure until
719+
# the initial delay period is up
720+
added_timeout.append(int(container['livenessProbe'].get('initialDelaySeconds', 50)))
721+
722+
if added_timeout:
723+
delay = max(added_timeout)
724+
self.log(namespace, "adding {}s on to the original {}s timeout to account for the initial delay specified in the liveness / readiness probe".format(delay, timeout)) # noqa
725+
timeout += delay
726+
727+
return timeout

0 commit comments

Comments
 (0)