Skip to content

Commit e3f517e

Browse files
committed
add --namespace flag to deploy
allow the user to specify a namespace to deploy into (overrides kubectl default namespace)
1 parent acc63ed commit e3f517e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/warnet/deploy.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,23 @@ def validate_directory(ctx, param, value):
4242
callback=validate_directory,
4343
)
4444
@click.option("--debug", is_flag=True)
45-
def deploy(directory, debug):
45+
@click.option("--namespace", "-n", type=str, help="Namespace to deploy network into (overrides the current namespace in kubectl)")
46+
def deploy(directory, debug, namespace):
4647
"""Deploy a warnet with topology loaded from <directory>"""
4748
directory = Path(directory)
4849

4950
if (directory / NETWORK_FILE).exists():
5051
dl = deploy_logging_stack(directory, debug)
51-
deploy_network(directory, debug)
52+
deploy_network(directory, namespace, debug)
5253
df = deploy_fork_observer(directory, debug)
5354
if dl | df:
5455
deploy_ingress(debug)
5556
deploy_caddy(directory, debug)
5657
elif (directory / NAMESPACES_FILE).exists():
57-
deploy_namespaces(directory)
58+
if namespace:
59+
click.echo("Cannot specify a --namespace when deploying a namespaces chart.")
60+
else:
61+
deploy_namespaces(directory)
5862
else:
5963
click.echo(
6064
"Error: Neither network.yaml nor namespaces.yaml found in the specified directory."
@@ -189,14 +193,14 @@ def deploy_fork_observer(directory: Path, debug: bool) -> bool:
189193
return True
190194

191195

192-
def deploy_network(directory: Path, debug: bool = False):
196+
def deploy_network(directory: Path, namespace_override: str, debug: bool = False):
193197
network_file_path = directory / NETWORK_FILE
194198
defaults_file_path = directory / DEFAULTS_FILE
195199

196200
with network_file_path.open() as f:
197201
network_file = yaml.safe_load(f)
198202

199-
namespace = get_default_namespace()
203+
namespace = namespace_override if namespace_override else get_default_namespace()
200204

201205
for node in network_file["nodes"]:
202206
click.echo(f"Deploying node: {node.get('name')}")

0 commit comments

Comments
 (0)