Skip to content

Commit 2e237bc

Browse files
committed
speedy startup namespaces
1 parent 32cdfd3 commit 2e237bc

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/warnet/deploy.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -320,32 +320,40 @@ def deploy_namespaces(directory: Path):
320320
)
321321
return
322322

323+
processes = []
323324
for namespace in namespaces_file["namespaces"]:
324-
click.echo(f"Deploying namespace: {namespace.get('name')}")
325-
try:
326-
temp_override_file_path = ""
327-
namespace_name = namespace.get("name")
328-
namespace_config_override = {k: v for k, v in namespace.items() if k != "name"}
329-
330-
cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path}"
331-
332-
if namespace_config_override:
333-
with tempfile.NamedTemporaryFile(
334-
mode="w", suffix=".yaml", delete=False
335-
) as temp_file:
336-
yaml.dump(namespace_config_override, temp_file)
337-
temp_override_file_path = Path(temp_file.name)
338-
cmd = f"{cmd} -f {temp_override_file_path}"
339-
340-
if not stream_command(cmd):
341-
click.echo(f"Failed to run Helm command: {cmd}")
342-
return
343-
except Exception as e:
344-
click.echo(f"Error: {e}")
325+
p = Process(target=deploy_single_namespace, args=(namespace, defaults_file_path))
326+
p.start()
327+
processes.append(p)
328+
329+
for p in processes:
330+
p.join()
331+
332+
333+
def deploy_single_namespace(namespace, defaults_file_path: Path):
334+
click.echo(f"Deploying namespace: {namespace.get('name')}")
335+
temp_override_file_path = ""
336+
try:
337+
namespace_name = namespace.get("name")
338+
namespace_config_override = {k: v for k, v in namespace.items() if k != "name"}
339+
340+
cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path}"
341+
342+
if namespace_config_override:
343+
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as temp_file:
344+
yaml.dump(namespace_config_override, temp_file)
345+
temp_override_file_path = Path(temp_file.name)
346+
cmd = f"{cmd} -f {temp_override_file_path}"
347+
348+
if not stream_command(cmd):
349+
click.echo(f"Failed to run Helm command: {cmd}")
345350
return
346-
finally:
347-
if temp_override_file_path:
348-
temp_override_file_path.unlink()
351+
except Exception as e:
352+
click.echo(f"Error: {e}")
353+
return
354+
finally:
355+
if temp_override_file_path:
356+
Path(temp_override_file_path).unlink()
349357

350358

351359
def is_windows():

0 commit comments

Comments
 (0)