From 3d2d7120e0a1853488aeb8275b85d29def4275ef Mon Sep 17 00:00:00 2001 From: josibake Date: Mon, 16 Sep 2024 11:27:37 +0200 Subject: [PATCH] add namespace labels --- .../charts/bitcoincore/templates/namespace-hook.yaml | 9 +++++++++ resources/charts/bitcoincore/values.yaml | 1 + resources/charts/namespaces/templates/namespace.yaml | 2 ++ resources/charts/namespaces/values.yaml | 3 ++- src/warnet/constants.py | 8 ++++++++ src/warnet/deploy.py | 5 +++-- 6 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 resources/charts/bitcoincore/templates/namespace-hook.yaml diff --git a/resources/charts/bitcoincore/templates/namespace-hook.yaml b/resources/charts/bitcoincore/templates/namespace-hook.yaml new file mode 100644 index 000000000..9e3b0eb9a --- /dev/null +++ b/resources/charts/bitcoincore/templates/namespace-hook.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Release.Namespace }} + labels: + type: {{ .Values.type }} + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-weight": "-1" diff --git a/resources/charts/bitcoincore/values.yaml b/resources/charts/bitcoincore/values.yaml index 320d59c62..59688a30b 100644 --- a/resources/charts/bitcoincore/values.yaml +++ b/resources/charts/bitcoincore/values.yaml @@ -137,3 +137,4 @@ connect: [] loadSnapshot: enabled: false url: "" +type: "assets" diff --git a/resources/charts/namespaces/templates/namespace.yaml b/resources/charts/namespaces/templates/namespace.yaml index 5e01eebed..5709cf499 100644 --- a/resources/charts/namespaces/templates/namespace.yaml +++ b/resources/charts/namespaces/templates/namespace.yaml @@ -2,3 +2,5 @@ apiVersion: v1 kind: Namespace metadata: name: {{ .Values.namespaceName | default .Release.Name }} + labels: + type: {{ .Values.type }} diff --git a/resources/charts/namespaces/values.yaml b/resources/charts/namespaces/values.yaml index 61f946879..99d411363 100644 --- a/resources/charts/namespaces/values.yaml +++ b/resources/charts/namespaces/values.yaml @@ -1,3 +1,4 @@ +type: "assets" users: - name: warnet-user roles: @@ -37,4 +38,4 @@ roles: verbs: ["get", "list"] - apiGroups: [""] resources: ["events"] - verbs: ["get"] \ No newline at end of file + verbs: ["get"] diff --git a/src/warnet/constants.py b/src/warnet/constants.py index c01e8c2b4..d119905b6 100644 --- a/src/warnet/constants.py +++ b/src/warnet/constants.py @@ -16,6 +16,14 @@ INGRESS_NAMESPACE = "ingress" HELM_COMMAND = "helm upgrade --install --create-namespace" +# 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" + + # Directories and files for non-python assets, e.g., helm charts, example scenarios, default configs SRC_DIR = files("warnet") RESOURCES_DIR = files("resources") diff --git a/src/warnet/deploy.py b/src/warnet/deploy.py index 3cfbb9fc3..37361165e 100644 --- a/src/warnet/deploy.py +++ b/src/warnet/deploy.py @@ -19,6 +19,7 @@ NAMESPACES_CHART_LOCATION, NAMESPACES_FILE, NETWORK_FILE, + WARNET_ASSETS, ) from .k8s import get_default_namespace, wait_for_ingress_controller, wait_for_pod_ready from .process import stream_command @@ -209,7 +210,7 @@ def deploy_network(directory: Path, namespace_override: str, debug: bool = False node_name = node.get("name") node_config_override = {k: v for k, v in node.items() if k != "name"} - cmd = f"{HELM_COMMAND} {node_name} {BITCOIN_CHART_LOCATION} --namespace {namespace} -f {defaults_file_path}" + cmd = f"{HELM_COMMAND} {node_name} {BITCOIN_CHART_LOCATION} --namespace {namespace} -f {defaults_file_path} --set type={WARNET_ASSETS}" if debug: cmd += " --debug" @@ -246,7 +247,7 @@ def deploy_namespaces(directory: Path): namespace_name = namespace.get("name") namespace_config_override = {k: v for k, v in namespace.items() if k != "name"} - cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path}" + cmd = f"{HELM_COMMAND} {namespace_name} {NAMESPACES_CHART_LOCATION} -f {defaults_file_path} --set type={WARNET_ASSETS}" if namespace_config_override: with tempfile.NamedTemporaryFile(