Skip to content

Commit

Permalink
add namespace labels
Browse files Browse the repository at this point in the history
  • Loading branch information
josibake committed Sep 26, 2024
1 parent b5f5656 commit 3d2d712
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions resources/charts/bitcoincore/templates/namespace-hook.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions resources/charts/bitcoincore/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ connect: []
loadSnapshot:
enabled: false
url: ""
type: "assets"
2 changes: 2 additions & 0 deletions resources/charts/namespaces/templates/namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.namespaceName | default .Release.Name }}
labels:
type: {{ .Values.type }}
3 changes: 2 additions & 1 deletion resources/charts/namespaces/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type: "assets"
users:
- name: warnet-user
roles:
Expand Down Expand Up @@ -37,4 +38,4 @@ roles:
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["events"]
verbs: ["get"]
verbs: ["get"]
8 changes: 8 additions & 0 deletions src/warnet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions src/warnet/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3d2d712

Please sign in to comment.