Add nodeSelector to enable selecting the desired 21/43721/1
authorTrevor Tao <trevor.tao@arm.com>
Thu, 21 Sep 2017 06:43:29 +0000 (14:43 +0800)
committerRoss Brattain <ross.b.brattain@intel.com>
Sat, 30 Sep 2017 08:23:07 +0000 (01:23 -0700)
Kubernetes running node when creating containers for
Kubernetes context

For example, a yaml file may looks like:
 servers:
    host:
      image: xxx
      command: /bin/bash
      nodeSelector:
          xxx: yyy

Synchronously change the unit test for this function

Change-Id: If74c9dad9b1a70395bb79f34708a0fde04e7e650
Signed-off-by: Trevor Tao <trevor.tao@arm.com>
tests/unit/orchestrator/test_kubernetes.py
yardstick/orchestrator/kubernetes.py

index 51718ab..1a3291c 100644 (file)
@@ -62,7 +62,10 @@ service ssh restart;while true ; do sleep 10000; done"
                                 },
                                 "name": "k8s-86096c30-key"
                             }
-                        ]
+                        ],
+                        "nodeSelector": {
+                           "kubernetes.io/hostname": "node-01"
+                        }
                     }
                 }
             }
@@ -71,7 +74,8 @@ service ssh restart;while true ; do sleep 10000; done"
             'command': '/bin/bash',
             'args': ['-c', 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/*; \
 service ssh restart;while true ; do sleep 10000; done'],
-            'ssh_key': 'k8s-86096c30-key'
+            'ssh_key': 'k8s-86096c30-key',
+            'nodeSelector': { 'kubernetes.io/hostname': 'node-01'}
         }
         name = 'host-k8s-86096c30'
         output_r = KubernetesObject(name, **input_s).get_template()
index 9f94fd4..198eeac 100644 (file)
@@ -23,6 +23,7 @@ class KubernetesObject(object):
         self.command = [kwargs.get('command', '/bin/bash')]
         self.args = kwargs.get('args', [])
         self.ssh_key = kwargs.get('ssh_key', 'yardstick_key')
+        self.node_selector = kwargs.get('nodeSelector', {})
 
         self.volumes = []
 
@@ -42,7 +43,8 @@ class KubernetesObject(object):
                     },
                     "spec": {
                         "containers": [],
-                        "volumes": []
+                        "volumes": [],
+                        "nodeSelector": {}
                     }
                 }
             }
@@ -50,6 +52,7 @@ class KubernetesObject(object):
 
         self._change_value_according_name(name)
         self._add_containers()
+        self._add_node_selector()
         self._add_ssh_key_volume()
         self._add_volumes()
 
@@ -88,6 +91,11 @@ class KubernetesObject(object):
 
         return container
 
+    def _add_node_selector(self):
+        utils.set_dict_value(self.template,
+                             'spec.template.spec.nodeSelector',
+                             self.node_selector)
+
     def _add_volumes(self):
         utils.set_dict_value(self.template,
                              'spec.template.spec.volumes',