Skip to content

Commit

Permalink
more wip changes
Browse files Browse the repository at this point in the history
  • Loading branch information
josibake committed Sep 26, 2024
1 parent f18d236 commit 36e4f3c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions resources/charts/namespaces/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: "assets"
namespaceName: "default-warnet-value"
users:
- name: warnet-user
roles:
Expand Down
3 changes: 2 additions & 1 deletion src/warnet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
DEFAULT_NAMESPACE = "warnet"
LOGGING_NAMESPACE = "warnet-logging"
INGRESS_NAMESPACE = "ingress"
HELM_COMMAND = "helm upgrade --install --create-namespace"
HELM_COMMAND = "helm upgrade --install"

# labels are applied to namespaces to help filter commands without relying on naming conventions
# on the namespaces themselves. Namespaces containing tanks and commanders get the WARNET_ASSETS tag
# whereas logging namespaces get the WARNET_LOGGING tag, and admin namespaces get the WARNET_ADMIN tag
WARNET_ASSETS = "assets"
WARNET_LOGGING = "logging"
WARNET_ADMIN = "admin"
WARNET_NAMESPACE_ANNOTATION = "dontremember"


# Directories and files for non-python assets, e.g., helm charts, example scenarios, default configs
Expand Down
16 changes: 10 additions & 6 deletions src/warnet/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def deploy(directory, debug, namespace):
if namespace:
click.echo("Cannot specify a --namespace when deploying a namespaces chart.")
else:
deploy_namespaces(directory)
deploy_namespaces(directory, debug)
else:
click.echo(
"Error: Neither network.yaml nor namespaces.yaml found in the specified directory."
Expand Down Expand Up @@ -233,21 +233,21 @@ def deploy_network(directory: Path, namespace_override: str, debug: bool = False
Path(temp_override_file_path).unlink()


def deploy_namespaces(directory: Path):
def deploy_namespaces(directory: Path, debug: bool = False):
namespaces_file_path = directory / NAMESPACES_FILE
defaults_file_path = directory / DEFAULTS_NAMESPACE_FILE

with namespaces_file_path.open() as f:
namespaces_file = yaml.safe_load(f)

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

cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path} --set type={WARNET_ASSETS}"
cmd = f"{HELM_COMMAND} --create-namespace {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path} --set type={WARNET_ASSETS}"

if namespace_config_override:
with tempfile.NamedTemporaryFile(
Expand All @@ -257,6 +257,9 @@ def deploy_namespaces(directory: Path):
temp_override_file_path = Path(temp_file.name)
cmd = f"{cmd} -f {temp_override_file_path}"

if debug:
cmd += " --debug"

if not stream_command(cmd):
click.echo(f"Failed to run Helm command: {cmd}")
return
Expand All @@ -266,6 +269,7 @@ def deploy_namespaces(directory: Path):
finally:
if temp_override_file_path.exists():
temp_override_file_path.unlink()
print("DONE!!!!!")


def is_windows():
Expand Down

0 comments on commit 36e4f3c

Please sign in to comment.