From 8be66d92a0d8a203e720f92f005387ad21eac0c7 Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Sun, 18 Jan 2026 20:12:31 +0100 Subject: [PATCH] support all in one template --- apps/charts/homarr/templates/client.yaml | 1 - apps/charts/homarr/templates/common.yaml | 1 + apps/charts/homarr/templates/deployment.yaml | 1 - apps/charts/homarr/templates/pvc.yaml | 1 - .../templates/secret-external-secrets.yaml | 1 - .../templates/secret-password-generators.yaml | 1 - apps/charts/homarr/templates/service.yaml | 1 - .../homarr/templates/virtual-service.yaml | 1 - apps/charts/komga/templates/common.yaml | 1 + apps/charts/komga/templates/deployment.yaml | 1 - apps/charts/komga/templates/pvc.yaml | 1 - apps/charts/komga/templates/service.yaml | 1 - .../komga/templates/virtual-service.yaml | 1 - apps/common/README.md | 107 ++++++++---------- apps/common/templates/_helpers.tpl | 31 ++++- 15 files changed, 79 insertions(+), 72 deletions(-) delete mode 100644 apps/charts/homarr/templates/client.yaml create mode 100644 apps/charts/homarr/templates/common.yaml delete mode 100644 apps/charts/homarr/templates/deployment.yaml delete mode 100644 apps/charts/homarr/templates/pvc.yaml delete mode 100644 apps/charts/homarr/templates/secret-external-secrets.yaml delete mode 100644 apps/charts/homarr/templates/secret-password-generators.yaml delete mode 100644 apps/charts/homarr/templates/service.yaml delete mode 100644 apps/charts/homarr/templates/virtual-service.yaml create mode 100644 apps/charts/komga/templates/common.yaml delete mode 100644 apps/charts/komga/templates/deployment.yaml delete mode 100644 apps/charts/komga/templates/pvc.yaml delete mode 100644 apps/charts/komga/templates/service.yaml delete mode 100644 apps/charts/komga/templates/virtual-service.yaml diff --git a/apps/charts/homarr/templates/client.yaml b/apps/charts/homarr/templates/client.yaml deleted file mode 100644 index c13745f..0000000 --- a/apps/charts/homarr/templates/client.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.oidc" . }} diff --git a/apps/charts/homarr/templates/common.yaml b/apps/charts/homarr/templates/common.yaml new file mode 100644 index 0000000..a6613c2 --- /dev/null +++ b/apps/charts/homarr/templates/common.yaml @@ -0,0 +1 @@ +{{ include "common.all" . }} diff --git a/apps/charts/homarr/templates/deployment.yaml b/apps/charts/homarr/templates/deployment.yaml deleted file mode 100644 index 4508e33..0000000 --- a/apps/charts/homarr/templates/deployment.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.deployment" . }} diff --git a/apps/charts/homarr/templates/pvc.yaml b/apps/charts/homarr/templates/pvc.yaml deleted file mode 100644 index 379bad9..0000000 --- a/apps/charts/homarr/templates/pvc.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.pvc" . }} diff --git a/apps/charts/homarr/templates/secret-external-secrets.yaml b/apps/charts/homarr/templates/secret-external-secrets.yaml deleted file mode 100644 index de340c4..0000000 --- a/apps/charts/homarr/templates/secret-external-secrets.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.externalSecrets.externalSecrets" . }} diff --git a/apps/charts/homarr/templates/secret-password-generators.yaml b/apps/charts/homarr/templates/secret-password-generators.yaml deleted file mode 100644 index 2183e0a..0000000 --- a/apps/charts/homarr/templates/secret-password-generators.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.externalSecrets.passwordGenerators" . }} diff --git a/apps/charts/homarr/templates/service.yaml b/apps/charts/homarr/templates/service.yaml deleted file mode 100644 index f024c64..0000000 --- a/apps/charts/homarr/templates/service.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.service" . }} diff --git a/apps/charts/homarr/templates/virtual-service.yaml b/apps/charts/homarr/templates/virtual-service.yaml deleted file mode 100644 index 766f6b9..0000000 --- a/apps/charts/homarr/templates/virtual-service.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.virtualService" . }} diff --git a/apps/charts/komga/templates/common.yaml b/apps/charts/komga/templates/common.yaml new file mode 100644 index 0000000..a6613c2 --- /dev/null +++ b/apps/charts/komga/templates/common.yaml @@ -0,0 +1 @@ +{{ include "common.all" . }} diff --git a/apps/charts/komga/templates/deployment.yaml b/apps/charts/komga/templates/deployment.yaml deleted file mode 100644 index 4508e33..0000000 --- a/apps/charts/komga/templates/deployment.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.deployment" . }} diff --git a/apps/charts/komga/templates/pvc.yaml b/apps/charts/komga/templates/pvc.yaml deleted file mode 100644 index 379bad9..0000000 --- a/apps/charts/komga/templates/pvc.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.pvc" . }} diff --git a/apps/charts/komga/templates/service.yaml b/apps/charts/komga/templates/service.yaml deleted file mode 100644 index f024c64..0000000 --- a/apps/charts/komga/templates/service.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.service" . }} diff --git a/apps/charts/komga/templates/virtual-service.yaml b/apps/charts/komga/templates/virtual-service.yaml deleted file mode 100644 index 766f6b9..0000000 --- a/apps/charts/komga/templates/virtual-service.yaml +++ /dev/null @@ -1 +0,0 @@ -{{ include "common.virtualService" . }} diff --git a/apps/common/README.md b/apps/common/README.md index 656ae39..6327b0a 100644 --- a/apps/common/README.md +++ b/apps/common/README.md @@ -30,9 +30,20 @@ Run `helm dependency build` to download the dependency. Create `values.yaml` with the standardized structure (see [Values Structure](#values-structure) below). -### 4. Create Template Files +### 4. Create Template File -Replace complex templates with simple includes: +Use a single template file that includes all resources: + +```yaml +# templates/common.yaml +{{ include "common.all" . }} +``` + +The `common.all` helper automatically includes all standard resources based on your `values.yaml` configuration. Resources are only rendered if their corresponding values are defined and enabled. + +**Alternative: Individual Templates** + +If you need more control, you can use individual template files instead: ```yaml # templates/deployment.yaml @@ -239,9 +250,29 @@ env: ## Template Files -### Basic Application +### Recommended: Single Template with `common.all` -For a simple application with persistent storage: +The simplest approach is to use a single template file: + +```yaml +# templates/common.yaml +{{ include "common.all" . }} +``` + +This automatically renders all resources based on your `values.yaml`: +- **Deployment** - always rendered if `deployment` is defined +- **Service** - always rendered if `service` is defined +- **ServiceAccount** - rendered if `serviceAccount` is defined +- **PVC** - rendered if `persistentVolumeClaims` is defined +- **VirtualService** - rendered if `virtualService.enabled: true` +- **DNS** - rendered if `dns.enabled: true` +- **OIDC** - rendered if `oidc.enabled: true` +- **Database** - rendered if `database.enabled: true` +- **ExternalSecrets** - rendered if `externalSecrets` is defined + +### Alternative: Individual Templates + +For more control or custom resources, use individual template files: ```yaml # templates/deployment.yaml @@ -255,31 +286,13 @@ For a simple application with persistent storage: # templates/virtual-service.yaml {{ include "common.virtualService" . }} -``` -### With OIDC Authentication - -Add OIDC client template: - -```yaml -# templates/client.yaml (or oidc.yaml) +# templates/client.yaml (OIDC) {{ include "common.oidc" . }} -``` -### With Database - -Add database template: - -```yaml # templates/database.yaml {{ include "common.database" . }} -``` -### With External Secrets - -Add secret generation templates: - -```yaml # templates/secret-password-generators.yaml {{ include "common.externalSecrets.passwordGenerators" . }} @@ -328,14 +341,8 @@ env: ``` ```yaml -# templates/deployment.yaml -{{ include "common.deployment" . }} - -# templates/service.yaml -{{ include "common.service" . }} - -# templates/virtual-service.yaml -{{ include "common.virtualService" . }} +# templates/common.yaml +{{ include "common.all" . }} ``` ### Example 2: Application with OIDC and Database @@ -415,23 +422,8 @@ env: ``` ```yaml -# templates/deployment.yaml -{{ include "common.deployment" . }} - -# templates/service.yaml -{{ include "common.service" . }} - -# templates/pvc.yaml -{{ include "common.pvc" . }} - -# templates/virtual-service.yaml -{{ include "common.virtualService" . }} - -# templates/client.yaml -{{ include "common.oidc" . }} - -# templates/database.yaml -{{ include "common.database" . }} +# templates/common.yaml +{{ include "common.all" . }} ``` ### Example 3: Application with Generated Secrets @@ -470,25 +462,26 @@ env: ``` ```yaml -# templates/secret-password-generators.yaml -{{ include "common.externalSecrets.passwordGenerators" . }} - -# templates/secret-external-secrets.yaml -{{ include "common.externalSecrets.externalSecrets" . }} +# templates/common.yaml +{{ include "common.all" . }} ``` ## Available Templates The library provides full resource templates that can be included directly: +- **`common.all`** - All-in-one template that renders all resources based on values (recommended) - `common.deployment` - Full Deployment resource with all standard configurations (supports custom command/args) - `common.service` - Full Service resource(s) - supports multiple services +- `common.serviceAccount` - Full ServiceAccount resource - `common.pvc` - Full PVC resources - supports multiple PVCs - `common.virtualService` - Full VirtualService resources (public + private gateways) +- `common.dns` - Full DNSRecord resource - `common.oidc` - Full AuthentikClient resource for OIDC authentication - `common.database` - Full PostgresDatabase resource for database provisioning -- `common.externalSecrets.passwordGenerators` - Password generator resources -- `common.externalSecrets.externalSecrets` - ExternalSecret resources +- `common.externalSecrets` - Combined Password generators + ExternalSecret resources +- `common.externalSecrets.passwordGenerators` - Password generator resources only +- `common.externalSecrets.externalSecrets` - ExternalSecret resources only ## Secret References @@ -697,7 +690,7 @@ After creating your chart: ## Examples See migrated charts for real-world examples: -- `apps/charts/readeck` - Simple application -- `apps/charts/miniflux` - Application with OIDC and database +- `apps/charts/komga` - Simple application using `common.all` +- `apps/charts/homarr` - Application with OIDC and external secrets using `common.all` - `apps/charts/n8n` - Complex application with multiple services - `apps/charts/home-assistant` - Application with host networking and privileged containers diff --git a/apps/common/templates/_helpers.tpl b/apps/common/templates/_helpers.tpl index 556aa88..24ea597 100644 --- a/apps/common/templates/_helpers.tpl +++ b/apps/common/templates/_helpers.tpl @@ -306,6 +306,7 @@ Full Deployment resource */}} {{- define "common.deployment" -}} {{- if .Values.deployment }} +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -390,6 +391,7 @@ Full ServiceAccount resource */}} {{- define "common.serviceAccount" -}} {{- if .Values.serviceAccount }} +--- apiVersion: v1 kind: ServiceAccount metadata: @@ -430,6 +432,7 @@ spec: {{- include "common.selectorLabels" $ | nindent 4 }} {{- end }} {{- else }} +--- apiVersion: v1 kind: Service metadata: @@ -483,6 +486,7 @@ Full VirtualService resources {{- define "common.virtualService" -}} {{- if and .Values.virtualService.enabled .Values.subdomain (hasKey .Values.globals "domain") (ne .Values.globals.domain "") }} {{- if and .Values.virtualService.gateways.public (hasKey .Values.globals "istio") (hasKey .Values.globals.istio "gateways") (hasKey .Values.globals.istio.gateways "public") (ne .Values.globals.istio.gateways.public "") }} +--- apiVersion: networking.istio.io/v1 kind: VirtualService metadata: @@ -510,9 +514,9 @@ spec: number: {{ include "common.servicePort" . }} {{- end }} ---- {{- end }} {{- if and .Values.virtualService.gateways.private (hasKey .Values.globals "istio") (hasKey .Values.globals.istio "gateways") (hasKey .Values.globals.istio.gateways "private") (ne .Values.globals.istio.gateways.private "") }} +--- apiVersion: networking.istio.io/v1 kind: VirtualService metadata: @@ -547,7 +551,8 @@ spec: Full DNS resource */}} {{- define "common.dns" -}} -{{- if and .Values.dns.enabled (hasKey .Values.globals "networking") (hasKey .Values.globals.networking "private") (hasKey .Values.globals.networking.private "ip") (ne .Values.globals.networking.private.ip "") }} +{{- if and .Values.dns .Values.dns.enabled (hasKey .Values.globals "networking") (hasKey .Values.globals.networking "private") (hasKey .Values.globals.networking.private "ip") (ne .Values.globals.networking.private.ip "") }} +--- apiVersion: dns.homelab.mortenolsen.pro/v1alpha1 kind: DNSRecord metadata: @@ -572,7 +577,8 @@ spec: Full OIDC/AuthentikClient resource */}} {{- define "common.oidc" -}} -{{- if and .Values.oidc.enabled (hasKey .Values.globals "authentik") (hasKey .Values.globals.authentik "ref") (hasKey .Values.globals.authentik.ref "name") (hasKey .Values.globals.authentik.ref "namespace") (ne .Values.globals.authentik.ref.name "") (ne .Values.globals.authentik.ref.namespace "") }} +{{- if and .Values.oidc .Values.oidc.enabled (hasKey .Values.globals "authentik") (hasKey .Values.globals.authentik "ref") (hasKey .Values.globals.authentik.ref "name") (hasKey .Values.globals.authentik.ref "namespace") (ne .Values.globals.authentik.ref.name "") (ne .Values.globals.authentik.ref.namespace "") }} +--- apiVersion: authentik.homelab.mortenolsen.pro/v1alpha1 kind: AuthentikClient metadata: @@ -597,7 +603,8 @@ spec: Full PostgreSQL Database resource */}} {{- define "common.database" -}} -{{- if and .Values.database.enabled (hasKey .Values.globals "database") (hasKey .Values.globals.database "ref") (hasKey .Values.globals.database.ref "name") (hasKey .Values.globals.database.ref "namespace") (ne .Values.globals.database.ref.name "") (ne .Values.globals.database.ref.namespace "") }} +{{- if and .Values.database .Values.database.enabled (hasKey .Values.globals "database") (hasKey .Values.globals.database "ref") (hasKey .Values.globals.database.ref "name") (hasKey .Values.globals.database.ref "namespace") (ne .Values.globals.database.ref.name "") (ne .Values.globals.database.ref.namespace "") }} +--- apiVersion: postgres.homelab.mortenolsen.pro/v1 kind: PostgresDatabase metadata: @@ -689,3 +696,19 @@ Combined helper that outputs generators first, then ExternalSecrets {{- include "common.externalSecrets.passwordGenerators" . }} {{- include "common.externalSecrets.externalSecrets" . }} {{- end }} + +{{/* +Full All-in-One resource +Includes all standard resources based on values.yaml configuration +*/}} +{{- define "common.all" -}} +{{- include "common.deployment" . }} +{{- include "common.serviceAccount" . }} +{{- include "common.service" . }} +{{- include "common.pvc" . }} +{{- include "common.virtualService" . }} +{{- include "common.dns" . }} +{{- include "common.oidc" . }} +{{- include "common.database" . }} +{{- include "common.externalSecrets" . }} +{{- end }}