Skip to content

Commit

Permalink
Merge pull request #1600 from grycap/devel
Browse files Browse the repository at this point in the history
Add command to container app
  • Loading branch information
micafer authored Jul 24, 2024
2 parents 906d00a + 5567ce4 commit 30ba415
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions IM/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions test/files/tosca_k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions test/unit/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}],
Expand Down

0 comments on commit 30ba415

Please sign in to comment.