Skip to content

Commit f377d91

Browse files
authored
Merge pull request #1618 from grycap/devel
Devel
2 parents c066a9f + e2de8a1 commit f377d91

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

IM/connectors/Kubernetes.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ def _generate_ingress_data(self, namespace, name, dns, port, apps_dns):
370370
if dns_url[1]:
371371
host = dns_url[1]
372372
if apps_dns and not host.endswith(apps_dns):
373-
host += "." + apps_dns
373+
if not host.endswith(".") and not apps_dns.startswith("."):
374+
host += "."
375+
host += apps_dns
374376
if dns_url[2]:
375377
path = dns_url[2]
376378

@@ -422,12 +424,13 @@ def _gen_basic_k8s_elem(namespace, name, kind, version="v1"):
422424
def _get_env_variables(radl_system):
423425
env_vars = []
424426
if radl_system.getValue('environment.variables'):
425-
keypairs = radl_system.getValue('environment.variables').split(",")
426-
for keypair in keypairs:
427-
parts = keypair.split("=")
428-
key = parts[0].strip()
429-
value = parts[1].strip()
430-
env_vars.append({'name': key, 'value': value})
427+
# Parse the environment variables
428+
# The pattern is: key="value" or key=value
429+
# in case of value with commas it should be enclosed in double quotes
430+
pattern = r'([^,=]+)=(".*?(?<!\\)"|[^,]*)'
431+
keypairs = re.findall(pattern, radl_system.getValue('environment.variables'))
432+
for key, value in keypairs:
433+
env_vars.append({'name': key.strip(), 'value': value.strip(' "')})
431434
return env_vars
432435

433436
def _generate_pod_data(self, namespace, name, outports, system, volumes, configmaps, tags):

IM/tosca/Tosca.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2150,13 +2150,13 @@ def _gen_k8s_volumes(self, node, nodetemplates, value, cont=1):
21502150
cont += 1
21512151
return volumes
21522152

2153-
def _gen_k8s_configmaps(self, res, cms):
2153+
def _gen_k8s_configmaps(self, res, cms, node):
21542154
"""Get the configmaps attached to an K8s container."""
21552155
cont = 1
21562156
for cm in cms:
21572157
mount_path = cm.get("deploy_path")
21582158
cm_file = cm.get("file")
2159-
content = cm.get("properties", {}).get("content", "")
2159+
content = self._final_function_result(cm.get("properties", {}).get("content", ""), node)
21602160
if content:
21612161
res.setValue('disk.%d.content' % cont, content)
21622162
# if content is not empty file is ignored
@@ -2186,7 +2186,7 @@ def _gen_k8s_system(self, node, nodetemplates):
21862186
if not image:
21872187
raise Exception("No image specified for K8s container.")
21882188

2189-
cont = self._gen_k8s_configmaps(res, cms)
2189+
cont = self._gen_k8s_configmaps(res, cms, node)
21902190

21912191
repo = artifact.get("repository", None)
21922192
if repo:
@@ -2206,6 +2206,8 @@ def _gen_k8s_system(self, node, nodetemplates):
22062206
for k, v in value.items():
22072207
if variables != "":
22082208
variables += ","
2209+
if ',' in v:
2210+
v = '"%s"' % v
22092211
variables += "%s=%s" % (k, v)
22102212
res.setValue("environment.variables", variables)
22112213
elif prop.name == "command":

doc/source/client.rst

+3
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ The available keys are:
367367

368368
* ``namespace`` indicates a namespace name to be associated to the Kubernetes credential (from version 1.7.1).
369369

370+
* ``apps_dns`` indicates a DNS domain used by the Kubernetes provider to expose application URLs.
371+
(from version 1.7.1).
372+
370373
Vault Credentials support
371374
^^^^^^^^^^^^^^^^^^^^^^^^^
372375

test/files/tosca_k8s.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ topology_template:
5656
# when the content is not provided, the file is downloaded from the URL
5757
# otherwise, the file is ignored
5858
# If the content is base64 encoded, it is assumed to be a K8s Secret
59-
content: |
60-
[im]
61-
REST_API = True
59+
content:
60+
concat:
61+
- |-
62+
[im]
63+
REST_API =
64+
- "True"
6265
my_secret:
6366
deploy_path: /etc/secret
6467
type: tosca.artifacts.File
@@ -86,6 +89,7 @@ topology_template:
8689
environment:
8790
MYSQL_ROOT_PASSWORD: { get_input: mysql_root_password }
8891
MYSQL_DATABASE: "im-db"
92+
TEST: "some,value"
8993
requirements:
9094
- host: mysql_runtime
9195
artifacts:

test/unit/Tosca.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ def test_tosca_k8s(self):
442442
self.assertEqual(node.getValue("memory.size"), 1000000000)
443443
self.assertEqual(node.getValue("disk.1.size"), 10000000000)
444444
self.assertEqual(node.getValue("disk.1.mount_path"), '/var/lib/mysql')
445-
self.assertEqual(node.getValue("environment.variables"), 'MYSQL_ROOT_PASSWORD=my-secret,MYSQL_DATABASE=im-db')
445+
self.assertEqual(node.getValue("environment.variables"),
446+
'MYSQL_ROOT_PASSWORD=my-secret,MYSQL_DATABASE=im-db,TEST="some,value"')
446447
self.assertEqual(node.getValue("net_interface.0.connection"), 'mysql_container_priv')
447448
self.assertIsNone(node.getValue("net_interface.1.connection"))
448449
net = radl.get_network_by_id('mysql_container_priv')
@@ -457,7 +458,7 @@ def test_tosca_k8s(self):
457458
net = radl.get_network_by_id('im_container_pub')
458459
self.assertEqual(net.getValue("outports"), '30880/tcp-8800/tcp')
459460
self.assertEqual(net.getValue("outbound"), 'yes')
460-
self.assertEqual(node.getValue("disk.1.content"), '[im]\nREST_API = True\n')
461+
self.assertEqual(node.getValue("disk.1.content"), '[im]\nREST_API = True')
461462
self.assertEqual(node.getValue("disk.1.mount_path"), '/etc/im/im.cfg')
462463
self.assertEqual(node.getValue("disk.2.content"), 'c29tZSBlbmNvZGVkIGNvbnRlbnQ=')
463464
self.assertEqual(node.getValue("disk.2.mount_path"), '/etc/secret')

test/unit/connectors/Kubernetes.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_20_launch(self, save_data, requests):
145145
memory.size>=512m and
146146
net_interface.0.connection = 'net' and
147147
net_interface.0.dns_name = 'https://ingress.domain.com/path' and
148-
environment.variables = 'var=some_val' and
148+
environment.variables = 'var=some_val,var2="some,val2"' and
149149
instance_tags = 'key=_inva:lid_' and
150150
disk.0.os.name = 'linux' and
151151
disk.0.image.url = 'docker://someimage' and
@@ -240,7 +240,8 @@ def test_20_launch(self, save_data, requests):
240240
"limits": {"cpu": "1", "memory": "536870912"},
241241
"requests": {"cpu": "1", "memory": "536870912"},
242242
},
243-
"env": [{"name": "var", "value": "some_val"}],
243+
"env": [{"name": "var", "value": "some_val"},
244+
{"name": "var2", "value": "some,val2"}],
244245
"volumeMounts": [{"name": "test-1", "mountPath": "/mnt"},
245246
{'mountPath': '/etc/config', 'name': 'test-cm-2',
246247
'readOnly': True, 'subPath': 'config'},

0 commit comments

Comments
 (0)