Skip to content

Commit 81e7db6

Browse files
committed
speedy startup namespaces
1 parent 201b877 commit 81e7db6

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

src/warnet/deploy.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -315,32 +315,41 @@ def deploy_namespaces(directory: Path):
315315
)
316316
return
317317

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

345354

346355
def is_windows():

0 commit comments

Comments
 (0)