{{/* Per-instance fully-qualified name. Used as the prefix for every K8s object in the chart so instances in the same namespace can't collide. */}} {{- define "instance.fullname" -}} {{- .Values.instance.code | trunc 40 | trimSuffix "-" -}} {{- end -}} {{/* Standard labels applied to every K8s object. Keeps `kubectl get -l` queries by-instance trivial. */}} {{- define "instance.labels" -}} app.kubernetes.io/name: odoo app.kubernetes.io/instance: {{ .Values.instance.code | quote }} app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/version: {{ .Values.odoo.tag | quote }} odoosky.io/component: instance {{- end -}} {{/* Resources for a given role (`odoo` | `postgres`), looked up against the `sizes` table by `instance.size`. Falls back to "small" if the operator picked a name that doesn't exist (defensive: a typo shouldn't blow up the rendered chart). */}} {{- define "instance.resources" -}} {{- $size := .Values.instance.size | default "small" -}} {{- $cfg := index .Values.sizes $size | default (index .Values.sizes "small") -}} {{- toYaml (index $cfg .role) -}} {{- end -}} {{/* Storage size for a given layer (`filestore` | `database`). Resolution order, most-specific first: 1. instance.{layer}Storage in the tenant overlay (operator override) 2. sizes[size].storage.{layer} (per-tier default) 3. legacy chart-level fallback (.Values.odoo.filestoreSize / .Values.postgres.storage) This lets operators decouple storage from CPU/RAM tiers — a Small instance with lots of attachments can have 50 GB filestore without upgrading to Medium for capacity it doesn't need. */}} {{- define "instance.storage" -}} {{- $size := .Values.instance.size | default "small" -}} {{- $tier := index .Values.sizes $size | default (index .Values.sizes "small") -}} {{- if eq .layer "filestore" -}} {{- if .Values.instance.filestoreStorage -}}{{ .Values.instance.filestoreStorage }}{{- else if and $tier.storage $tier.storage.filestore -}}{{ $tier.storage.filestore }}{{- else -}}{{ .Values.odoo.filestoreSize | default "10Gi" }}{{- end -}} {{- else if eq .layer "database" -}} {{- if .Values.instance.dbStorage -}}{{ .Values.instance.dbStorage }}{{- else if and $tier.storage $tier.storage.database -}}{{ $tier.storage.database }}{{- else -}}{{ .Values.postgres.storage | default "10Gi" }}{{- end -}} {{- end -}} {{- end -}} {{/* Postgres password. Looks up the existing Secret on upgrades; uses .Values.postgres.password if set; otherwise generates a 32-char random string on first install. The lookup ensures `helm upgrade` does NOT silently rotate the password. */}} {{- define "instance.pgPassword" -}} {{- $existing := lookup "v1" "Secret" .Release.Namespace (printf "%s-pg" .Values.instance.code) -}} {{- if and $existing $existing.data $existing.data.POSTGRES_PASSWORD -}} {{- index $existing.data "POSTGRES_PASSWORD" | b64dec -}} {{- else if .Values.postgres.password -}} {{- .Values.postgres.password -}} {{- else -}} {{- randAlphaNum 32 -}} {{- end -}} {{- end -}}