Skip to content

Commit 37eced9

Browse files
committed
fix(app): deploy applications on Controller start to create RCs and Pods
Fixes #541
1 parent 3cc896f commit 37eced9

6 files changed

Lines changed: 22 additions & 9 deletions

File tree

rootfs/api/management/commands/load_db_state_to_k8s.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Command(BaseCommand):
99
to k8s.
1010
"""
1111
def handle(self, *args, **options):
12-
"""Publishes Deis platform state from the database to etcd."""
13-
print("Publishing DB state to k8s...")
12+
"""Publishes Deis platform state from the database to kubernetes."""
13+
print("Publishing DB state to kubernetes...")
1414
for model in (Key, App, Domain, Certificate, Config):
1515
for obj in model.objects.all():
1616
obj.save()
@@ -21,4 +21,10 @@ def handle(self, *args, **options):
2121
domain = get_object_or_404(Domain, domain=domain)
2222
cert.attach_in_kubernetes(domain)
2323

24-
print("Done Publishing DB state to k8s.")
24+
# deploy applications
25+
print("Deploying available applications")
26+
for application in App.objects.all():
27+
rel = application.release_set.latest()
28+
application.deploy(rel)
29+
30+
print("Done Publishing DB state to kubernetes.")

rootfs/api/models/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _scale_pods(self, scale_types):
329329
log_event(self, err, logging.ERROR)
330330
raise
331331

332-
def deploy(self, user, release):
332+
def deploy(self, release):
333333
"""Deploy a new release to this application"""
334334
if release.build is None:
335335
raise EnvironmentError('No build associated with this release')

rootfs/api/models/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def create(self, user, *args, **kwargs):
4141
)
4242

4343
try:
44-
self.app.deploy(user, new_release)
44+
self.app.deploy(new_release)
4545
return new_release
4646
except Exception:
4747
if 'new_release' in locals():

rootfs/api/models/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def rollback(self, user, version):
141141

142142
try:
143143
if self.build is not None:
144-
self.app.deploy(user, new_release)
144+
self.app.deploy(new_release)
145145
return new_release
146146
except Exception:
147147
if 'new_release' in locals():

rootfs/api/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def post_save(self, config):
304304
try:
305305
# It's possible to set config values before a build
306306
if self.release.build is not None:
307-
config.app.deploy(self.request.user, self.release)
307+
config.app.deploy(self.release)
308308
except Exception:
309309
self.release.delete()
310310
raise

rootfs/scheduler/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,21 @@ def __init__(self):
336336
session.verify = False
337337
self.session = session
338338

339-
def deploy(self, namespace, name, image, command, **kwargs):
339+
def deploy(self, namespace, name, image, command, **kwargs): # noqa
340340
logger.debug('deploy {}, img {}, params {}, cmd "{}"'.format(name, image, kwargs, command))
341341
app_type = kwargs.get('app_type')
342342
routable = kwargs.get('routable', False)
343343

344344
# Fetch old RC and create the new one for a release
345345
old_rc = self._get_old_rc(namespace, app_type)
346-
new_rc = self._create_rc(namespace, name, image, command, **kwargs)
346+
347+
# If an RC already exists then stop processing of the deploy
348+
try:
349+
self._get_rc(namespace, name)
350+
logger.debug('RC {} already exists under Namespace {}. Stopping deploy'.format(name, namespace)) # noqa
351+
return
352+
except KubeHTTPException:
353+
new_rc = self._create_rc(namespace, name, image, command, **kwargs)
347354

348355
# Get the desired number to scale to
349356
if old_rc:

0 commit comments

Comments
 (0)