Skip to content

Commit 259d13f

Browse files
committed
ref(apps): iterate over RC for desired pod count when doing an app restart
Rationale here is that the RC already has the desired information and we may be iterating over many RCs. Not using the pod count is helpful in case other operations happen to have interfered with things. Another option is to use the structure info from the App model but this solutions seems more solid
1 parent 2131870 commit 259d13f

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

rootfs/api/models/app.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,20 @@ def restart(self, **kwargs): # noqa
177177
version = "v{}".format(release.version)
178178
kwargs['name'] = '{}-{}-{}'.format(kwargs['id'], version, kwargs['name'])
179179

180-
# Fetch the initial set of pods to work from
181-
pods = self.list_pods(**kwargs)
182-
desired = len(pods)
180+
# Iterate over RCs to get total desired count if not a single item
181+
desired = 1
182+
if 'name' not in kwargs:
183+
desired = 0
184+
labels = self._scheduler_filter(**kwargs)
185+
controllers = self._scheduler._get_rcs(kwargs['id'], labels=labels).json()['items']
186+
for controller in controllers:
187+
desired += controller['spec']['replicas']
183188
except KubeException:
184189
# Nothing was found
185190
return []
186191

187192
try:
188-
for pod in pods:
193+
for pod in self.list_pods(**kwargs):
189194
# This function verifies the delete. Gives pod 30 seconds
190195
self._scheduler._delete_pod(self.id, pod['name'])
191196
except Exception as e:
@@ -550,19 +555,7 @@ def run(self, user, command):
550555
def list_pods(self, *args, **kwargs):
551556
"""Used to list basic information about pods running for a given application"""
552557
try:
553-
labels = {'app': str(self)}
554-
555-
# always supply a version, either latest or a specific one
556-
if 'release' not in kwargs or kwargs['release'] is None:
557-
release = self.release_set.latest()
558-
else:
559-
release = self.release_set.get(version=kwargs['release'])
560-
561-
version = "v{}".format(release.version)
562-
labels.update({'version': version})
563-
564-
if 'type' in kwargs:
565-
labels.update({'type': kwargs['type']})
558+
labels = self._scheduler_filter(**kwargs)
566559

567560
# in case a singular pod is requested
568561
if 'name' in kwargs:
@@ -599,3 +592,20 @@ def list_pods(self, *args, **kwargs):
599592
err = '(list pods): {}'.format(e)
600593
log_event(self, err, logging.ERROR)
601594
raise
595+
596+
def _scheduler_filter(self, **kwargs):
597+
labels = {'app': self.id}
598+
599+
# always supply a version, either latest or a specific one
600+
if 'release' not in kwargs or kwargs['release'] is None:
601+
release = self.release_set.latest()
602+
else:
603+
release = self.release_set.get(version=kwargs['release'])
604+
605+
version = "v{}".format(release.version)
606+
labels.update({'version': version})
607+
608+
if 'type' in kwargs:
609+
labels.update({'type': kwargs['type']})
610+
611+
return labels

0 commit comments

Comments
 (0)