Skip to content

Commit c85cac4

Browse files
committed
feat(controller): add canary support
1 parent 9cc6dea commit c85cac4

31 files changed

Lines changed: 1223 additions & 617 deletions

rootfs/api/management/commands/load_db_state_to_k8s.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ class Command(BaseCommand):
1717
"""Management command for publishing Drycc platform state from the database
1818
to k8s.
1919
"""
20+
21+
def _deploy(self, app, release):
22+
if release.build is None:
23+
print('WARNING: {} has no build associated with '
24+
'its latest release. Skipping deployment...'.format(app))
25+
return
26+
27+
try:
28+
app.deploy(release)
29+
except AlreadyExists as error:
30+
logger.debug(error)
31+
print('WARNING: {} has a deployment in progress. '
32+
'Skipping deployment...'.format(app))
33+
except DryccException as error:
34+
logger.exception(error)
35+
print('ERROR: There was a problem deploying {} '
36+
'due to {}'.format(app, str(error)))
37+
2038
def handle(self, *args, **options):
2139
"""Publishes Drycc platform state from the database to kubernetes."""
2240
print("Publishing DB state to kubernetes...")
@@ -29,26 +47,13 @@ def handle(self, *args, **options):
2947
domain = get_object_or_404(Domain, domain=domain)
3048
cert.attach_in_kubernetes(domain)
3149

32-
# deploy applications
50+
# deploy apps
3351
print("Deploying available applications")
34-
for application in App.objects.all():
35-
rel = application.release_set.filter(failed=False).latest()
36-
if rel.build is None:
37-
print('WARNING: {} has no build associated with '
38-
'its latest release. Skipping deployment...'.format(application))
39-
continue
40-
41-
try:
42-
application.deploy(rel)
43-
except AlreadyExists as error:
44-
logger.debug(error)
45-
print('WARNING: {} has a deployment in progress. '
46-
'Skipping deployment...'.format(application))
47-
continue
48-
except DryccException as error:
49-
logger.exception(error)
50-
print('ERROR: There was a problem deploying {} '
51-
'due to {}'.format(application, str(error)))
52+
for app in App.objects.all():
53+
release = app.release_set.filter(failed=False).latest()
54+
if release.canary:
55+
self._deploy(app, app.release_set.filter(failed=False, canary=False).latest())
56+
self._deploy(app, release)
5257

5358
print("Done Publishing DB state to kubernetes.")
5459

rootfs/api/migrations/0001_initial.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# Generated by Django 4.1.7 on 2023-05-05 03:32
1+
# Generated by Django 4.2.1 on 2023-05-31 02:30
22

33
import api.models.app
44
import api.models.certificate
55
import api.models.key
6+
import api.models.tls
67
import api.utils
78
from django.conf import settings
89
import django.contrib.auth.models
@@ -185,7 +186,7 @@ class Migration(migrations.Migration):
185186
('uuid', models.UUIDField(auto_created=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True, verbose_name='UUID')),
186187
('created', models.DateTimeField(auto_now_add=True)),
187188
('updated', models.DateTimeField(auto_now=True)),
188-
('issuer', models.JSONField(default={'email': 'anonymous@cert-manager.io', 'key_id': '', 'key_secret': '', 'server': 'https://acme-v02.api.letsencrypt.org/directory'})),
189+
('issuer', models.JSONField(default=api.models.tls.default_issuer)),
189190
('https_enforced', models.BooleanField(null=True)),
190191
('certs_auto_enabled', models.BooleanField(null=True)),
191192
('app', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.app')),
@@ -204,6 +205,7 @@ class Migration(migrations.Migration):
204205
('created', models.DateTimeField(auto_now_add=True)),
205206
('updated', models.DateTimeField(auto_now=True)),
206207
('ports', models.JSONField(default=list)),
208+
('canary', models.BooleanField(default=False)),
207209
('procfile_type', models.TextField()),
208210
('app', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.app')),
209211
('owner', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
@@ -266,6 +268,7 @@ class Migration(migrations.Migration):
266268
('version', models.PositiveIntegerField()),
267269
('summary', models.TextField(blank=True, null=True)),
268270
('failed', models.BooleanField(default=False)),
271+
('canary', models.BooleanField(default=False)),
269272
('exception', models.TextField(blank=True, null=True)),
270273
('app', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.app')),
271274
('build', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.build')),
@@ -318,6 +321,7 @@ class Migration(migrations.Migration):
318321
('uuid', models.UUIDField(auto_created=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True, verbose_name='UUID')),
319322
('created', models.DateTimeField(auto_now_add=True)),
320323
('updated', models.DateTimeField(auto_now=True)),
324+
('canaries', models.JSONField(default=list)),
321325
('routable', models.BooleanField(default=True)),
322326
('autoscale', models.JSONField(blank=True, default=dict)),
323327
('label', models.JSONField(blank=True, default=dict)),
@@ -331,4 +335,3 @@ class Migration(migrations.Migration):
331335
},
332336
),
333337
]
334-

0 commit comments

Comments
 (0)