|
1 | 1 | import shutil
|
2 |
| -import tempfile |
3 | 2 | from importlib.resources import files
|
4 | 3 | from pathlib import Path
|
5 | 4 |
|
6 | 5 | import click
|
7 |
| -import yaml |
8 | 6 |
|
9 | 7 | from .process import run_command, stream_command
|
10 | 8 |
|
@@ -35,58 +33,9 @@ def namespaces():
|
35 | 33 | """Namespaces commands"""
|
36 | 34 |
|
37 | 35 |
|
38 |
| -@namespaces.command() |
39 | 36 | @click.argument(
|
40 | 37 | "namespaces_dir", type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path)
|
41 | 38 | )
|
42 |
| -def deploy(namespaces_dir: Path): |
43 |
| - """Deploy namespaces with users from a <namespaces_file>""" |
44 |
| - namespaces_file_path = namespaces_dir / NAMESPACES_FILE |
45 |
| - defaults_file_path = namespaces_dir / DEFAULTS_FILE |
46 |
| - |
47 |
| - with namespaces_file_path.open() as f: |
48 |
| - namespaces_file = yaml.safe_load(f) |
49 |
| - |
50 |
| - # validate names before deploying |
51 |
| - names = [n.get("name") for n in namespaces_file["namespaces"]] |
52 |
| - for n in names: |
53 |
| - if not n.startswith("warnet-"): |
54 |
| - print( |
55 |
| - f"Failed to create namespace: {n}. Namespaces must start with a 'warnet-' prefix." |
56 |
| - ) |
57 |
| - |
58 |
| - # deploy namespaces |
59 |
| - for namespace in namespaces_file["namespaces"]: |
60 |
| - print(f"Deploying namespace: {namespace.get('name')}") |
61 |
| - try: |
62 |
| - temp_override_file_path = Path() |
63 |
| - namespace_name = namespace.get("name") |
64 |
| - # all the keys apart from name |
65 |
| - namespace_config_override = {k: v for k, v in namespace.items() if k != "name"} |
66 |
| - |
67 |
| - cmd = ( |
68 |
| - f"{HELM_COMMAND} {namespace_name} {BITCOIN_CHART_LOCATION} -f {defaults_file_path}" |
69 |
| - ) |
70 |
| - |
71 |
| - if namespace_config_override: |
72 |
| - with tempfile.NamedTemporaryFile( |
73 |
| - mode="w", suffix=".yaml", delete=False |
74 |
| - ) as temp_file: |
75 |
| - yaml.dump(namespace_config_override, temp_file) |
76 |
| - temp_override_file_path = Path(temp_file.name) |
77 |
| - cmd = f"{cmd} -f {temp_override_file_path}" |
78 |
| - |
79 |
| - if not stream_command(cmd): |
80 |
| - print(f"Failed to run Helm command: {cmd}") |
81 |
| - return |
82 |
| - except Exception as e: |
83 |
| - print(f"Error: {e}") |
84 |
| - return |
85 |
| - finally: |
86 |
| - if temp_override_file_path.exists(): |
87 |
| - temp_override_file_path.unlink() |
88 |
| - |
89 |
| - |
90 | 39 | @namespaces.command()
|
91 | 40 | def list():
|
92 | 41 | """List all namespaces with 'warnet-' prefix"""
|
|
0 commit comments