-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathload_db_state_to_k8s.py
More file actions
34 lines (28 loc) · 1.33 KB
/
load_db_state_to_k8s.py
File metadata and controls
34 lines (28 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from django.core.management.base import BaseCommand
from django.shortcuts import get_object_or_404
from api.models import Key, App, Domain, Certificate, Config
class Command(BaseCommand):
"""Management command for publishing Deis platform state from the database
to k8s.
"""
def handle(self, *args, **options):
"""Publishes Deis platform state from the database to kubernetes."""
print("Publishing DB state to kubernetes...")
for model in (Key, App, Domain, Certificate, Config):
for obj in model.objects.all():
obj.save()
# certificates have to be attached to domains to create k8s secrets
for cert in Certificate.objects.all():
for domain in cert.domains:
domain = get_object_or_404(Domain, domain=domain)
cert.attach_in_kubernetes(domain)
# deploy applications
print("Deploying available applications")
for application in App.objects.all():
rel = application.release_set.latest()
if rel.build is None:
print('WARNING: {} has no build associated with '
'its latest release. Skipping deployment...'.format(application))
continue
application.deploy(rel)
print("Done Publishing DB state to kubernetes.")