Skip to content

Commit aea5fb3

Browse files
committed
Merge pull request #578 from helgi/ticket_571
fix(scheduler): only update port on routable services
2 parents 559aff3 + 8a840a7 commit aea5fb3

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

rootfs/api/models/app.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from datetime import datetime
23
import logging
34
import random
@@ -341,31 +342,33 @@ def deploy(self, user, release):
341342
self.save()
342343

343344
# deploy application to k8s. Also handles initial scaling
345+
deploys = {}
344346
build_type = app_build_type(release)
345347
for scale_type in self.structure.keys():
346-
image = release.image
347-
version = "v{}".format(release.version)
348-
kwargs = {
348+
deploys[scale_type] = {
349349
'memory': release.config.memory,
350350
'cpu': release.config.cpu,
351351
'tags': release.config.tags,
352352
'envs': release.config.values,
353353
'replicas': 0, # Scaling up happens in a separate operation
354-
'version': version,
354+
'version': "v{}".format(release.version),
355355
'app_type': scale_type,
356356
'build_type': build_type,
357357
'healthcheck': release.config.healthcheck(),
358358
# http://docs.deis.io/en/latest/using_deis/process-types/#web-vs-cmd-process-types
359359
'routable': True if scale_type in ['web', 'cmd'] else False
360360
}
361361

362-
command = self._get_command(scale_type)
362+
# Sort deploys so routable comes first
363+
deploys = OrderedDict(sorted(deploys.items(), key=lambda d: d[1].get('routable')))
364+
365+
for scale_type, kwargs in deploys.items():
363366
try:
364367
self._scheduler.deploy(
365368
namespace=self.id,
366369
name=self._get_job_id(scale_type),
367-
image=image,
368-
command=command,
370+
image=release.image,
371+
command=self._get_command(scale_type),
369372
**kwargs
370373
)
371374

rootfs/scheduler/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def deploy(self, namespace, name, image, command, **kwargs):
395395
# traffic to the application
396396
self._update_application_service(namespace, name, app_type, image, routable)
397397

398-
def _update_application_service(self, namespace, name, app_type, image, routable):
398+
def _update_application_service(self, namespace, name, app_type, image, routable=False):
399399
"""Update application service with all the various required information"""
400400
try:
401401
# Fetch service
@@ -411,11 +411,12 @@ def _update_application_service(self, namespace, name, app_type, image, routable
411411
service['spec']['selector']['type'] = app_type
412412

413413
# Find if target port exists already, update / create as required
414-
port = self._get_port(image)
415-
for pos, item in enumerate(service['spec']['ports']):
416-
if item['port'] == 80 and port != item['targetPort']:
417-
# port 80 is the only one we care about right now
418-
service['spec']['ports'][pos]['targetPort'] = port
414+
if routable:
415+
port = self._get_port(image)
416+
for pos, item in enumerate(service['spec']['ports']):
417+
if item['port'] == 80 and port != item['targetPort']:
418+
# port 80 is the only one we care about right now
419+
service['spec']['ports'][pos]['targetPort'] = port
419420

420421
self._update_service(namespace, namespace, data=service)
421422
except Exception as e:

0 commit comments

Comments
 (0)