mirror of
https://github.com/shadoll/helm-charts.git
synced 2026-08-28 11:33:17 +00:00
feat: Add Home Assistant Helm chart with PostgreSQL backup support
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
{{/*
|
||||
Expand the name of the chart.
|
||||
*/}}
|
||||
{{- define "home-assistant.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create a default fully qualified app name.
|
||||
*/}}
|
||||
{{- define "home-assistant.fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- if contains $name .Release.Name }}
|
||||
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create chart name and version as used by the chart label.
|
||||
*/}}
|
||||
{{- define "home-assistant.chart" -}}
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Common labels
|
||||
*/}}
|
||||
{{- define "home-assistant.labels" -}}
|
||||
helm.sh/chart: {{ include "home-assistant.chart" . }}
|
||||
{{ include "home-assistant.selectorLabels" . }}
|
||||
{{- if .Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Selector labels
|
||||
*/}}
|
||||
{{- define "home-assistant.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "home-assistant.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,71 @@
|
||||
{{- if .Values.backup.enabled -}}
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: {{ include "home-assistant.fullname" . }}-backup
|
||||
{{- if .Values.namespaceOverride }}
|
||||
namespace: {{ .Values.namespaceOverride }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "home-assistant.labels" . | nindent 4 }}
|
||||
spec:
|
||||
schedule: {{ .Values.backup.schedule | quote }}
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres-backup
|
||||
image: {{ .Values.backup.image }}
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
# Backup Home Assistant database
|
||||
pg_dump -h {{ .Values.backup.postgres.host }} -U {{ .Values.backup.postgres.user }} -d $DB_NAME | gzip > /backup/$DB_NAME-$(date +%Y%m%d-%H%M%S).sql.gz
|
||||
# Retention: Delete backups older than specified days
|
||||
find /backup -name "$DB_NAME-*.sql.gz" -mtime +$RETENTION_DAYS -delete
|
||||
env:
|
||||
- name: PGPASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.backup.postgres.existingSecret }}
|
||||
key: {{ .Values.backup.postgres.secretKey }}
|
||||
- name: DB_NAME
|
||||
value: {{ .Values.backup.postgres.db | quote }}
|
||||
- name: RETENTION_DAYS
|
||||
value: {{ .Values.backup.retentionDays | quote }}
|
||||
volumeMounts:
|
||||
- name: backup-storage
|
||||
mountPath: /backup
|
||||
volumes:
|
||||
- name: backup-storage
|
||||
hostPath:
|
||||
path: {{ .Values.backup.storagePath }}
|
||||
type: DirectoryOrCreate
|
||||
restartPolicy: OnFailure
|
||||
{{- if .Values.backup.node }}
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: kubernetes.io/hostname
|
||||
operator: In
|
||||
values:
|
||||
- {{ .Values.backup.node }}
|
||||
{{- else }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 10 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 10 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 10 }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,84 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "home-assistant.fullname" . }}
|
||||
{{- if .Values.namespaceOverride }}
|
||||
namespace: {{ .Values.namespaceOverride }}
|
||||
{{- end }}
|
||||
annotations:
|
||||
version-source: github-release:home-assistant/core
|
||||
labels:
|
||||
{{- include "home-assistant.labels" . | nindent 4 }}
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "home-assistant.selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
{{- include "home-assistant.selectorLabels" . | nindent 8 }}
|
||||
spec:
|
||||
{{- if .Values.hostNetwork }}
|
||||
hostNetwork: true
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
{{- end }}
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 8123
|
||||
protocol: TCP
|
||||
{{- if .Values.homekit.enabled }}
|
||||
- name: homekit
|
||||
containerPort: {{ .Values.homekit.port }}
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
env:
|
||||
- name: TZ
|
||||
value: {{ .Values.timezone | quote }}
|
||||
volumeMounts:
|
||||
{{- if .Values.persistence.config.enabled }}
|
||||
- name: config
|
||||
mountPath: {{ .Values.persistence.config.mountPath }}
|
||||
{{- end }}
|
||||
{{- if .Values.persistence.media.enabled }}
|
||||
- name: media
|
||||
mountPath: {{ .Values.persistence.media.mountPath }}
|
||||
{{- end }}
|
||||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
volumes:
|
||||
{{- if .Values.persistence.config.enabled }}
|
||||
- name: config
|
||||
{{- if eq .Values.persistence.config.type "hostPath" }}
|
||||
hostPath:
|
||||
path: {{ .Values.persistence.config.hostPath }}
|
||||
type: DirectoryOrCreate
|
||||
{{- else }}
|
||||
persistentVolumeClaim:
|
||||
claimName: {{ .Values.persistence.config.existingClaim | default (include "home-assistant.fullname" .) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if .Values.persistence.media.enabled }}
|
||||
- name: media
|
||||
hostPath:
|
||||
path: {{ .Values.persistence.media.hostPath }}
|
||||
type: DirectoryOrCreate
|
||||
{{- end }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,32 @@
|
||||
{{- range $name, $config := .Values.ingresses }}
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ include "home-assistant.fullname" $ }}-{{ $name }}
|
||||
{{- if $.Values.namespaceOverride }}
|
||||
namespace: {{ $.Values.namespaceOverride }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "home-assistant.labels" $ | nindent 4 }}
|
||||
{{- with $config.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
rules:
|
||||
- host: {{ $config.host }}
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: {{ include "home-assistant.fullname" $ }}
|
||||
port:
|
||||
number: {{ $.Values.service.port }}
|
||||
{{- with $config.tls }}
|
||||
tls:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{- if .Values.persistence.config.enabled }}
|
||||
{{- if eq .Values.persistence.config.type "pvc" }}
|
||||
{{- if not .Values.persistence.config.existingClaim }}
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: {{ include "home-assistant.fullname" . }}
|
||||
{{- if .Values.namespaceOverride }}
|
||||
namespace: {{ .Values.namespaceOverride }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "home-assistant.labels" . | nindent 4 }}
|
||||
spec:
|
||||
accessModes:
|
||||
{{- toYaml .Values.persistence.config.accessModes | nindent 4 }}
|
||||
resources:
|
||||
requests:
|
||||
storage: {{ .Values.persistence.config.size | quote }}
|
||||
{{- if .Values.persistence.config.storageClass }}
|
||||
storageClassName: {{ .Values.persistence.config.storageClass | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,18 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "home-assistant.fullname" . }}
|
||||
{{- if .Values.namespaceOverride }}
|
||||
namespace: {{ .Values.namespaceOverride }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "home-assistant.labels" . | nindent 4 }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- port: {{ .Values.service.port }}
|
||||
targetPort: 8123
|
||||
protocol: TCP
|
||||
name: http
|
||||
selector:
|
||||
{{- include "home-assistant.selectorLabels" . | nindent 4 }}
|
||||
Reference in New Issue
Block a user