Skip to content

Commit

Permalink
speedy startup namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
willcl-ark committed Oct 12, 2024
1 parent 06c7a76 commit 604eb15
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/warnet/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,32 +314,40 @@ def deploy_namespaces(directory: Path):
)
return

processes = []
for namespace in namespaces_file["namespaces"]:
click.echo(f"Deploying namespace: {namespace.get('name')}")
try:
temp_override_file_path = ""
namespace_name = namespace.get("name")
namespace_config_override = {k: v for k, v in namespace.items() if k != "name"}

cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path}"

if namespace_config_override:
with tempfile.NamedTemporaryFile(
mode="w", suffix=".yaml", delete=False
) as temp_file:
yaml.dump(namespace_config_override, temp_file)
temp_override_file_path = Path(temp_file.name)
cmd = f"{cmd} -f {temp_override_file_path}"

if not stream_command(cmd):
click.echo(f"Failed to run Helm command: {cmd}")
return
except Exception as e:
click.echo(f"Error: {e}")
p = Process(target=deploy_single_namespace, args=(namespace, defaults_file_path))
p.start()
processes.append(p)

for p in processes:
p.join()


def deploy_single_namespace(namespace, defaults_file_path: Path):
click.echo(f"Deploying namespace: {namespace.get('name')}")
temp_override_file_path = ""
try:
namespace_name = namespace.get("name")
namespace_config_override = {k: v for k, v in namespace.items() if k != "name"}

cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path}"

if namespace_config_override:
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as temp_file:
yaml.dump(namespace_config_override, temp_file)
temp_override_file_path = Path(temp_file.name)
cmd = f"{cmd} -f {temp_override_file_path}"

if not stream_command(cmd):
click.echo(f"Failed to run Helm command: {cmd}")
return
finally:
if temp_override_file_path:
temp_override_file_path.unlink()
except Exception as e:
click.echo(f"Error: {e}")
return
finally:
if temp_override_file_path:
Path(temp_override_file_path).unlink()


def is_windows():
Expand Down

0 comments on commit 604eb15

Please sign in to comment.