Files
porthole/helm/tline/templates/_helpers.tpl
OpenCode Test e1a64aa092 Initial commit
2025-12-24 10:50:10 -08:00

152 lines
5.4 KiB
Smarty

{{- define "tline.name" -}}
{{- default .Chart.Name .Values.global.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "tline.fullname" -}}
{{- if .Values.global.fullnameOverride -}}
{{- .Values.global.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name (include "tline.name" .) | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- define "tline.labels" -}}
app.kubernetes.io/name: {{ include "tline.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | quote }}
{{- end -}}
{{- define "tline.selectorLabels" -}}
app.kubernetes.io/name: {{ include "tline.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{- define "tline.componentName" -}}
{{- printf "%s-%s" (include "tline.fullname" .) .component | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "tline.storageClass" -}}
{{- $sc := .storageClass | default "" -}}
{{- if $sc -}}
{{- $sc -}}
{{- else if .Values.global.storageClass -}}
{{- .Values.global.storageClass -}}
{{- else -}}
{{- "" -}}
{{- end -}}
{{- end -}}
{{- define "tline.affinity" -}}
{{- $class := .schedulingClass | default "compute" -}}
{{- $sched := index .Values.scheduling $class -}}
{{- if $sched.affinity -}}
{{- toYaml $sched.affinity -}}
{{- end -}}
{{- end -}}
{{- define "tline.tolerations" -}}
{{- $class := .schedulingClass | default "compute" -}}
{{- $sched := index .Values.scheduling $class -}}
{{- if $sched.tolerations -}}
{{- toYaml $sched.tolerations -}}
{{- end -}}
{{- end -}}
{{- define "tline.secretName" -}}
{{- if .Values.secrets.existingSecret -}}
{{- .Values.secrets.existingSecret -}}
{{- else -}}
{{- printf "%s-secrets" (include "tline.fullname" .) -}}
{{- end -}}
{{- end -}}
{{- define "tline.databaseUrl" -}}
{{- if .Values.app.databaseUrl -}}
{{- .Values.app.databaseUrl -}}
{{- else if not .Values.postgres.enabled -}}
{{- fail "app.databaseUrl is required when postgres.enabled=false" -}}
{{- else if .Values.secrets.existingSecret -}}
{{- fail "app.databaseUrl is required when secrets.existingSecret is set (password not available in values)" -}}
{{- else -}}
{{- $svc := include "tline.componentName" (dict "Values" .Values "Chart" .Chart "Release" .Release "component" "postgres") -}}
{{- printf "postgres://%s:%s@%s:%d/%s" .Values.secrets.postgres.user .Values.secrets.postgres.password $svc (.Values.postgres.service.port | int) .Values.secrets.postgres.database -}}
{{- end -}}
{{- end -}}
{{- define "tline.redisUrl" -}}
{{- if .Values.app.redisUrl -}}
{{- .Values.app.redisUrl -}}
{{- else if not .Values.redis.enabled -}}
{{- fail "app.redisUrl is required when redis.enabled=false" -}}
{{- else -}}
{{- $svc := include "tline.componentName" (dict "Values" .Values "Chart" .Chart "Release" .Release "component" "redis") -}}
{{- printf "redis://%s:%d" $svc (.Values.redis.service.port | int) -}}
{{- end -}}
{{- end -}}
{{- define "tline.minioInternalEndpoint" -}}
{{- if .Values.app.minio.internalEndpoint -}}
{{- .Values.app.minio.internalEndpoint -}}
{{- else if not .Values.minio.enabled -}}
{{- fail "app.minio.internalEndpoint is required when minio.enabled=false" -}}
{{- else -}}
{{- $svc := include "tline.componentName" (dict "Values" .Values "Chart" .Chart "Release" .Release "component" "minio") -}}
{{- printf "http://%s:%d" $svc (.Values.minio.service.s3Port | int) -}}
{{- end -}}
{{- end -}}
{{- define "tline.minioPublicEndpointTs" -}}
{{- if .Values.app.minio.publicEndpointTs -}}
{{- .Values.app.minio.publicEndpointTs -}}
{{- else if and .Values.global.tailscale.enabled .Values.global.tailscale.tailnetFQDN -}}
{{- $label := .Values.minio.ingressS3.hostnameLabel -}}
{{- if .Values.minio.tailscaleServiceS3.enabled -}}
{{- $label = .Values.minio.tailscaleServiceS3.hostnameLabel -}}
{{- end -}}
{{- printf "https://%s.%s" $label .Values.global.tailscale.tailnetFQDN -}}
{{- else -}}
{{- fail "app.minio.publicEndpointTs is required (or set global.tailscale.tailnetFQDN to derive it)" -}}
{{- end -}}
{{- end -}}
{{- define "tline.image" -}}
{{- $repo := .repository | default "" -}}
{{- $tag := .tag | default "" -}}
{{- if or (not $repo) (not $tag) -}}
{{- fail "image repository and tag must be set" -}}
{{- end -}}
{{- printf "%s:%s" $repo $tag -}}
{{- end -}}
{{- define "tline.migrateImage" -}}
{{- $repo := .Values.jobs.migrate.image.repository | default .Values.images.worker.repository -}}
{{- $tag := .Values.jobs.migrate.image.tag | default .Values.images.worker.tag -}}
{{- $policy := .Values.jobs.migrate.image.pullPolicy | default .Values.images.worker.pullPolicy -}}
{{- if or (not $repo) (not $tag) -}}
{{- fail "migrate image repository/tag must be set (jobs.migrate.image or images.worker)" -}}
{{- end -}}
{{- dict "image" (printf "%s:%s" $repo $tag) "pullPolicy" $policy | toYaml -}}
{{- end -}}
{{- define "tline.registrySecretName" -}}
{{- if .Values.registrySecret.name -}}
{{- .Values.registrySecret.name -}}
{{- else -}}
{{- printf "%s-registry" (include "tline.fullname" .) -}}
{{- end -}}
{{- end -}}
{{- define "tline.imagePullSecrets" -}}
{{- $secrets := .Values.imagePullSecrets | default (list) -}}
{{- if .Values.registrySecret.create -}}
{{- $secrets = append $secrets (include "tline.registrySecretName" .) -}}
{{- end -}}
{{- if gt (len $secrets) 0 -}}
imagePullSecrets:
{{- range $name := $secrets }}
- name: {{ $name | quote }}
{{- end -}}
{{- end -}}
{{- end -}}