Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix label values #1528

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change k8s env values to string
  • Loading branch information
micafer committed Feb 16, 2024
commit fc94e6bb6d60eae0d1984d0dbadbb89493585940
10 changes: 7 additions & 3 deletions IM/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,13 @@ def _generate_service_data(self, namespace, name, outports):
@staticmethod
def _get_env_variables(radl_system):
env_vars = []
for elem in radl_system.getValue("environment.variables", []):
parts = elem.split(":")
env_vars.append({'name': parts[0], 'value': ":".join(parts[1:])})
if radl_system.getValue('environment.variables'):
keypairs = radl_system.getValue('environment.variables').split(",")
for keypair in keypairs:
parts = keypair.split("=")
key = parts[0].strip()
value = parts[1].strip()
env_vars.append({'name': key, 'value': value})
return env_vars

def _generate_pod_data(self, namespace, name, outports, system, volumes, tags):
Expand Down
8 changes: 5 additions & 3 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,10 +2175,12 @@ def _gen_k8s_system(self, node, nodetemplates):
value = self._final_function_result(prop.value, node)
if value not in [None, [], {}]:
if prop.name == "environment":
env = []
variables = ""
for k, v in value.items():
env.append("%s:%s" % (k, v))
res.setValue('environment.variables', env)
if variables != "":
variables += ","
variables += "%s=%s" % (k, v)
res.setValue("environment.variables", variables)

runtime = self._find_host_node(node, nodetemplates, base_root_type="tosca.nodes.SoftwareComponent")

Expand Down
2 changes: 1 addition & 1 deletion test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def test_tosca_k8s(self):
self.assertEqual(node.getValue("memory.size"), 2000000000)
self.assertEqual(node.getValue("disk.1.size"), 10000000000)
self.assertEqual(node.getValue("disk.1.mount_path"), '/some/path')
self.assertEqual(node.getValue("environment.variables"), ['MYSQL_ROOT_PASSWORD:my-secret'])
self.assertEqual(node.getValue("environment.variables"), 'MYSQL_ROOT_PASSWORD=my-secret')
net = radl.get_network_by_id('mysql_container_pub')
self.assertEqual(net.getValue("outports"), '33306/tcp-3306/tcp')
self.assertEqual(net.getValue("outbound"), 'yes')
Expand Down
2 changes: 1 addition & 1 deletion test/unit/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_20_launch(self, save_data, requests):
memory.size>=512m and
net_interface.0.connection = 'net' and
net_interface.0.dns_name = 'test' and
environment.variables = ['var:some_val'] and
environment.variables = 'var=some_val' and
instance_tags = 'key=_inva:lid_' and
disk.0.os.name = 'linux' and
disk.0.image.url = 'docker://someimage' and
Expand Down