From 6c9c219eb0444648c38545ce60d38a30ffa5f165 Mon Sep 17 00:00:00 2001 From: Benjamin Schanzel Date: Mon, 15 Aug 2022 14:42:50 +0200 Subject: [PATCH] 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 --- doc/source/kubernetes.rst | 16 ++++++++++++++++ nodepool/driver/kubernetes/config.py | 4 ++++ nodepool/driver/kubernetes/provider.py | 2 ++ ...ubernetes-storage-limit-c87497ac74a10d96.yaml | 15 +++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 releasenotes/notes/kubernetes-storage-limit-c87497ac74a10d96.yaml diff --git a/doc/source/kubernetes.rst b/doc/source/kubernetes.rst index b66ea4453..98984067e 100644 --- a/doc/source/kubernetes.rst +++ b/doc/source/kubernetes.rst @@ -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: [] diff --git a/nodepool/driver/kubernetes/config.py b/nodepool/driver/kubernetes/config.py index 6b238a98e..d84160cb6 100644 --- a/nodepool/driver/kubernetes/config.py +++ b/nodepool/driver/kubernetes/config.py @@ -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 = { diff --git a/nodepool/driver/kubernetes/provider.py b/nodepool/driver/kubernetes/provider.py index 1d96f2d7a..d92936fdc 100644 --- a/nodepool/driver/kubernetes/provider.py +++ b/nodepool/driver/kubernetes/provider.py @@ -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 = { diff --git a/releasenotes/notes/kubernetes-storage-limit-c87497ac74a10d96.yaml b/releasenotes/notes/kubernetes-storage-limit-c87497ac74a10d96.yaml new file mode 100644 index 000000000..5a5af5166 --- /dev/null +++ b/releasenotes/notes/kubernetes-storage-limit-c87497ac74a10d96.yaml @@ -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` +