summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/orchestrator/kubernetes.py7
-rw-r--r--yardstick/tests/unit/orchestrator/test_kubernetes.py18
2 files changed, 25 insertions, 0 deletions
diff --git a/yardstick/orchestrator/kubernetes.py b/yardstick/orchestrator/kubernetes.py
index f690ab3e9..07a7ab1b6 100644
--- a/yardstick/orchestrator/kubernetes.py
+++ b/yardstick/orchestrator/kubernetes.py
@@ -22,6 +22,7 @@ class ContainerObject(object):
SSH_MOUNT_PATH = '/tmp/.ssh/'
IMAGE_DEFAULT = 'openretriever/yardstick'
COMMAND_DEFAULT = '/bin/bash'
+ RESOURCES = ['requests', 'limits']
def __init__(self, name, ssh_key, **kwargs):
self._name = name
@@ -32,6 +33,7 @@ class ContainerObject(object):
self._volume_mounts = kwargs.get('volumeMounts', [])
self._security_context = kwargs.get('securityContext')
self._env = kwargs.get('env', [])
+ self._resources = kwargs.get('resources', {})
def _create_volume_mounts(self):
"""Return all "volumeMounts" items per container"""
@@ -64,6 +66,11 @@ class ContainerObject(object):
for env in self._env:
container['env'].append({'name': env['name'],
'value': env['value']})
+ if self._resources:
+ container['resources'] = {}
+ for res in (res for res in self._resources if
+ res in self.RESOURCES):
+ container['resources'][res] = self._resources[res]
return container
diff --git a/yardstick/tests/unit/orchestrator/test_kubernetes.py b/yardstick/tests/unit/orchestrator/test_kubernetes.py
index 5eba1a02a..2451518a4 100644
--- a/yardstick/tests/unit/orchestrator/test_kubernetes.py
+++ b/yardstick/tests/unit/orchestrator/test_kubernetes.py
@@ -302,6 +302,24 @@ class ContainerObjectTestCase(base.BaseUnitTestCase):
'value': 'fake_var_value'}]}
self.assertEqual(expected, container_obj.get_container_item())
+ def test_get_container_item_with_resources(self):
+ volume_mount = {'name': 'fake_name',
+ 'mountPath': 'fake_path'}
+ args = ['arg1', 'arg2']
+ resources = {'requests': {'key1': 'val1'},
+ 'limits': {'key2': 'val2'},
+ 'other_key': {'key3': 'val3'}}
+ container_obj = kubernetes.ContainerObject(
+ 'cname', ssh_key='fake_sshkey', volumeMount=[volume_mount],
+ args=args, resources=resources)
+ expected = {'args': args,
+ 'command': [kubernetes.ContainerObject.COMMAND_DEFAULT],
+ 'image': kubernetes.ContainerObject.IMAGE_DEFAULT,
+ 'name': 'cname-container',
+ 'volumeMounts': container_obj._create_volume_mounts(),
+ 'resources': {'requests': {'key1': 'val1'},
+ 'limits': {'key2': 'val2'}}}
+ self.assertEqual(expected, container_obj.get_container_item())
class CustomResourceDefinitionObjectTestCase(base.BaseUnitTestCase):