@@ -82,6 +82,14 @@ def sync_openshift_project_labels(project_id, allocator, apply):
8282 f"Labels updated for Openshift project { project_id } : { ', ' .join (missing_or_incorrect_labels )} "
8383 )
8484
85+ @staticmethod
86+ def set_default_quota_on_allocation (allocation , allocator , coldfront_attr ):
87+ uqm = tasks .UNIT_QUOTA_MULTIPLIERS [allocator .resource_type ]
88+ value = allocation .quantity * uqm .get (coldfront_attr , 0 )
89+ value += tasks .STATIC_QUOTA [allocator .resource_type ].get (coldfront_attr , 0 )
90+ utils .set_attribute_on_allocation (allocation , coldfront_attr , value )
91+ return value
92+
8593 def check_institution_specific_code (self , allocation , apply ):
8694 attr = attributes .ALLOCATION_INSTITUTION_SPECIFIC_CODE
8795 isc = allocation .get_attribute (attr )
@@ -299,19 +307,41 @@ def handle(self, *args, **options):
299307 )
300308 msg = f"{ msg } Attribute set to match current quota."
301309 logger .warning (msg )
302- elif not (current_value == expected_value ):
303- msg = (
304- f"Value for quota for { attr } = { current_value } does not match expected"
305- f" value of { expected_value } on allocation { allocation_str } "
306- )
307- logger .warning (msg )
310+ else :
311+ # We just checked the case where the quota value is set in the cluster
312+ # but not in coldfront. This is the only case the cluster value is the
313+ # "source of truth" for the quota value
314+ # If the coldfront value is set, it is always the source of truth.
315+ # But first, we need to check if the quota value is set anywhere at all.
316+ # TODO (Quan): Refactor these if statements so that we can remove this comment block
317+ if current_value is None and expected_value is None :
318+ msg = (
319+ f"Value for quota for { attr } is not set anywhere"
320+ f" on allocation { allocation_str } "
321+ )
322+ logger .warning (msg )
308323
309- if options ["apply" ]:
310- try :
311- allocator .set_quota (project_id )
324+ if options ["apply" ]:
325+ expected_value = self .set_default_quota_on_allocation (
326+ allocation , allocator , attr
327+ )
312328 logger .warning (
313- f"Quota for allocation { project_id } was out of date. Reapplied! "
329+ f"Added default quota for { attr } to allocation { allocation_str } to { expected_value } "
314330 )
315- except Exception as e :
316- logger .error (f"setting openshift quota failed: { e } " )
317- continue
331+
332+ if not (current_value == expected_value ):
333+ msg = (
334+ f"Value for quota for { attr } = { current_value } does not match expected"
335+ f" value of { expected_value } on allocation { allocation_str } "
336+ )
337+ logger .warning (msg )
338+
339+ if options ["apply" ]:
340+ try :
341+ allocator .set_quota (project_id )
342+ logger .warning (
343+ f"Quota for allocation { project_id } was out of date. Reapplied!"
344+ )
345+ except Exception as e :
346+ logger .error (f"setting openshift quota failed: { e } " )
347+ continue
0 commit comments