Skip to content

Commit

Permalink
Volume processing fixes (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
dboreham authored Feb 6, 2024
1 parent 3d5ecec commit bfbcfb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
32 changes: 23 additions & 9 deletions stack_orchestrator/deploy/k8s/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ def volume_mounts_for_service(parsed_pod_files, service):
if "volumes" in service_obj:
volumes = service_obj["volumes"]
for mount_string in volumes:
# Looks like: test-data:/data
parts = mount_string.split(":")
volume_name = parts[0]
mount_path = parts[1]
mount_options = parts[2] if len(parts) == 3 else None
# Looks like: test-data:/data or test-data:/data:ro or test-data:/data:rw
if opts.o.debug:
print(f"mount_string: {mount_string}")
mount_split = mount_string.split(":")
volume_name = mount_split[0]
mount_path = mount_split[1]
mount_options = mount_split[2] if len(mount_split) == 3 else None
if opts.o.debug:
print(f"volumne_name: {volume_name}")
print(f"mount path: {mount_path}")
print(f"mount options: {mount_options}")
volume_device = client.V1VolumeMount(
mount_path=mount_path, name=volume_name, read_only="ro" == mount_options)
result.append(volume_device)
Expand Down Expand Up @@ -163,12 +169,20 @@ def _generate_kind_mounts(parsed_pod_files, deployment_dir, deployment_context):
if "volumes" in service_obj:
volumes = service_obj["volumes"]
for mount_string in volumes:
# Looks like: test-data:/data
volume_name = mount_string.split(":")[0]
# Looks like: test-data:/data or test-data:/data:ro or test-data:/data:rw
if opts.o.debug:
print(f"mount_string: {mount_string}")
mount_split = mount_string.split(":")
volume_name = mount_split[0]
mount_path = mount_split[1]
if opts.o.debug:
print(f"volumne_name: {volume_name}")
print(f"map: {volume_host_path_map}")
print(f"mount path: {mount_path}")
if volume_name not in deployment_context.spec.get_configmaps():
volume_definitions.append(
f" - hostPath: {_make_absolute_host_path(volume_host_path_map[volume_name], deployment_dir)}\n"
f" containerPath: {get_node_pv_mount_path(volume_name)}"
f" containerPath: {get_node_pv_mount_path(volume_name)}\n"
)
return (
"" if len(volume_definitions) == 0 else (
Expand All @@ -191,7 +205,7 @@ def _generate_kind_port_mappings(parsed_pod_files):
for port_string in ports:
# TODO handle the complex cases
# Looks like: 80 or something more complicated
port_definitions.append(f" - containerPort: {port_string}\n hostPort: {port_string}")
port_definitions.append(f" - containerPort: {port_string}\n hostPort: {port_string}\n")
return (
"" if len(port_definitions) == 0 else (
" extraPortMappings:\n"
Expand Down
7 changes: 7 additions & 0 deletions stack_orchestrator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def get_compose_file_dir():
return source_compose_dir


def get_config_file_dir():
# TODO: refactor to use common code with deploy command
data_dir = Path(__file__).absolute().parent.joinpath("data")
source_config_dir = data_dir.joinpath("config")
return source_config_dir


def get_parsed_deployment_spec(spec_file):
spec_file_path = Path(spec_file)
try:
Expand Down

0 comments on commit bfbcfb7

Please sign in to comment.