diff --git a/IM/connectors/Kubernetes.py b/IM/connectors/Kubernetes.py index 1fd74d40..c2392fea 100644 --- a/IM/connectors/Kubernetes.py +++ b/IM/connectors/Kubernetes.py @@ -461,6 +461,14 @@ def _generate_pod_data(self, namespace, name, outports, system, volumes, configm if system.getValue("docker.privileged") == 'yes': containers[0]['securityContext'] = {'privileged': True} + if system.getValue('command'): + command = system.getValue('command') + if command and not isinstance(command, list): + command = command.split() + containers[0]["command"] = [command[0]] + if len(command) > 1: + containers[0]["args"] = command[1:] + pod_data['spec'] = {'restartPolicy': 'OnFailure'} if volumes: diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index 1a01449c..7ccbc088 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -2205,6 +2205,8 @@ def _gen_k8s_system(self, node, nodetemplates): variables += "," variables += "%s=%s" % (k, v) res.setValue("environment.variables", variables) + elif prop.name == "command": + res.setValue("command", value) runtime = self._find_host_node(node, nodetemplates, node_type="tosca.nodes.Container.Runtime.Docker") diff --git a/test/files/tosca_k8s.yml b/test/files/tosca_k8s.yml index 577a15a7..7f02bd36 100644 --- a/test/files/tosca_k8s.yml +++ b/test/files/tosca_k8s.yml @@ -33,6 +33,7 @@ topology_template: im_container: type: tosca.nodes.Container.Application.Docker properties: + command: ["/bin/sh", "-c", "im_service.py"] environment: IM_DATA_DB: concat: diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index b05edb01..a52f79b4 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -453,6 +453,7 @@ def test_tosca_k8s(self): node = radl.get_system_by_name('im_container') self.assertEqual(node.getValue("disk.0.image.url"), "docker://grycap/im") + self.assertEqual(node.getValue("command"), ["/bin/sh", "-c", "im_service.py"]) net = radl.get_network_by_id('im_container_pub') self.assertEqual(net.getValue("outports"), '30880/tcp-8800/tcp') self.assertEqual(net.getValue("outbound"), 'yes') diff --git a/test/unit/connectors/Kubernetes.py b/test/unit/connectors/Kubernetes.py index 0921f0d5..758130bc 100755 --- a/test/unit/connectors/Kubernetes.py +++ b/test/unit/connectors/Kubernetes.py @@ -149,6 +149,7 @@ def test_20_launch(self, save_data, requests): instance_tags = 'key=_inva:lid_' and disk.0.os.name = 'linux' and disk.0.image.url = 'docker://someimage' and + command = ['/bin/bash', '-c', 'sleep 100'] and disk.1.size = 10G and disk.1.mount_path = '/mnt' and disk.2.mount_path = '/etc/config' and @@ -230,6 +231,8 @@ def test_20_launch(self, save_data, requests): "containers": [ { "name": "test", + "command": ["/bin/bash"], + "args": ["-c", "sleep 100"], "image": "someimage", "imagePullPolicy": "Always", "ports": [{"containerPort": 8080, "protocol": "TCP"}],