From 42b33dc3cba15a22214295770756c94f9be08f11 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 22 Jun 2018 14:53:22 +0100 Subject: Add "tolerations" parameter in Kubernetes context This new parameter, "torelations", is applied to pods and allow (but not require) the pods to schedule onto node with matching tains [1]. Example of "tolerations" definition in a Kubernetes pod: spec: containers: [...] tolerations: - key: value: effect: operator: - key: ... Example of "tolerations" definition in a Yardstick test case: context: type: Kubernetes servers: host: containers: [...] tolerations: - key: ... value: ... effect: ... operator: ... NOTE: if any toleration is defined, a default one will be applied in order to allow any replication controller to create the pods in any Kubernetes node. This default toleration is defined as: spec: tolerations: - operator: "Exists" [1] https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/ JIRA: YARDSTICK-1254 Change-Id: I32fb9c7086b4218c323218738057f634eb6ffff4 Signed-off-by: Rodolfo Alonso Hernandez --- yardstick/orchestrator/kubernetes.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'yardstick/orchestrator') diff --git a/yardstick/orchestrator/kubernetes.py b/yardstick/orchestrator/kubernetes.py index 6fd3fa640..3c7559c7d 100644 --- a/yardstick/orchestrator/kubernetes.py +++ b/yardstick/orchestrator/kubernetes.py @@ -89,6 +89,7 @@ class ReplicationControllerObject(object): SSHKEY_DEFAULT = 'yardstick_key' RESTART_POLICY = ('Always', 'OnFailure', 'Never') + TOLERATIONS_KEYS = ('key', 'value', 'effect', 'operator') def __init__(self, name, **kwargs): super(ReplicationControllerObject, self).__init__() @@ -99,6 +100,7 @@ class ReplicationControllerObject(object): self._volumes = parameters.pop('volumes', []) self._security_context = parameters.pop('securityContext', None) self._networks = parameters.pop('networks', []) + self._tolerations = parameters.pop('tolerations', []) self._restart_policy = parameters.pop('restartPolicy', 'Always') if self._restart_policy not in self.RESTART_POLICY: raise exceptions.KubernetesWrongRestartPolicy( @@ -129,7 +131,8 @@ class ReplicationControllerObject(object): "containers": [], "volumes": [], "nodeSelector": {}, - "restartPolicy": self._restart_policy + "restartPolicy": self._restart_policy, + "tolerations": [] } } } @@ -141,6 +144,7 @@ class ReplicationControllerObject(object): self._add_volumes() self._add_security_context() self._add_networks() + self._add_tolerations() def get_template(self): return self.template @@ -211,6 +215,18 @@ class ReplicationControllerObject(object): 'spec.template.metadata.annotations', annotations) + def _add_tolerations(self): + tolerations = [] + for tol in self._tolerations: + tolerations.append({k: tol[k] for k in tol + if k in self.TOLERATIONS_KEYS}) + + tolerations = ([{'operator': 'Exists'}] if not tolerations + else tolerations) + utils.set_dict_value(self.template, + 'spec.template.spec.tolerations', + tolerations) + class ServiceNodePortObject(object): -- cgit 1.2.3-korg