2323from api .models .release import Release
2424from api .models .config import Config
2525from api .models .domain import Domain
26+ from api .models .appsettings import AppSettings
2627
2728from scheduler import KubeHTTPException , KubeException
2829
@@ -178,7 +179,7 @@ def log(self, message, level=logging.INFO):
178179
179180 def create (self , * args , ** kwargs ): # noqa
180181 """
181- Create a application with an initial config, release, domain
182+ Create a application with an initial config, settings, release, domain
182183 and k8s resource if needed
183184 """
184185 try :
@@ -220,6 +221,10 @@ def create(self, *args, **kwargs): # noqa
220221
221222 raise ServiceUnavailable ('Kubernetes resources could not be created' ) from e
222223
224+ try :
225+ self .appsettings_set .latest ()
226+ except AppSettings .DoesNotExist :
227+ AppSettings .objects .create (owner = self .owner , app = self )
223228 # Attach the platform specific application sub domain to the k8s service
224229 # Only attach it on first release in case a customer has remove the app domain
225230 if rel .version == 1 and not Domain .objects .filter (domain = self .id ).exists ():
@@ -389,6 +394,7 @@ def scale(self, user, structure): # noqa
389394
390395 def _scale_pods (self , scale_types ):
391396 release = self .release_set .latest ()
397+ app_settings = self .appsettings_set .latest ()
392398 version = "v{}" .format (release .version )
393399 image = release .image
394400 envs = self ._build_env_vars (release .build .type , version , image , release .config .values )
@@ -403,7 +409,7 @@ def _scale_pods(self, scale_types):
403409 for scale_type , replicas in scale_types .items ():
404410 # only web / cmd are routable
405411 # http://docs.deis.io/en/latest/using_deis/process-types/#web-vs-cmd-process-types
406- routable = True if scale_type in ['web' , 'cmd' ] and release . config .routable else False
412+ routable = True if scale_type in ['web' , 'cmd' ] and app_settings .routable else False
407413 # fetch application port and inject into ENV Vars as needed
408414 port = release .get_port ()
409415 if port :
@@ -424,6 +430,7 @@ def _scale_pods(self, scale_types):
424430 'app_type' : scale_type ,
425431 'build_type' : release .build .type ,
426432 'healthcheck' : healthcheck ,
433+ 'service_annotations' : {'maintenance' : app_settings .maintenance },
427434 'routable' : routable ,
428435 'deploy_batches' : batches ,
429436 'deploy_timeout' : deploy_timeout ,
@@ -461,6 +468,8 @@ def deploy(self, release, force_deploy=False):
461468 if release .build is None :
462469 raise DeisException ('No build associated with this release' )
463470
471+ app_settings = self .appsettings_set .latest ()
472+
464473 # use create to make sure minimum resources are created
465474 self .create ()
466475
@@ -486,7 +495,7 @@ def deploy(self, release, force_deploy=False):
486495 for scale_type , replicas in self .structure .items ():
487496 # only web / cmd are routable
488497 # http://docs.deis.io/en/latest/using_deis/process-types/#web-vs-cmd-process-types
489- routable = True if scale_type in ['web' , 'cmd' ] and release . config .routable else False
498+ routable = True if scale_type in ['web' , 'cmd' ] and app_settings .routable else False
490499 # fetch application port and inject into ENV vars as needed
491500 port = release .get_port ()
492501 if port :
@@ -509,6 +518,7 @@ def deploy(self, release, force_deploy=False):
509518 'build_type' : release .build .type ,
510519 'healthcheck' : healthcheck ,
511520 'routable' : routable ,
521+ 'service_annotations' : {'maintenance' : app_settings .maintenance },
512522 'deploy_batches' : batches ,
513523 'deploy_timeout' : deploy_timeout ,
514524 'deployment_history_limit' : deployment_history ,
@@ -597,7 +607,8 @@ def verify_application_health(self, **kwargs):
597607 """
598608 # Bail out early if the application is not routable
599609 release = self .release_set .latest ()
600- if not kwargs .get ('routable' , False ) and release .config .routable :
610+ app_settings = self .appsettings_set .latest ()
611+ if not kwargs .get ('routable' , False ) and app_settings .routable :
601612 return
602613
603614 app_type = kwargs .get ('app_type' )
0 commit comments