Skip to content

Commit

Permalink
Merge pull request #32 from 2gis/I-21
Browse files Browse the repository at this point in the history
I-21 check replicas greater or equal
  • Loading branch information
dekhtyarev authored Sep 26, 2018
2 parents 75af6c3 + ccb4621 commit cb5b923
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 5 additions & 5 deletions k8s/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def __init__(self, command, sync_mode, show_logs):
self.show_logs = show_logs

@staticmethod
def _replicas_are_equal(replicas):
def _replicas_count_are_greater_or_equal(replicas):
replicas = [0 if r is None else r for r in replicas] # replace all None to 0
return all(r == replicas[0] for r in replicas)
return all(r >= replicas[0] for r in replicas)

@staticmethod
def _ports_are_equal(old_port, new_port):
Expand Down Expand Up @@ -317,7 +317,7 @@ def _wait_deployment_complete(self, kube_client, tries, timeout):

log.info('desiredReplicas = {}, updatedReplicas = {}, availableReplicas = {}'.
format(replicas[0], replicas[4], replicas[2]))
if self._replicas_are_equal(replicas) and status.unavailable_replicas is None:
if self._replicas_count_are_greater_or_equal(replicas) and status.unavailable_replicas is None:
log.info('Deployment completed on {} attempt'.format(i + 1))
return
else:
Expand All @@ -338,7 +338,7 @@ def _wait_statefulset_complete(self, kube_client, tries, timeout):
if current_revision == update_revision:
log.info('desiredReplicas = {}, updatedReplicas = {}, availableReplicas = {}'.
format(replicas[0], replicas[1], replicas[2]))
if self._replicas_are_equal(replicas):
if self._replicas_count_are_greater_or_equal(replicas):
log.info('StatefulSet completed on {} attempt'.format(i))
return
else:
Expand All @@ -355,7 +355,7 @@ def _wait_daemonset_complete(self, kube_client, tries, timeout):
status.number_ready, status.updated_number_scheduled]
log.info('desiredNodes = {}, availableNodes = {}, readyNodes = {}, updatedNodes = {}'.
format(replicas[0], replicas[1], replicas[2], replicas[3]))
if self._replicas_are_equal(replicas) and status.number_unavailable is None:
if self._replicas_count_are_greater_or_equal(replicas) and status.number_unavailable is None:
log.info('DaemonSet completed on {} attempt'.format(i))
return
else:
Expand Down
14 changes: 11 additions & 3 deletions k8s/test_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,16 @@ def test_get_template_context(self):
class TestKubeObject(unittest.TestCase):
def test_replicas_equal(self):
replicas = (1, 1, 1)
self.assertTrue(Provisioner._replicas_are_equal(replicas))
self.assertTrue(Provisioner._replicas_count_are_greater_or_equal(replicas))

def test_replicas_greater(self):
replicas = (2, 3, 3)
self.assertTrue(Provisioner._replicas_count_are_greater_or_equal(replicas))

def test_replicas_not_equal(self):
replicas = (0, 1, 1)
self.assertFalse(Provisioner._replicas_are_equal(replicas))
replicas = (1, 1, 0)
self.assertFalse(Provisioner._replicas_count_are_greater_or_equal(replicas))

def test_replicas_with_hpa_not_equal(self):
replicas = (6, 7, 5)
self.assertFalse(Provisioner._replicas_count_are_greater_or_equal(replicas))

0 comments on commit cb5b923

Please sign in to comment.