Skip to content

Commit 7ad95e4

Browse files
authored
Merge pull request #936 from mboersma/load-only-latest-config
fix(controller): only load latest config
2 parents 6d6a10e + a9f7bcf commit 7ad95e4

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

rootfs/api/management/commands/load_db_state_to_k8s.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.core.management.base import BaseCommand
22
from django.shortcuts import get_object_or_404
33

4-
from api.models import Key, App, Domain, Certificate, Config
4+
from api.models import Key, App, Domain, Certificate
55
from api.exceptions import DeisException, AlreadyExists
66

77

@@ -12,13 +12,8 @@ class Command(BaseCommand):
1212
def handle(self, *args, **options):
1313
"""Publishes Deis platform state from the database to kubernetes."""
1414
print("Publishing DB state to kubernetes...")
15-
for model in (Key, App, Domain, Certificate, Config):
16-
for obj in model.objects.all():
17-
try:
18-
obj.save()
19-
except DeisException as error:
20-
print('ERROR: Problem saving to model {} for {}'
21-
'due to {}'.format(str(model.__name__), str(obj), str(error)))
15+
16+
self.save_apps()
2217

2318
# certificates have to be attached to domains to create k8s secrets
2419
for cert in Certificate.objects.all():
@@ -46,3 +41,20 @@ def handle(self, *args, **options):
4641
'due to {}'.format(application, str(error)))
4742

4843
print("Done Publishing DB state to kubernetes.")
44+
45+
def save_apps(self):
46+
"""Saves important Django data models to the database."""
47+
for app in App.objects.all():
48+
try:
49+
app.save()
50+
app.config_set.latest().save()
51+
except DeisException as error:
52+
print('ERROR: Problem saving to model {} for {}'
53+
'due to {}'.format(str(App.__name__), str(app), str(error)))
54+
for model in (Key, Domain, Certificate):
55+
for obj in model.objects.all():
56+
try:
57+
obj.save()
58+
except DeisException as error:
59+
print('ERROR: Problem saving to model {} for {}'
60+
'due to {}'.format(str(model.__name__), str(obj), str(error)))

0 commit comments

Comments
 (0)