Add config option to limit ephemeral storage on K8s Pod labels

This adds config options for limiting the amount of ephemeral storage
allocatable by a container of a K8s Pod-type label.
This optional config translates to K8s settings

* spec.containers[].resources.limits.ephemeral-storage
* spec.containers[].resources.requests.ephemeral-storage

This is to provide a mechanism that prevents Pods from filling up their
hosts storage and thereby interfering with or breaking other workloads
on the same host (esp. on shared clusters).

Like for cpu and memory limits, a pool-scoped default can also be
specified.

Change-Id: I23e90ae53cc2b2eb0e51cc9e3dc5802c86cc0ac9
This commit is contained in:
Benjamin Schanzel 2022-08-15 14:42:50 +02:00
parent 95b3d4c302
commit 6c9c219eb0
No known key found for this signature in database
4 changed files with 37 additions and 0 deletions

View File

@ -135,6 +135,15 @@ Selecting the kubernetes driver adds the following options to the
:attr:`providers.[kubernetes].pools.labels.memory` for all labels of
this pool that do not set their own value.
.. attr:: default-label-storage
:type: int
Only used by the
:value:`providers.[kubernetes].pools.labels.type.pod` label type;
specifies a default value in MB for
:attr:`providers.[kubernetes].pools.labels.storage` for all labels of
this pool that do not set their own value.
.. attr:: labels
:type: list
@ -218,6 +227,13 @@ Selecting the kubernetes driver adds the following options to the
:value:`providers.[kubernetes].pools.labels.type.pod` label type;
specifies the amount of memory in MB to request for the pod.
.. attr:: storage
:type: int
Only used by the
:value:`providers.[kubernetes].pools.labels.type.pod` label type;
specifies the amount of ephemeral-storage in MB to request for the pod.
.. attr:: env
:type: list
:default: []

View File

@ -41,6 +41,7 @@ class KubernetesPool(ConfigPool):
self.max_ram = pool_config.get('max-ram')
self.default_label_cpu = pool_config.get('default-label-cpu')
self.default_label_memory = pool_config.get('default-label-memory')
self.default_label_storage = pool_config.get('default-label-storage')
self.labels = {}
for label in pool_config.get('labels', []):
pl = KubernetesLabel()
@ -52,6 +53,7 @@ class KubernetesPool(ConfigPool):
pl.shell_type = label.get('shell-type')
pl.cpu = label.get('cpu', self.default_label_cpu)
pl.memory = label.get('memory', self.default_label_memory)
pl.storage = label.get('storage', self.default_label_storage)
pl.env = label.get('env', [])
pl.node_selector = label.get('node-selector')
pl.pool = self
@ -97,6 +99,7 @@ class KubernetesProviderConfig(ProviderConfig):
'shell-type': str,
'cpu': int,
'memory': int,
'storage': int,
'env': [env_var],
'node-selector': dict,
}
@ -109,6 +112,7 @@ class KubernetesProviderConfig(ProviderConfig):
v.Optional('max-ram'): int,
v.Optional('default-label-cpu'): int,
v.Optional('default-label-memory'): int,
v.Optional('default-label-storage'): int,
})
provider = {

View File

@ -276,6 +276,8 @@ class KubernetesProvider(Provider, QuotaSupport):
rbody['cpu'] = int(label.cpu)
if label.memory:
rbody['memory'] = '%dMi' % int(label.memory)
if label.storage:
rbody['ephemeral-storage'] = '%dM' % int(label.storage)
container_body['resources'][rtype] = rbody
spec_body = {

View File

@ -0,0 +1,15 @@
---
features:
- |
A new configuration option for K8s Pod type labels was added to limit the
amount of ephemeral storage allocatable in a container (cf. `K8s Local
ephemeral storage resource documentation`
<https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#local-ephemeral-storage`__)
This limit can be set via the integer value of
:attr:`providers.[kubernetes].pools.labels.storage`
and is treated as Megabytes. Also, a pool-scoped default value can be
specified via
:attr:`providers.[kubernetes].pools.default-label-storage`