Skip to content

Commit 3c07d6c

Browse files
committed
Merge pull request #629 from helgi/get_old_rcs
ref(scheduler): simplify _get_old_rc in scheduler. Use existing functions and filtering
2 parents 28a13cb + 46d65e7 commit 3c07d6c

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -768,27 +768,15 @@ def _delete_namespace(self, namespace):
768768
# REPLICATION CONTROLLER #
769769

770770
def _get_old_rc(self, namespace, app_type):
771-
url = self._api("/namespaces/{}/replicationcontrollers", namespace)
772-
resp = self.session.get(url)
773-
if unhealthy(resp.status_code):
774-
error(resp, 'get ReplicationControllers in Namespace "{}"', namespace)
775-
776-
exists = False
777-
prev_rc = []
778-
for rc in resp.json()['items']:
779-
if (
780-
'app' in rc['spec']['selector'] and
781-
namespace == rc['metadata']['labels']['app'] and
782-
'type' in rc['spec']['selector'] and
783-
app_type == rc['spec']['selector']['type']
784-
):
785-
exists = True
786-
prev_rc = rc
787-
break
788-
if exists:
789-
return prev_rc
771+
labels = {
772+
'app': namespace,
773+
'type': app_type
774+
}
775+
controllers = self._get_rcs(namespace, labels=labels).json()
776+
if len(controllers['items']) == 0:
777+
return False
790778

791-
return 0
779+
return controllers['items'][0]
792780

793781
def _get_rc_status(self, namespace, name):
794782
url = self._api("/namespaces/{}/replicationcontrollers/{}", namespace, name)

0 commit comments

Comments
 (0)