Skip to content

Commit 83d3451

Browse files
committed
chore(quota): add kube quota config
1 parent 612a380 commit 83d3451

3 files changed

Lines changed: 19 additions & 30 deletions

File tree

rootfs/api/models/app.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,12 +1100,6 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas):
11001100
pod_termination_grace_period_seconds = int(config.values.get(
11011101
'KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', settings.KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS)) # noqa
11021102

1103-
# get limits and requests ephemeral_storage
1104-
ephemeral_storage = "{}/{}".format(
1105-
settings.KUBERNETES_REQUESTS_EPHEMERAL_STORAGE,
1106-
settings.KUBERNETES_LIMITS_EPHEMERAL_STORAGE,
1107-
)
1108-
11091103
# set the image pull policy that is associated with the application container
11101104
image_pull_policy = config.values.get('IMAGE_PULL_POLICY', settings.IMAGE_PULL_POLICY)
11111105

@@ -1123,7 +1117,6 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas):
11231117
return {
11241118
'memory': config.memory,
11251119
'cpu': config.cpu,
1126-
'ephemeral_storage': ephemeral_storage,
11271120
'tags': config.tags,
11281121
'envs': envs,
11291122
'registry': config.registry,
@@ -1142,7 +1135,7 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas):
11421135
'pod_termination_grace_period_seconds': pod_termination_grace_period_seconds,
11431136
'pod_termination_grace_period_each': config.termination_grace_period,
11441137
'image_pull_secret_name': image_pull_secret_name,
1145-
'image_pull_policy': image_pull_policy
1138+
'image_pull_policy': image_pull_policy,
11461139
}
11471140

11481141
def set_application_config(self, release):

rootfs/api/settings/production.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,19 @@
334334
KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS = int(os.environ.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', 30)) # noqa
335335

336336
# Default quota spec for application namespace
337-
KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC = os.environ.get('KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC', '') # noqa
338-
339-
# See spec.containers[].resources.requests.ephemeral-storage
340-
KUBERNETES_REQUESTS_EPHEMERAL_STORAGE = os.environ.get('KUBERNETES_REQUESTS_EPHEMERAL_STORAGE', '1Gi') # noqa
341-
342-
# See spec.containers[].resources.limits.ephemeral-storage
343-
KUBERNETES_LIMITS_EPHEMERAL_STORAGE = os.environ.get('KUBERNETES_LIMITS_EPHEMERAL_STORAGE', '2Gi') # noqa
337+
KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC = os.environ.get(
338+
'KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC',
339+
json.dumps({"spec": {
340+
"hard": {
341+
"cpu": "4",
342+
"memory": "4Gi",
343+
"pods": "2",
344+
"ephemeral-storage": "1Gi",
345+
"requests.storage": "10Gi",
346+
"persistentvolumeclaims": 8,
347+
}
348+
}})
349+
)
344350

345351
# registry settings
346352
REGISTRY_HOST = os.environ.get('DRYCC_REGISTRY_PROXY_HOST', '127.0.0.1')

rootfs/scheduler/resources/pod.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,15 @@ def _set_resources(self, container, kwargs):
231231
app_type = kwargs.get("app_type")
232232
mem = kwargs.get("memory", {}).get(app_type)
233233
cpu = kwargs.get("cpu", {}).get(app_type)
234-
ephemeral_storage = kwargs.get("ephemeral_storage")
235-
resources = defaultdict(dict)
236234
if mem or cpu:
235+
resources = defaultdict(dict)
237236
if mem:
238237
if "/" in mem:
239238
parts = mem.split("/")
240-
resources["requests"]["memory"] = self._format_size(parts[0])
241-
resources["limits"]["memory"] = self._format_size(parts[1])
239+
resources["requests"]["memory"] = self._get_memory(parts[0])
240+
resources["limits"]["memory"] = self._get_memory(parts[1])
242241
else:
243-
resources["limits"]["memory"] = self._format_size(mem)
242+
resources["limits"]["memory"] = self._get_memory(mem)
244243
if cpu:
245244
# CPU needs to be defined as lower case
246245
if "/" in cpu:
@@ -249,15 +248,6 @@ def _set_resources(self, container, kwargs):
249248
resources["limits"]["cpu"] = parts[1].lower()
250249
else:
251250
resources["limits"]["cpu"] = cpu.lower()
252-
if ephemeral_storage:
253-
# ephemeral_storage needs to be defined as lower case
254-
if "/" in ephemeral_storage:
255-
parts = ephemeral_storage.split("/")
256-
resources["requests"]["ephemeral_storage"] = self._format_size(parts[0])
257-
resources["limits"]["ephemeral_storage"] = self._format_size(parts[1])
258-
else:
259-
resources["limits"]["ephemeral_storage"] = self._format_size(
260-
ephemeral_storage)
261251
if resources:
262252
container["resources"] = dict(resources)
263253

@@ -271,7 +261,7 @@ def _get_termination_grace_period(kwargs):
271261
return timeout_global if timeout_local is None else int(timeout_local)
272262

273263
@staticmethod
274-
def _format_size(size):
264+
def _get_memory(size, ):
275265
""" Format memory limit value """
276266
if size[-2:-1].isalpha() and size[-1].isalpha():
277267
size = size[:-1]

0 commit comments

Comments
 (0)