Skip to content

Commit

Permalink
feat(HPAs): resolves #135 recreate HPAs from db on load
Browse files Browse the repository at this point in the history
Signed-off-by: Cryptophobia <aouzounov@gmail.com>
  • Loading branch information
Cryptophobia committed Oct 16, 2020
1 parent 9346813 commit 0440e56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# If DEIS_REGISTRY is not set, try to populate it from legacy DEV_REGISTRY
DEIS_REGISTRY ?= $(DEV_REGISTRY)
IMAGE_PREFIX ?= deis
IMAGE_PREFIX ?= hephy
COMPONENT ?= controller
SHORT_NAME ?= $(COMPONENT)

Expand Down
1 change: 1 addition & 0 deletions rootfs/api/management/commands/healthchecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class Command(BaseCommand):
"""Management command for healthchecks"""

def handle(self, *args, **options):
"""Ensure DB and other things are alive"""
print("Checking if database is alive")
Expand Down
13 changes: 12 additions & 1 deletion rootfs/api/management/commands/load_db_state_to_k8s.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from django.core.management.base import BaseCommand
from django.shortcuts import get_object_or_404

from api.models import Key, App, Domain, Certificate, Service
from api.models import Key, App, AppSettings, Domain, Certificate, Service
from api.exceptions import DeisException, AlreadyExists


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...")
Expand Down Expand Up @@ -40,6 +41,16 @@ def handle(self, *args, **options):
print('ERROR: There was a problem deploying {} '
'due to {}'.format(application, str(error)))

# deploy autoscaling HPAs for application
appsettings = AppSettings.objects.filter(app=application).order_by('-created')[0]
if appsettings.autoscale:
try:
for proc_type in application.structure:
application.autoscale(proc_type, appsettings.autoscale[proc_type])
except Exception as error:
print('ERROR: There was a problem deploying HPAs for this {} proc_type '
'of {} app due to error: {}'.format(proc_type, application, error))

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

def save_apps(self):
Expand Down

0 comments on commit 0440e56

Please sign in to comment.