Skip to content

Commit 4273f76

Browse files
authored
ref(scheduler): remove scale_rc and deploy_rc as they are no longer used (#981)
These can always be brought back if the same logic is required for RS (due to diff deploy strategy than Deployments offers)
1 parent 7a152a6 commit 4273f76

2 files changed

Lines changed: 1 addition & 133 deletions

File tree

rootfs/scheduler/__init__.py

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -136,89 +136,6 @@ def deploy(self, namespace, name, image, entrypoint, command, **kwargs): # noqa
136136
# traffic to the application
137137
self._update_application_service(namespace, name, app_type, port, routable)
138138

139-
def deploy_rc(self, namespace, name, image, entrypoint, command, **kwargs): # noqa
140-
app_type = kwargs.get('app_type')
141-
routable = kwargs.get('routable', False)
142-
envs = kwargs.get('envs', {})
143-
port = envs.get('PORT', None)
144-
timeout = kwargs.get('deploy_timeout')
145-
146-
# Fetch old RC and create the new one for a release
147-
old_rc = self.get_old_rc(namespace, app_type)
148-
149-
# If an RC already exists then stop processing of the deploy
150-
try:
151-
self.get_rc(namespace, name)
152-
self.log(namespace, 'RC {} already exists. Stopping deploy'.format(name)) # noqa
153-
return
154-
except KubeHTTPException:
155-
# make replicas 0 so scaling handles the work
156-
replicas = kwargs.pop('replicas')
157-
new_rc = self.create_rc(
158-
namespace,
159-
name,
160-
image,
161-
entrypoint,
162-
command,
163-
replicas=0,
164-
**kwargs).json()
165-
kwargs['replicas'] = replicas
166-
167-
# Get the desired number to scale to
168-
if old_rc:
169-
desired = int(old_rc["spec"]["replicas"])
170-
else:
171-
desired = kwargs['replicas']
172-
self.log(namespace, 'No prior RC could be found for {}'.format(app_type))
173-
174-
# see if application or global deploy batches are defined
175-
batches = kwargs.get('deploy_batches', None)
176-
tags = kwargs.get('tags', {})
177-
steps = self._get_deploy_steps(batches, tags)
178-
batches = self._get_deploy_batches(steps, desired)
179-
180-
try:
181-
count = 0
182-
new_name = new_rc["metadata"]["name"]
183-
for batch in batches:
184-
count += batch
185-
self.log(namespace, 'scaling release {} to {} out of final {}'.format(
186-
new_name, count, desired
187-
))
188-
self._scale_rc(namespace, new_name, count, timeout)
189-
190-
if old_rc:
191-
old_name = old_rc["metadata"]["name"]
192-
self.log(namespace, 'scaling old release {} from original {} to {}'.format(
193-
old_name, desired, (desired-count))
194-
)
195-
self._scale_rc(namespace, old_name, (desired-count), timeout)
196-
except Exception as e:
197-
# New release is broken. Clean up
198-
199-
# Remove new release of the RC
200-
self.cleanup_release(namespace, new_rc, timeout)
201-
202-
# If there was a previous release then bring that back
203-
if old_rc:
204-
self._scale_rc(namespace, old_rc["metadata"]["name"], desired, timeout)
205-
206-
raise KubeException(
207-
'Could not scale {} to {}. '
208-
'Deleting and going back to old release'.format(
209-
new_rc["metadata"]["name"], desired
210-
)
211-
) from e
212-
213-
# New release is live and kicking. Clean up old release
214-
if old_rc:
215-
self.cleanup_release(namespace, old_rc, timeout)
216-
217-
# Make sure the application is routable and uses the correct port
218-
# Done after the fact to let initial deploy settle before routing
219-
# traffic to the application
220-
self._update_application_service(namespace, name, app_type, port, routable)
221-
222139
def cleanup_release(self, namespace, controller, timeout):
223140
"""
224141
Cleans up resources related to an application deployment
@@ -290,7 +207,7 @@ def _update_application_service(self, namespace, name, app_type, port, routable=
290207
raise KubeException(str(e)) from e
291208

292209
def scale(self, namespace, name, image, entrypoint, command, **kwargs):
293-
"""Scale RC or Deployment depending on what's requested"""
210+
"""Scale Deployment"""
294211
self.deploy_timeout = kwargs.get('deploy_timeout')
295212

296213
try:
@@ -313,24 +230,6 @@ def scale(self, namespace, name, image, entrypoint, command, **kwargs):
313230
# let the scale failure bubble up
314231
self._scale_deployment(namespace, name, image, entrypoint, command, **kwargs)
315232

316-
def scale_rc(self, namespace, name, image, entrypoint, command, **kwargs):
317-
replicas = kwargs.pop('replicas')
318-
try:
319-
self.get_rc(namespace, name)
320-
except KubeHTTPException as e:
321-
if e.response.status_code == 404:
322-
# add RC if it is missing for the namespace
323-
try:
324-
# Create RC with scale as 0 and then scale to get pod monitoring
325-
kwargs['replicas'] = 0
326-
self.create_rc(namespace, name, image, entrypoint, command, **kwargs)
327-
except KubeException:
328-
logger.exception("Creating RC {} failed".format(name))
329-
raise
330-
331-
# let the scale failure bubble up
332-
self._scale_rc(namespace, name, replicas, kwargs.get('deploy_timeout'))
333-
334233
def _build_pod_manifest(self, namespace, name, image, **kwargs):
335234
app_type = kwargs.get('app_type')
336235
build_type = kwargs.get('build_type')
@@ -825,17 +724,6 @@ def delete_namespace(self, namespace):
825724

826725
# REPLICATION CONTROLLER #
827726

828-
def get_old_rc(self, namespace, app_type):
829-
labels = {
830-
'app': namespace,
831-
'type': app_type
832-
}
833-
controllers = self.get_rcs(namespace, labels=labels).json()
834-
if len(controllers['items']) == 0:
835-
return False
836-
837-
return controllers['items'][0]
838-
839727
def get_rc(self, namespace, name):
840728
url = self._api("/namespaces/{}/replicationcontrollers/{}", namespace, name)
841729
response = self.session.get(url)

rootfs/scheduler/tests/test_replicationcontrollers.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,3 @@ def test_get_rc(self):
126126
},
127127
data['metadata']['labels']
128128
)
129-
130-
def test_scale(self):
131-
name = self.scale_rc()
132-
data = self.scheduler.get_rc(self.namespace, name).json()
133-
self.assertEqual(data['kind'], 'ReplicationController')
134-
self.assertEqual(data['metadata']['name'], name)
135-
136-
labels = {'app': self.namespace, 'version': 'v99', 'type': 'web'}
137-
pods = self.scheduler.get_pods(self.namespace, labels=labels).json()
138-
self.assertEqual(len(pods['items']), 4)
139-
140-
# scale to 8
141-
name = self.scale_rc(replicas=8)
142-
pods = self.scheduler.get_pods(self.namespace, labels=labels).json()
143-
self.assertEqual(len(pods['items']), 8)
144-
145-
# scale to 3
146-
name = self.scale_rc(replicas=3)
147-
pods = self.scheduler.get_pods(self.namespace, labels=labels).json()
148-
self.assertEqual(len(pods['items']), 3)

0 commit comments

Comments
 (0)