@@ -134,9 +134,8 @@ def __str__(self):
134134 def create (self , * args , ** kwargs ):
135135 config = Config .objects .create (owner = self .owner , app = self , values = {})
136136 build = Build .objects .create (owner = self .owner , app = self , image = settings .DEFAULT_BUILD )
137- limit = Limit .objects .create (owner = self .owner , app = self , memory = {}, cpu = {})
138137 Release .objects .create (version = 1 , owner = self .owner , app = self ,
139- config = config , build = build , limit = limit )
138+ config = config , build = build )
140139
141140 def delete (self , * args , ** kwargs ):
142141 for c in self .container_set .all ():
@@ -303,8 +302,10 @@ def _command_announceable(self):
303302 @transition (field = state , source = INITIALIZED , target = CREATED )
304303 def create (self ):
305304 image = self .release .image
306- kwargs = {'memory' : self .release .limit .memory ,
307- 'cpu' : self .release .limit .cpu }
305+ kwargs = {}
306+ if self .release .config .limit is not None :
307+ kwargs = {'memory' : self .release .config .limit .memory ,
308+ 'cpu' : self .release .config .limit .cpu }
308309 self ._scheduler .create (name = self ._job_id ,
309310 image = image ,
310311 command = self ._command ,
@@ -332,8 +333,10 @@ def deploy(self, release):
332333 new_job_id = self ._job_id
333334 image = self .release .image
334335 c_type = self .type
335- kwargs = {'memory' : self .release .limit .memory ,
336- 'cpu' : self .release .limit .cpu }
336+ kwargs = {}
337+ if self .release .config .limit is not None :
338+ kwargs = {'memory' : self .release .config .limit .memory ,
339+ 'cpu' : self .release .config .limit .cpu }
337340 self ._scheduler .create (name = new_job_id ,
338341 image = image ,
339342 command = self ._command .format (** locals ()),
@@ -424,6 +427,7 @@ class Config(UuidAuditedModel):
424427 owner = models .ForeignKey (settings .AUTH_USER_MODEL )
425428 app = models .ForeignKey ('App' )
426429 values = JSONField (default = '{}' , blank = True )
430+ limit = models .ForeignKey ('Limit' , null = True )
427431
428432 class Meta :
429433 get_latest_by = 'created'
@@ -470,7 +474,6 @@ class Release(UuidAuditedModel):
470474
471475 config = models .ForeignKey ('Config' )
472476 build = models .ForeignKey ('Build' )
473- limit = models .ForeignKey ('Limit' , null = True )
474477 # NOTE: image contains combined build + config, ready to run
475478 image = models .CharField (max_length = 256 , default = settings .DEFAULT_BUILD )
476479
@@ -482,8 +485,7 @@ class Meta:
482485 def __str__ (self ):
483486 return "{0}-v{1}" .format (self .app .id , self .version )
484487
485- def new (self , user , config = None , build = None , limit = None ,
486- summary = None , source_version = 'latest' ):
488+ def new (self , user , config = None , build = None , summary = None , source_version = 'latest' ):
487489 """
488490 Create a new application release using the provided Build and Config
489491 on behalf of a user.
@@ -494,8 +496,6 @@ def new(self, user, config=None, build=None, limit=None,
494496 config = self .config
495497 if not build :
496498 build = self .build
497- if not limit :
498- limit = self .limit
499499 # always create a release off the latest image
500500 source_image = '{}:{}' .format (build .image , source_version )
501501 # construct fully-qualified target image
@@ -505,8 +505,8 @@ def new(self, user, config=None, build=None, limit=None,
505505 target_image = '{}' .format (self .app .id )
506506 # create new release and auto-increment version
507507 release = Release .objects .create (
508- owner = user , app = self .app , config = config , build = build , limit = limit ,
509- version = new_version , image = target_image , summary = summary )
508+ owner = user , app = self .app , config = config ,
509+ build = build , version = new_version , image = target_image , summary = summary )
510510 # IOW, this image did not come from the builder
511511 if not build .sha :
512512 # we assume that the image is not present on our registry,
@@ -547,7 +547,7 @@ def save(self, *args, **kwargs): # noqa
547547 # compare this build to the previous build
548548 old_build = prev_release .build if prev_release else None
549549 old_config = prev_release .config if prev_release else None
550- old_limit = prev_release .limit if prev_release else None
550+ old_limit = prev_release .config . limit if prev_release else None
551551 # if the build changed, log it and who pushed it
552552 if self .version == 1 :
553553 self .summary += "{} created initial release" .format (self .app .owner )
@@ -574,7 +574,7 @@ def save(self, *args, **kwargs): # noqa
574574 self .summary += ' and '
575575 self .summary += "{} {}" .format (self .config .owner , changes )
576576 # if the limit changes, log the dict diff
577- elif self .limit != old_limit :
577+ elif self .config . limit != old_limit :
578578 changes = []
579579 old_mem = old_limit .memory if old_limit else {}
580580 diff = dict_diff (self .limit .memory , old_mem )
0 commit comments