From 8ec205069c1d99375826781610f040fdb290027c Mon Sep 17 00:00:00 2001 From: Min Idzelis Date: Thu, 24 Oct 2024 03:51:10 +0000 Subject: [PATCH] Upgrade common chart. Allow split api/worker config. --- charts/immich/Chart.yaml | 4 +- charts/immich/templates/_utils/debug.tpl | 3 + charts/immich/templates/checks.yaml | 5 +- charts/immich/templates/machine-learning.yaml | 22 ++- charts/immich/templates/server.yaml | 56 ++++--- charts/immich/templates/workers.yaml | 148 ++++++++++++++++++ charts/immich/values.yaml | 61 +++++--- 7 files changed, 248 insertions(+), 51 deletions(-) create mode 100644 charts/immich/templates/_utils/debug.tpl create mode 100644 charts/immich/templates/workers.yaml diff --git a/charts/immich/Chart.yaml b/charts/immich/Chart.yaml index 5a69f9be..aa223605 100644 --- a/charts/immich/Chart.yaml +++ b/charts/immich/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 description: A chart to power Immich (immich.app) running on kubernetes name: immich -version: 0.8.2 +version: 0.9.0 appVersion: v1.118.0 home: https://immich.app/ icon: https://raw.githubusercontent.com/immich-app/immich/main/design/immich-logo.svg @@ -17,7 +17,7 @@ maintainers: dependencies: - name: common repository: https://bjw-s.github.io/helm-charts - version: 1.4.0 + version: 3.5.1 - name: postgresql condition: postgresql.enabled repository: https://charts.bitnami.com/bitnami diff --git a/charts/immich/templates/_utils/debug.tpl b/charts/immich/templates/_utils/debug.tpl new file mode 100644 index 00000000..4e3109d0 --- /dev/null +++ b/charts/immich/templates/_utils/debug.tpl @@ -0,0 +1,3 @@ +{{- define "debug.var_dump" -}} +{{- . | toPrettyJson | printf "\nThe JSON output of the dumped var is: \n%s" | fail }} +{{- end -}} \ No newline at end of file diff --git a/charts/immich/templates/checks.yaml b/charts/immich/templates/checks.yaml index d34a209c..4e0fc72f 100644 --- a/charts/immich/templates/checks.yaml +++ b/charts/immich/templates/checks.yaml @@ -1 +1,4 @@ -{{- $name := .Values.immich.persistence.library.existingClaim | required ".Values.immich.persistence.library.existingClaim is required." -}} \ No newline at end of file +{{- $name := .Values.immich.persistence.library.existingClaim | required ".Values.immich.persistence.library.existingClaim is required." -}} +{{- if and (eq .Values.workers.enabled true) (eq .Values.workers.enabled .Values.server.enabled) }} +{{- fail (printf "Only one of workers.enabled or server.enabled must be true.") }} +{{- end }} \ No newline at end of file diff --git a/charts/immich/templates/machine-learning.yaml b/charts/immich/templates/machine-learning.yaml index 77f3c0dd..31563ae7 100644 --- a/charts/immich/templates/machine-learning.yaml +++ b/charts/immich/templates/machine-learning.yaml @@ -2,10 +2,21 @@ global: nameOverride: machine-learning +controllers: + machine-learning: + containers: + main: + enabled: true + image: + repository: ghcr.io/immich-app/immich-machine-learning + pullPolicy: IfNotPresent + tag: {{ .Values.immich.image.tag }} + service: - main: + machine-learning: enabled: true primary: true + controller: machine-learning type: ClusterIP ports: http: @@ -29,12 +40,13 @@ probes: readiness: *probes startup: enabled: false +# end of define {{- end }} {{- /* Have to reference with index here because the dash breaks a normal dereference */}} {{ if (index .Values "machine-learning").enabled }} -{{- $ctx := deepCopy . -}} -{{- $_ := get .Values "machine-learning" | mergeOverwrite $ctx.Values -}} -{{- $_ = include "immich.machine-learning.hardcodedValues" . | fromYaml | merge $ctx.Values -}} +{{- $ctx := deepCopy (omit . "Values") }} +{{- $_ := set $ctx "Values" dict }} +{{- $_ := merge $ctx.Values (deepCopy .Values.common) (include "immich.machine-learning.hardcodedValues" . | fromYaml) (deepCopy (get .Values "machine-learning")) -}} {{- include "bjw-s.common.loader.all" $ctx }} -{{ end }} +{{- end }} \ No newline at end of file diff --git a/charts/immich/templates/server.yaml b/charts/immich/templates/server.yaml index 3d4937ed..1ed43d29 100644 --- a/charts/immich/templates/server.yaml +++ b/charts/immich/templates/server.yaml @@ -2,23 +2,34 @@ global: nameOverride: server -env: - {{ if .Values.immich.metrics.enabled }} - IMMICH_METRICS: true - {{ end }} - {{- if .Values.immich.configuration }} - IMMICH_CONFIG_FILE: /config/immich-config.yaml - {{- end }} - {{- if .Values.immich.configuration }} -podAnnotations: - checksum/config: {{ .Values.immich.configuration | toYaml | sha256sum }} +defaultPodOptions: + annotations: + checksum/config: {{ .Values.immich.configuration | toYaml | sha256sum }} {{- end }} +controllers: + immich-server: + containers: + main: + enabled: true + image: + repository: ghcr.io/immich-app/immich-server + pullPolicy: IfNotPresent + tag: {{ .Values.immich.image.tag }} + env: + {{ if .Values.immich.metrics.enabled }} + IMMICH_METRICS: true + {{ end }} + {{- if .Values.immich.configuration }} + IMMICH_CONFIG_FILE: /config/immich-config.yaml + {{- end }} + service: - main: + immich-server: enabled: true primary: true + controller: immich-server type: ClusterIP ports: http: @@ -37,8 +48,9 @@ service: serviceMonitor: - main: + immich-server: enabled: {{ .Values.immich.metrics.enabled }} + serviceName: immich-server endpoints: - port: metrics-api scheme: http @@ -79,13 +91,21 @@ persistence: {{- end }} library: enabled: true - mountPath: /usr/src/app/upload + type: persistentVolumeClaim + accessMode: ReadWriteMany existingClaim: {{ .Values.immich.persistence.library.existingClaim }} + retain: true + globalMounts: + - path: /usr/src/app/upload + readOnly: false +# end of define {{- end }} -{{ if .Values.server.enabled }} -{{- $ctx := deepCopy . -}} -{{- $_ := get .Values "server" | mergeOverwrite $ctx.Values -}} -{{- $_ = include "immich.server.hardcodedValues" . | fromYaml | merge $ctx.Values -}} +{{- if .Values.server.enabled }} +{{- $ctx := deepCopy (omit . "Values") }} +{{- $_ := set $ctx "Values" dict }} +{{- /* This part is needed so that bjw-s can reflectively resolve values like .Values.postgresql.global.postgresql.auth.username in the envVars */ -}} +{{- $_ := set $ctx.Values "postgresql" (deepCopy .Values.postgresql) }} +{{- $_ := merge $ctx.Values (deepCopy .Values.common) (include "immich.server.hardcodedValues" . | fromYaml) (deepCopy .Values.server) -}} {{- include "bjw-s.common.loader.all" $ctx }} -{{ end }} +{{- end }} \ No newline at end of file diff --git a/charts/immich/templates/workers.yaml b/charts/immich/templates/workers.yaml new file mode 100644 index 00000000..93517a2d --- /dev/null +++ b/charts/immich/templates/workers.yaml @@ -0,0 +1,148 @@ + +{{- define "immich.workers.hardcodedValues" -}} +global: + nameOverride: workers + +env: + {{ if .Values.immich.metrics.enabled }} + IMMICH_METRICS: true + {{ end }} + {{- if .Values.immich.configuration }} + IMMICH_CONFIG_FILE: /config/immich-config.yaml + {{- end }} + +{{- $worker_env := deepCopy .Values.immich.env }} +{{ if .Values.immich.metrics.enabled }} +{{- $_ := merge $worker_env (dict "IMMICH_METRICS" "true") }} +{{- end }} +{{ if .Values.immich.configuration }} +{{- $_ := merge $worker_env (dict "IMMICH_CONFIG_FILE" "/config/immich-config.yaml") }} +{{- end }} +{{- $apiEnv := merge (deepCopy $worker_env) (dict "IMMICH_WORKERS_INCLUDE" "api")}} +{{- $microservicesEnv := merge (deepCopy $worker_env) (dict "IMMICH_WORKERS_EXCLUDE" "api")}} + +{{- if .Values.immich.configuration }} +defaultPodOptions: + annotations: + checksum/config: {{ .Values.immich.configuration | toYaml | sha256sum }} +{{- end }} + +controllers: + api: + enabled: true + containers: + main: + enabled: true + image: + repository: ghcr.io/immich-app/immich-server + pullPolicy: IfNotPresent + tag: {{ .Values.immich.image.tag }} + env: {{ $apiEnv | toYaml | nindent 10 }} + microservices: + enabled: true + containers: + main: + enabled: true + image: + repository: ghcr.io/immich-app/immich-server + pullPolicy: IfNotPresent + tag: {{ .Values.immich.image.tag }} + env: {{ $microservicesEnv | toYaml | nindent 10 }} +service: + api: + enabled: true + primary: true + controller: api + nameOverride: api + type: ClusterIP + ports: + http: + enabled: true + primary: true + port: 2283 + protocol: HTTP + metrics-api: + enabled: {{ .Values.immich.metrics.enabled }} + port: 8081 + protocol: HTTP +{{- if .Values.immich.metrics.enabled }} + microservices: + enabled: true + primary: true + controller: microservices + nameOverride: microservices + type: ClusterIP + ports: + metrics-ms: + enabled: {{ .Values.immich.metrics.enabled }} + port: 8082 + protocol: HTTP +{{ end }} + +serviceMonitor: + api: + enabled: {{ .Values.immich.metrics.enabled }} + serviceName: immich-workers-api + endpoints: + - port: metrics-api + scheme: http + microservices: + enabled: {{ .Values.immich.metrics.enabled }} + serviceName: immich-workers-microservices + endpoints: + - port: metrics-ms + scheme: http + +probes: + liveness: &probes + enabled: true + custom: true + spec: + httpGet: + path: /api/server/ping + port: http + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + readiness: *probes + startup: + enabled: true + custom: true + spec: + httpGet: + path: /api/server/ping + port: http + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 30 + +persistence: +{{- if .Values.immich.configuration }} + config: + enabled: true + type: configMap + name: {{ .Release.Name }}-immich-config +{{- end }} + library: + enabled: true + type: persistentVolumeClaim + accessMode: ReadWriteMany + existingClaim: {{ .Values.immich.persistence.library.existingClaim }} + retain: true + globalMounts: + - path: /usr/src/app/upload + readOnly: false +# end of define +{{- end }} + +{{- if .Values.workers.enabled }} +{{- $ctx := deepCopy (omit . "Values") }} +{{- $_ := set $ctx "Values" dict }} +{{- /* This part is needed so that bjw-s can reflectively resolve values like .Values.postgresql.global.postgresql.auth.username in the envVars */ -}} +{{- $_ := set $ctx.Values "postgresql" (deepCopy .Values.postgresql) }} +{{- $_ := merge $ctx.Values (deepCopy .Values.common) (include "immich.workers.hardcodedValues" . | fromYaml) (deepCopy .Values.workers) -}} + +{{- include "bjw-s.common.loader.all" $ctx }} +{{- end }} \ No newline at end of file diff --git a/charts/immich/values.yaml b/charts/immich/values.yaml index 21054210..162c87c0 100644 --- a/charts/immich/values.yaml +++ b/charts/immich/values.yaml @@ -4,19 +4,18 @@ # These entries are shared between all the Immich components -env: - REDIS_HOSTNAME: '{{ printf "%s-redis-master" .Release.Name }}' - DB_HOSTNAME: "{{ .Release.Name }}-postgresql" - DB_USERNAME: "{{ .Values.postgresql.global.postgresql.auth.username }}" - DB_DATABASE_NAME: "{{ .Values.postgresql.global.postgresql.auth.database }}" - # -- You should provide your own secret outside of this helm-chart and use `postgresql.global.postgresql.auth.existingSecret` to provide credentials to the postgresql instance - DB_PASSWORD: "{{ .Values.postgresql.global.postgresql.auth.password }}" - IMMICH_MACHINE_LEARNING_URL: '{{ printf "http://%s-machine-learning:3003" .Release.Name }}' - -image: - tag: v1.118.0 - immich: + image: + tag: v1.118.0 + env: + REDIS_HOSTNAME: '{{ printf "%s-redis-master" .Release.Name }}' + DB_HOSTNAME: '{{ .Release.Name }}-postgresql' + DB_USERNAME: '{{ .Values.postgresql.global.postgresql.auth.username }}' + DB_DATABASE_NAME: '{{ .Values.postgresql.global.postgresql.auth.database }}' + # -- You should provide your own secret outside of this helm-chart and use `postgresql.global.postgresql.auth.existingSecret` to provide credentials to the postgresql instance + DB_PASSWORD: '{{ .Values.postgresql.global.postgresql.auth.password }}' + IMMICH_MACHINE_LEARNING_URL: '{{ printf "http://%s-machine-learning:3003" .Release.Name }}' + metrics: # Enabling this will create the service monitors needed to monitor immich with the prometheus operator enabled: false @@ -29,16 +28,16 @@ immich: # configuration is immich-config.json converted to yaml # ref: https://immich.app/docs/install/config-file/ # - configuration: {} + configuration: + {} # trash: # enabled: false # days: 30 # storageTemplate: # enabled: true - # template: "{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}" + # template: '{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}' # Dependencies - postgresql: enabled: false image: @@ -67,36 +66,48 @@ redis: enabled: false # Immich components - server: enabled: true - image: - repository: ghcr.io/immich-app/immich-server - pullPolicy: IfNotPresent ingress: main: enabled: false annotations: # proxy-body-size is set to 0 to remove the body limit on file uploads - nginx.ingress.kubernetes.io/proxy-body-size: "0" + nginx.ingress.kubernetes.io/proxy-body-size: '0' hosts: - host: immich.local paths: - - path: "/" + - path: '/' tls: [] machine-learning: enabled: true - image: - repository: ghcr.io/immich-app/immich-machine-learning - pullPolicy: IfNotPresent env: TRANSFORMERS_CACHE: /cache persistence: cache: enabled: true size: 10Gi - # Optional: Set this to pvc to avoid downloading the ML models every start. + # Optional: Set this to a persistentVolumeClaim to avoid downloading the ML models every start. type: emptyDir accessMode: ReadWriteMany # storageClass: your-class + +workers: + enabled: false + controllers: + api: + replicas: 1 + microservices: + replicas: 1 + ingress: + api: + enabled: false + annotations: + # proxy-body-size is set to 0 to remove the body limit on file uploads + nginx.ingress.kubernetes.io/proxy-body-size: '0' + hosts: + - host: immich.local + paths: + - path: '/' + tls: []