From 150e8785aeef5f56f2f20be07014e8a0e472e44a Mon Sep 17 00:00:00 2001 From: Michael Ruoss Date: Fri, 5 Jan 2024 22:32:11 +0100 Subject: [PATCH] livebook: add env variables and fix docker image (#16880) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** * Fix Livebook container image source and upgrade to latest version * Add environment variables, mostly for clustering of multiple replicas **โš™๏ธ Type of change** - [ ] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› Bugfix - [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** I've used a local KIND cluster and `helm template` => `kubectl install` **๐Ÿ“ƒ Notes:** **โœ”๏ธ Checklist:** - [x] โš–๏ธ My code follows the style guidelines of this project - [x] ๐Ÿ‘€ I have performed a self-review of my own code - [x] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made corresponding changes to the documentation - [x] โš ๏ธ My changes generate no new warnings - [ ] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [x] โฌ†๏ธ I increased versions for any altered app according to semantic versioning --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- charts/dev/livebook/Chart.yaml | 2 +- charts/dev/livebook/questions.yaml | 17 ++++++++++-- charts/dev/livebook/templates/_secrets.tpl | 15 ++++++++++ charts/dev/livebook/templates/common.yaml | 13 ++++++++- charts/dev/livebook/values.yaml | 32 ++++++++++++++++++---- 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 charts/dev/livebook/templates/_secrets.tpl diff --git a/charts/dev/livebook/Chart.yaml b/charts/dev/livebook/Chart.yaml index 7e4bceb2f54..2a1eed52f9f 100644 --- a/charts/dev/livebook/Chart.yaml +++ b/charts/dev/livebook/Chart.yaml @@ -1,7 +1,7 @@ kubeVersion: ">=1.24.0-0" apiVersion: v2 name: livebook -version: 3.0.13 +version: 3.1.0 appVersion: latest description: Livebook is a web application for writing interactive and collaborative code notebooks for Elixir home: https://truecharts.org/charts/incubator/livebook diff --git a/charts/dev/livebook/questions.yaml b/charts/dev/livebook/questions.yaml index 9dc1d00e9c8..675cde7e542 100644 --- a/charts/dev/livebook/questions.yaml +++ b/charts/dev/livebook/questions.yaml @@ -16,11 +16,24 @@ questions: type: dict attrs: - variable: LIVEBOOK_PASSWORD - label: "LIVEBOOK_PASSWORD" + label: "Password (LIVEBOOK_PASSWORD)" description: "Password needed to access livebook (must be at least 12 characters)" schema: type: string - default: "livebookiscool" + required: true + private: true + - variable: LIVEBOOK_DEBUG + label: "Debug Logging (LIVEBOOK_DEBUG)" + description: > + enables verbose logging, when set to "true". Disabled by default. + schema: + type: boolean + - variable: LIVEBOOK_UPDATE_INSTRUCTIONS_URL + label: "Update instruction URL (LIVEBOOK_UPDATE_INSTRUCTIONS_URL)" + description: > + sets the URL to direct the user to for updating Livebook when a new version becomes available. + schema: + type: string # Include{serviceRoot} - variable: main label: "Main Service" diff --git a/charts/dev/livebook/templates/_secrets.tpl b/charts/dev/livebook/templates/_secrets.tpl new file mode 100644 index 00000000000..205e77ddbd9 --- /dev/null +++ b/charts/dev/livebook/templates/_secrets.tpl @@ -0,0 +1,15 @@ +{{/* Define the secrets */}} +{{- define "livebook.secrets" -}} +{{- $secretName := (printf "%s-secrets" (include "tc.v1.common.lib.chart.names.fullname" $)) }} +{{/* Base64 encoding is intended, application expects a b64 formatted value */}} +{{- $secretKeyBase := randAlphaNum 48 | b64enc -}} +{{- $cookie := randAlphaNum 20 -}} +{{- with (lookup "v1" "Secret" .Release.Namespace $secretName) -}} + {{- $secretKeyBase = index .data "LIVEBOOK_SECRET_KEY_BASE" | b64dec -}} + {{- $cookie = index .data "LIVEBOOK_COOKIE" | b64dec -}} +{{- end }} +enabled: true +data: + LIVEBOOK_SECRET_KEY_BASE: {{ $secretKeyBase }} + LIVEBOOK_COOKIE: {{ $cookie }} +{{- end -}} diff --git a/charts/dev/livebook/templates/common.yaml b/charts/dev/livebook/templates/common.yaml index 78d963fb168..28fd652b7e0 100644 --- a/charts/dev/livebook/templates/common.yaml +++ b/charts/dev/livebook/templates/common.yaml @@ -1,2 +1,13 @@ {{/* Render the templates */}} -{{ include "tc.v1.common.loader.all" . }} +{{/* Make sure all variables are set properly */}} +{{- include "tc.v1.common.loader.init" . }} + +{{/* Render secrets for livebook */}} +{{- $secrets := include "livebook.secrets" . | fromYaml -}} +{{- if $secrets -}} + {{- $_ := set .Values.secret "secrets" $secrets -}} +{{- end -}} + +{{/* Render the templates */}} +{{ include "tc.v1.common.loader.apply" . }} + diff --git a/charts/dev/livebook/values.yaml b/charts/dev/livebook/values.yaml index f1d0ef1c2ae..cf90783411f 100644 --- a/charts/dev/livebook/values.yaml +++ b/charts/dev/livebook/values.yaml @@ -1,7 +1,7 @@ image: pullPolicy: IfNotPresent - repository: livebook/livebook - tag: latest@sha256:99c321de38ad781df509cfd3e452805f04627589a435645faa889a963bd7d1f5 + repository: ghcr.io/livebook-dev/livebook + tag: 0.12.1@sha256:11c5691efc8e35bf0eee9c336ff029e674bcf4146ec39021b1ef75c1b17fb775 persistence: data: enabled: true @@ -19,12 +19,34 @@ service: ports: main: port: 8787 - protocol: tcp - targetPort: 8080 + headless: + enabled: true + primary: false + clusterIP: None + ports: + headless: + enabled: true + port: "{{ .Values.service.main.ports.main.port }}" workload: main: podSpec: containers: main: env: - LIVEBOOK_PASSWORD: livebookiscool + # A_ because these variables are sorted alphabetically and this one needs to come first. + A_POD_IP: + fieldRef: + fieldPath: status.podIP + LIVEBOOK_CLUSTER: '{{ printf "dns:%s-headless" (include "tc.v1.common.lib.chart.names.fullname" .) }}' + LIVEBOOK_DISTRIBUTION: name + LIVEBOOK_NODE: livebook@$(A_POD_IP) + LIVEBOOK_PORT: "{{ .Values.service.main.ports.main.port }}" + LIVEBOOK_HOME: "{{ .Values.persistence.data.mountPath }}" + LIVEBOOK_SECRET_KEY_BASE: + secretKeyRef: + name: secrets + key: LIVEBOOK_SECRET_KEY_BASE + LIVEBOOK_COOKIE: + secretKeyRef: + name: secrets + key: LIVEBOOK_COOKIE