Skip to content

Commit 8a71778

Browse files
committed
CH-108 improve quotas conversion consistency
1 parent 197aef1 commit 8a71778

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

  • applications/jupyterhub/src/harness_jupyter/harness_jupyter
  • libraries/cloudharness-common/cloudharness/auth

applications/jupyterhub/src/harness_jupyter/harness_jupyter/jupyterhub.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def change_pod_manifest(self: KubeSpawner):
224224

225225
# set user quota cpu/mem usage if value has a "value" else don't change the value
226226
logging.info("Setting user quota cpu/mem usage")
227-
set_key_value(self, key="cpu_guarantee", value=float(user_quotas.get(
228-
"quota-ws-guaranteecpu")))
227+
set_key_value(self, key="cpu_guarantee", value=user_quotas.get(
228+
"quota-ws-guaranteecpu"))
229229
set_key_value(self, key="cpu_limit",
230-
value=float(user_quotas.get("quota-ws-maxcpu")))
230+
value=user_quotas.get("quota-ws-maxcpu"))
231231
set_key_value(self, key="mem_guarantee", value=user_quotas.get(
232232
"quota-ws-guaranteemem"), unit="G")
233233
set_key_value(self, key="mem_limit", value=user_quotas.get(

libraries/cloudharness-common/cloudharness/auth/quota.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from keycloak import KeycloakError
23
from .keycloak import AuthClient
34
from cloudharness.applications import get_current_configuration
@@ -93,17 +94,23 @@ def _compute_quotas_from_tree(node: QuotaNode):
9394
child_attrs = _compute_quotas_from_tree(child)
9495
for key in child_attrs:
9596
try:
96-
child_val = float(child_attrs[key])
97+
# we expect all quota values to be numbers: the unit is implicit and
98+
# defined at usage time
99+
child_val = attribute_to_quota(child_attrs[key])
97100
except:
98-
# value not a float, skip (use 0)
99-
child_val = 0
101+
# value not a float, skip
102+
continue
100103
if not key in new_attrs or new_attrs[key] < child_val:
101104
new_attrs.update({key: child_val})
102105
for key in new_attrs:
103106
node.attrs.update({key: new_attrs[key]})
104107
return node.attrs
105108

106109

110+
def attribute_to_quota(attr_value: str):
111+
return float(re.sub("[^0-9.]", "", attr_value))
112+
113+
107114
def get_user_quotas(application_config: ApplicationConfig = None, user_id: str = None) -> dict:
108115
"""Get the user quota from Keycloak and application
109116
@@ -142,5 +149,5 @@ def get_user_quotas(application_config: ApplicationConfig = None, user_id: str =
142149
user_quotas.update({key: group_quotas[key]})
143150
for key in base_quotas:
144151
if key not in user_quotas:
145-
user_quotas.update({key: base_quotas[key]})
152+
user_quotas.update({key: attribute_to_quota(base_quotas[key])})
146153
return user_quotas

0 commit comments

Comments
 (0)