Skip to content

Commit 9de95ee

Browse files
fix(signal-processing): Correctly template namespace in notebook (#437)
* fix(signal-processing): Correctly template namespace in notebook * temp: Fetch notebook from branch with fixes * fix(signal-processing): Use different placeholder in NiFi flow * temp: Fetch NiFi flow from branch with fixes * chore(stack/signal-processing): Add some guidance for finding Helm values * chore(stack/signal-processing): Disable cloudMetadata block The iptables call ing the It fails for me. I am on kernel 7.0. It could be that. Or maybe oci.stackable.tech/demos/jupyter-pyspark-with-alibi-detect needs some update? * fix(stack/signal-processing): Namespace interpolation Add extraEnv for providing the templated namespace. We would use the downward api, but that breaks because the value of extraEnv is also passed to `hub` which expects a dict. * chore: Apply suggestions Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com> --------- Co-authored-by: Nick Larsen <nick.larsen@stackable.tech> Co-authored-by: Nick <10092581+NickLarsenNZ@users.noreply.github.com>
1 parent 1945c43 commit 9de95ee

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

demos/signal-processing/DownloadAndWriteToDB.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@
741741
"kerberos-credentials-service": null,
742742
"dbcp-max-conn-lifetime": "-1",
743743
"Validation-query": "select count(*) from conditions;",
744-
"Database Connection URL": "jdbc:postgresql://postgresql-timescaledb.{{ NAMESPACE }}.svc.cluster.local:5432/tsdb",
744+
"Database Connection URL": "jdbc:postgresql://postgresql-timescaledb.[[ NAMESPACE ]].svc.cluster.local:5432/tsdb",
745745
"dbcp-time-between-eviction-runs": "-1",
746746
"Database User": "admin",
747747
"kerberos-user-service": null,

demos/signal-processing/create-nifi-ingestion-job.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ data:
9090
# At release time, .scripts/update_refs.sh rewrites the branch in this URL to the release
9191
# branch. Keep the URL in a form its regex matches, or release-branch installs will
9292
# download this file from main (see the 26.3 regression).
93-
response = requests.get("https://raw.githubusercontent.com/stackabletech/demos/main/demos/signal-processing/DownloadAndWriteToDB.json")
93+
response = requests.get("https://raw.githubusercontent.com/stackabletech/demos/refs/heads/main/demos/signal-processing/DownloadAndWriteToDB.json")
9494
9595
filename = "/tmp/DownloadAndWriteToDB.json"
9696
with open(filename, "w") as f:
97-
f.write(response.text.replace("{{ NAMESPACE }}", os.environ["NAMESPACE"]))
97+
f.write(response.text.replace("[[ NAMESPACE ]]", os.environ["NAMESPACE"]))
9898
9999
pg_id = get_root_pg_id()
100100

stacks/signal-processing/jupyterhub.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ repo:
55
name: jupyterhub
66
url: https://jupyterhub.github.io/helm-chart/
77
version: 4.4.0 # appVersion: 5.5.0
8+
# Find values here: https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/main/jupyterhub/values.yaml
9+
# Note, they don't tag the repository, so you need to find _a_ commit where the Chart version matches what you are looking for.
810
options:
911
hub:
1012
config:
@@ -40,6 +42,11 @@ options:
4042
# the demo is reproducable for the release and it will be automatically replaced for the release branch.
4143
name: oci.stackable.tech/demos/jupyter-pyspark-with-alibi-detect
4244
tag: python-3.9
45+
cloudMetadata:
46+
# Disable, otherwise we get Back-off restarting failed container block-cloud-metadata in pod:
47+
# block-cloud-metadata iptables v1.8.9 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
48+
# I believe this breaks in Kernel 7.x.
49+
blockWithIptables: false
4350
serviceAccountName: spark
4451
networkPolicy:
4552
enabled: false
@@ -51,11 +58,19 @@ options:
5158
# {% if DEMO is defined %}
5259
stackable.tech/demo: "{{ DEMO }}"
5360
# {% endif %}
61+
extraEnv:
62+
# Needed because the Notebook runs code to interpolate the Postgres DB hostname with a namespace.
63+
# We cannot use the downward API because some python code uses it and expects scalar values.
64+
# We also MUST use a dict, otherwise hub shows the following error:
65+
# traitlets.traitlets.TraitError: The 'environment' trait of a KubeSpawner instance expected a dict, not the list [{'name': 'NAMESPACE', 'value': 'my-namespace'}].
66+
# A helper in the chart formats these properly for any container env vars in Pods.
67+
NAMESPACE: "{{ NAMESPACE }}"
5468
initContainers:
5569
- name: download-notebook
5670
image: oci.stackable.tech/sdp/tools:1.0.0-stackable0.0.0-dev
71+
env:
5772
# This file path needs adjustment for versioned demos on release branch
58-
command: ['sh', '-c', 'curl https://raw.githubusercontent.com/stackabletech/demos/main/stacks/signal-processing/tsdb.ipynb -o /notebook/tsdb.ipynb']
73+
command: ['sh', '-c', 'curl https://raw.githubusercontent.com/stackabletech/demos/refs/heads/main/stacks/signal-processing/tsdb.ipynb -o /notebook/tsdb.ipynb']
5974
volumeMounts:
6075
- mountPath: /notebook
6176
name: notebook

stacks/signal-processing/tsdb.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868
"metadata": {},
6969
"outputs": [],
7070
"source": [
71-
"engine = sqlalchemy.create_engine(\"postgresql://admin:adminadmin@postgresql-timescaledb.{{ NAMESPACE }}.svc.cluster.local:5432/tsdb\")\n",
71+
"import os\n",
72+
"namespace = os.environ.get('NAMESPACE', \"default\")\n",
73+
"\n",
74+
"engine = sqlalchemy.create_engine(f\"postgresql://admin:adminadmin@postgresql-timescaledb.{namespace}.svc.cluster.local:5432/tsdb\")\n",
7275
"last_time = \"1970-01-01\"\n",
7376
"cols = ['r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10', 'r11', 'r12', 'r13', 'r14']"
7477
]

0 commit comments

Comments
 (0)