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 --- .../tests/unit/orchestrator/test_kubernetes.py | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'yardstick/tests/unit/orchestrator') diff --git a/yardstick/tests/unit/orchestrator/test_kubernetes.py b/yardstick/tests/unit/orchestrator/test_kubernetes.py index afadf748a..cc1b37569 100644 --- a/yardstick/tests/unit/orchestrator/test_kubernetes.py +++ b/yardstick/tests/unit/orchestrator/test_kubernetes.py @@ -67,7 +67,10 @@ service ssh restart;while true ; do sleep 10000; done" "nodeSelector": { "kubernetes.io/hostname": "node-01" }, - "restartPolicy": "Always" + "restartPolicy": "Always", + "tolerations": [ + {"operator": "Exists"} + ] } } } @@ -231,6 +234,30 @@ class ReplicationControllerObjectTestCase(base.BaseUnitTestCase): '{"name": "network3"}]') self.assertEqual(expected, networks) + def test__add_tolerations(self): + _kwargs = {'tolerations': [{'key': 'key1', + 'value': 'value2', + 'effect': 'effect3', + 'operator': 'operator4', + 'wrong_key': 'error_key'}] + } + k8s_obj = kubernetes.ReplicationControllerObject('pod_name', **_kwargs) + k8s_obj._add_tolerations() + _tol = k8s_obj.template['spec']['template']['spec']['tolerations'] + self.assertEqual(1, len(_tol)) + self.assertEqual({'key': 'key1', + 'value': 'value2', + 'effect': 'effect3', + 'operator': 'operator4'}, + _tol[0]) + + def test__add_tolerations_default(self): + k8s_obj = kubernetes.ReplicationControllerObject('pod_name') + k8s_obj._add_tolerations() + _tol = k8s_obj.template['spec']['template']['spec']['tolerations'] + self.assertEqual(1, len(_tol)) + self.assertEqual({'operator': 'Exists'}, _tol[0]) + class ContainerObjectTestCase(base.BaseUnitTestCase): -- cgit 1.2.3-korg