Skip to content

Commit

Permalink
Improve k8s with configmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Feb 23, 2024
1 parent 42e2eb2 commit f1e14e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions IM/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ def _generate_pod_data(self, namespace, name, outports, system, volumes, configm
containers[0]['volumeMounts'] = containers[0].get('volumeMounts', [])
for (cm_name, cm_mount_path) in configmaps:
containers[0]['volumeMounts'].append(
{'name': cm_name, 'mountPath': cm_mount_path, 'readOnly': True})
{'name': cm_name, 'mountPath': cm_mount_path, "readOnly": True,
'subPath': os.path.basename(cm_mount_path)})

pod_data['spec'] = {'containers': containers, 'restartPolicy': 'OnFailure'}

Expand All @@ -462,11 +463,11 @@ def _generate_pod_data(self, namespace, name, outports, system, volumes, configm
{'name': v_name, 'persistentVolumeClaim': {'claimName': v_name}})

if configmaps:
pod_data['spec']['volumes'] = pod_data['spec'].get('volumes', [])
for (cm_name, _) in configmaps:
pod_data['spec']['volumes'].append(
{'name': cm_name,
'configMap': {'name': cm_name,
'items': [{'key': os.path.basename(cm_mount_path), 'path': cm_mount_path}]}})
'configMap': {'name': cm_name}})

return pod_data

Expand Down
6 changes: 3 additions & 3 deletions test/unit/connectors/Kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ def test_20_launch(self, save_data, requests):
},
"env": [{"name": "var", "value": "some_val"}],
"volumeMounts": [{"name": "test-1", "mountPath": "/mnt"},
{'mountPath': '/etc/config', 'name': 'test-cm-2', 'readOnly': True}],
{'mountPath': '/etc/config', 'name': 'test-cm-2',
'readOnly': True, 'subPath': 'config'}],
}
],
"restartPolicy": "OnFailure",
"volumes": [
{"name": "test-1", "persistentVolumeClaim": {"claimName": "test-1"}},
{"name": "test-cm-2", "configMap": {"name": "test-cm-2",
"items": [{"key": "config", "path": "/etc/config"}]}},
{"name": "test-cm-2", "configMap": {"name": "test-cm-2"}},
],
},
}
Expand Down

0 comments on commit f1e14e3

Please sign in to comment.