diff --git a/charts/home-assistant/.helmignore b/charts/home-assistant/.helmignore new file mode 100644 index 0000000000..c1347c2c27 --- /dev/null +++ b/charts/home-assistant/.helmignore @@ -0,0 +1,2 @@ +# Patterns to ignore when building packages. +*.png diff --git a/charts/home-assistant/1.0.0/Chart.yaml b/charts/home-assistant/1.0.0/Chart.yaml new file mode 100644 index 0000000000..0c5f0d18e4 --- /dev/null +++ b/charts/home-assistant/1.0.0/Chart.yaml @@ -0,0 +1,15 @@ +apiVersion: v2 +appVersion: "2022.5.3" +icon: https://truecharts.org/_static/img/appicons/home-assistant.png +description: home-assistant App for TrueNAS SCALE +name: home-assistant +version: 1.0.0 +dependencies: +- name: common + repository: file://../../../library/common/2112.0.0 + version: 2112.0.0 +home: https://github.com/home-assistant/home-assistant +keywords: +- home-automation +sources: +- https://github.com/home-assistant/home-assistant diff --git a/charts/home-assistant/1.0.0/README.md b/charts/home-assistant/1.0.0/README.md new file mode 100644 index 0000000000..bcdded4f0a --- /dev/null +++ b/charts/home-assistant/1.0.0/README.md @@ -0,0 +1,3 @@ +# Introduction + +home assistant App for TrueNAS SCALE \ No newline at end of file diff --git a/charts/home-assistant/1.0.0/app-readme.md b/charts/home-assistant/1.0.0/app-readme.md new file mode 100644 index 0000000000..15cfb6b108 --- /dev/null +++ b/charts/home-assistant/1.0.0/app-readme.md @@ -0,0 +1 @@ +home-assistant App for TrueNAS SCALE diff --git a/charts/home-assistant/1.0.0/charts/common-2112.0.0.tgz b/charts/home-assistant/1.0.0/charts/common-2112.0.0.tgz new file mode 100644 index 0000000000..62c214e1c8 Binary files /dev/null and b/charts/home-assistant/1.0.0/charts/common-2112.0.0.tgz differ diff --git a/charts/home-assistant/1.0.0/ix_values.yaml b/charts/home-assistant/1.0.0/ix_values.yaml new file mode 100644 index 0000000000..9f8c99f3a0 --- /dev/null +++ b/charts/home-assistant/1.0.0/ix_values.yaml @@ -0,0 +1,4 @@ +image: + pullPolicy: IfNotPresent + repository: homeassistant/home-assistant + tag: "2022.5.3" diff --git a/charts/home-assistant/1.0.0/questions.yaml b/charts/home-assistant/1.0.0/questions.yaml new file mode 100644 index 0000000000..2afb8ed3fb --- /dev/null +++ b/charts/home-assistant/1.0.0/questions.yaml @@ -0,0 +1,265 @@ +groups: + - name: "Configuration" + description: "Home Assistant application configuration" + - name: "Storage" + description: "Configure storage for homeassistant" + - name: "Networking" + description: "Networking Configuration for homeassistant" + - name: "Advanced DNS Settings" + description: "Configure DNS settings" + +portals: + web_portal: + protocols: + - "http" + host: + - "$node_ip" + ports: + - "$variable-web_port" + path: "/" + +questions: + - variable: web_port + label: "Web Port for homeassistant" + group: Networking + schema: + type: int + min: 8000 + max: 65535 + default: 20810 + required: true + + - variable: timezone + label: "Configure timezone" + group: "Configuration" + description: "Configure timezone for Home Assistant" + schema: + type: string + $ref: + - "definitions/timezone" + + - variable: hostNetwork + label: "Enable Host Network" + group: "Networking" + schema: + type: boolean + default: false + + - variable: dnsConfig + label: "DNS Configuration" + group: "Advanced DNS Settings" + schema: + type: dict + attrs: + - variable: options + label: "DNS Options" + schema: + type: list + items: + - variable: optionsEntry + label: "Option Entry Configuration" + schema: + type: dict + attrs: + - variable: name + label: "Option Name" + schema: + type: string + required: true + - variable: value + label: "Option Value" + schema: + type: string + required: true + + - variable: ownerUID + label: "Storage User ID" + description: "User ID of the storage volume being used (application will chown the storage volume path with specified UID)" + group: Configuration + schema: + type: int + default: 568 + min: 1 + max: 65535 + + - variable: ownerGID + label: "Storage Group ID" + description: "Group ID of the storage volume being used (application will chown the storage volume path with specified GID)" + group: Configuration + schema: + type: int + default: 568 + min: 1 + max: 65535 + + - variable: environmentVariables + label: "Home Assistant environment" + group: "Configuration" + schema: + type: list + default: [] + items: + - variable: environmentVariable + label: "Environment Variable" + schema: + type: dict + attrs: + - variable: name + label: "Name" + schema: + type: string + - variable: value + label: "Value" + schema: + type: string + + - variable: appVolumeMounts + label: "Home Assistant Storage" + group: "Storage" + schema: + type: dict + attrs: + - variable: config + label: "Storage Volume for Configuration" + schema: + type: dict + attrs: + - variable: datasetName + label: "Configuration Storage Volume Dataset Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-config" + editable: false + - variable: mountPath + label: "Configuration Storage Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: true + default: "/config" + - variable: hostPathEnabled + label: "Enable Custom Host Path for Home Assistant Configuration Storage Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Home Assistant Configuration Storage Volume" + schema: + type: hostpath + required: true + - variable: media + label: "Storage Volume for Media" + schema: + type: dict + attrs: + - variable: datasetName + label: "Media Storage Volume Dataset Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-media" + editable: false + - variable: mountPath + label: "Media Storage Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: true + default: "/media" + - variable: hostPathEnabled + label: "Enable Custom Host Path for Home Assistant Media Storage Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Home Assistant Media Storage Volume" + schema: + type: hostpath + required: true + + + - variable: postgresAppVolumeMounts + label: "Postgres Storage" + group: "Storage" + schema: + type: dict + hidden: true + attrs: + - variable: postgres-data + label: "Postgres Data Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Postgres Data Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_data" + editable: false + - variable: mountPath + label: "Postgresql Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/var/lib/postgresql/data" + - variable: postgres-backup + label: "Postgres Backup Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Postgres Backup Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_backups" + editable: false + - variable: mountPath + label: "Postgresql Backup Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/postgres_backups" + + - variable: extraAppVolumeMounts + label: "Extra Host Path Volumes" + group: "Storage" + schema: + type: list + items: + - variable: extraAppVolume + label: "Host Path Volume" + description: "Add an extra host path volume for Home Assistant application" + schema: + type: dict + attrs: + - variable: mountPath + label: "Mount Path in Pod" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + required: true + - variable: hostPath + label: "Host Path" + description: "Host path" + schema: + type: hostpath + required: true \ No newline at end of file diff --git a/charts/home-assistant/1.0.0/templates/_postgres.tpl b/charts/home-assistant/1.0.0/templates/_postgres.tpl new file mode 100644 index 0000000000..dcb7404691 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/_postgres.tpl @@ -0,0 +1,49 @@ +{{/* +Get Home assistance Postgres Database Name +*/}} +{{- define "postgres.DatabaseName" -}} +{{- print "homeassistance" -}} +{{- end -}} + + +{{- define "postgres.imageName" -}} +{{- print "postgres:13.1" -}} +{{- end -}} + + +{{/* +Retrieve postgres backup name +This will return a unique name based on revision and chart numbers specified. +*/}} +{{- define "postgres.backupName" -}} +{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}} +{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}} +{{- end }} + + +{{/* +Retrieve postgres credentials for environment variables configuration +*/}} +{{- define "postgres.envVariableConfiguration" -}} +{{ $envList := list }} +{{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user") }} +{{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password") }} +{{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) }} +{{- end -}} + + +{{/* +Retrieve postgres volume configuration +*/}} +{{- define "postgres.volumeConfiguration" -}} +{{ include "common.storage.configureAppVolumes" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts "emptyDirVolumes" .Values.emptyDirVolumes "ixVolumes" .Values.ixVolumes) | nindent 0 }} +{{- end -}} + + +{{/* +Retrieve postgres volume mounts configuration +*/}} +{{- define "postgres.volumeMountsConfiguration" -}} +{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts ) | nindent 0 }} +{{- end -}} + diff --git a/charts/home-assistant/1.0.0/templates/backup-postgres-config.yaml b/charts/home-assistant/1.0.0/templates/backup-postgres-config.yaml new file mode 100644 index 0000000000..c9ccf66dba --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/backup-postgres-config.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "postgres-backup-hook-config-map" + annotations: + rollme: {{ randAlphaNum 5 | quote }} +data: + entrypoint.sh: |- + #!/bin/sh + cmd="/docker-entrypoint.sh postgres" + eval "${cmd}" & disown; + until pg_isready; do + sleep 5; + done; + pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName" . }} > /postgres_backups/$BACKUP_NAME; diff --git a/charts/home-assistant/1.0.0/templates/backup-postgres-hook.yaml b/charts/home-assistant/1.0.0/templates/backup-postgres-hook.yaml new file mode 100644 index 0000000000..fe1b71ea24 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/backup-postgres-hook.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ixChartContext.isUpgrade -}} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +apiVersion: batch/v1 +kind: Job +metadata: + name: "pre-upgrade-hook" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded + rollme: {{ randAlphaNum 5 | quote }} +spec: + template: + metadata: + name: "pre-upgrade-hook" + spec: + restartPolicy: Never + containers: + - name: {{ .Chart.Name }}-postgres-backup + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} + - name: BACKUP_NAME + value: {{ template "postgres.backupName" . }} + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + - name: backup-script-configmap + mountPath: /bin/backup_entrypoint.sh + readOnly: true + subPath: entrypoint.sh + command: + - "/bin/backup_entrypoint.sh" + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} + - name: backup-script-configmap + configMap: + defaultMode: 0700 + name: "postgres-backup-hook-config-map" +{{- end -}} diff --git a/charts/home-assistant/1.0.0/templates/deployment.yaml b/charts/home-assistant/1.0.0/templates/deployment.yaml new file mode 100644 index 0000000000..d7592023c1 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/deployment.yaml @@ -0,0 +1,86 @@ +{{ $postgres_values := (. | mustDeepCopy) }} +{{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }} + +apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }} +kind: Deployment +metadata: + name: {{ template "common.names.fullname" . }} + labels: + app: {{ template "common.names.name" . }} + chart: {{ template "common.names.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + rollme: {{ randAlphaNum 5 | quote }} +spec: + replicas: {{ (default 1 .Values.replicas) }} + strategy: + type: "Recreate" + selector: + matchLabels: + app: {{ template "common.names.name" . }} + release: {{ .Release.Name }} + template: + metadata: + name: {{ template "common.names.fullname" . }} + labels: + app: {{ template "common.names.name" . }} + release: {{ .Release.Name }} + {{- include "common.labels.selectorLabels" . | nindent 8 }} + annotations: {{ include "common.annotations" . | nindent 8 }} + spec: + hostNetwork: {{ .Values.hostNetwork }} + initContainers: + - name: init-postgresdb + image: {{ template "postgres.imageName" . }} + command: ['sh', '-c', "until pg_isready -h {{ template "common.names.fullname" $postgres_values }}; do echo waiting for postgres; sleep 2; done"] + imagePullPolicy: {{ .Values.image.pullPolicy }} + - name: init-configs + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - "sh" + - "/config/init/init.sh" + env: + {{ $envList := (default list .Values.environmentVariables) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_HOST" "value" (printf "%s:5432" (include "common.names.fullname" $postgres_values))) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user")}} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password")}} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }} + volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }} + - name: initial-config-script + mountPath: /config/init + + containers: + - name: {{ .Chart.Name }} + {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} + volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }} + {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }} + - name: extrappvolume-{{ $index }} + mountPath: {{ $hostPathConfiguration.mountPath }} + {{ end }} + + ports: + - name: web + containerPort: 8123 + env: + {{ $databaseName := (include "postgres.DatabaseName" .)}} + {{ $envList := (default list .Values.environmentVariables) }} + {{ $envList = mustAppend $envList (dict "name" "PUID" "value" .Values.ownerUID) }} + {{ $envList = mustAppend $envList (dict "name" "PGID" "value" .Values.ownerGID) }} + {{ $envList = mustAppend $envList (dict "name" "TZ" "value" .Values.timezone) }} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }} + +{{ include "common.networking.dnsConfiguration" .Values | nindent 6 }} + volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }} + - name: initial-config-script + configMap: + defaultMode: 0700 + name: "home-assistance-initial-script-configmap" + + {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }} + - name: extrappvolume-{{ $index }} + hostPath: + path: {{ $hostPathConfiguration.hostPath }} + {{ end }} diff --git a/charts/home-assistant/1.0.0/templates/home-assistance-init-config.yaml b/charts/home-assistant/1.0.0/templates/home-assistance-init-config.yaml new file mode 100644 index 0000000000..5a4c03183a --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/home-assistance-init-config.yaml @@ -0,0 +1,40 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "home-assistance-initial-script-configmap" + annotations: + rollme: {{ randAlphaNum 5 | quote }} +data: + configuration.yaml.default: |- + # Configure a default setup of Home Assistant (frontend, api, etc) + default_config: + + # Text to speech + tts: + - platform: google_translate + + + init.sh: |- + #!/bin/sh + if test -f "/config/configuration.yaml"; then + echo "configuration.yaml exists." + if grep -q recorder: "/config/configuration.yaml"; then + echo "configuration.yaml already contains recorder" + else + cat /config/init/recorder.default >> /config/configuration.yaml + echo " postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" >> /config/configuration.yaml + fi + else + echo "configuration.yaml does NOT exist." + cp /config/init/configuration.yaml.default /config/configuration.yaml + cat /config/init/recorder.default >> /config/configuration.yaml + echo " postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" >> /config/configuration.yaml + cat /config/init/http.default >> /config/configuration.yaml + fi + recorder.default: |- + + recorder: + purge_keep_days: 30 + commit_interval: 3 + db_url: + diff --git a/charts/home-assistant/1.0.0/templates/postgres-config.yaml b/charts/home-assistant/1.0.0/templates/postgres-config.yaml new file mode 100644 index 0000000000..8a0c284c51 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/postgres-config.yaml @@ -0,0 +1,8 @@ +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: posgress-configmap +data: + database_url: {{ template "common.names.fullname" $values }} diff --git a/charts/home-assistant/1.0.0/templates/postgres-deployment.yaml b/charts/home-assistant/1.0.0/templates/postgres-deployment.yaml new file mode 100644 index 0000000000..802ca73911 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/postgres-deployment.yaml @@ -0,0 +1,24 @@ +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +{{ include "common.deployment.common_config" $values | nindent 0 }} +spec: {{ include "common.deployment.common_spec" $values | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" $values | nindent 4 }} + spec: + hostNetwork: {{ .Values.hostNetwork }} + containers: + - name: {{ .Chart.Name }}-postgres + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + {{ $envList := (default list .Values.environmentVariables) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user")}} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password")}} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }} + + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + ports: + - name: postgres-tcp + containerPort: 5432 + protocol: TCP + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} diff --git a/charts/home-assistant/1.0.0/templates/postgres-secret.yaml b/charts/home-assistant/1.0.0/templates/postgres-secret.yaml new file mode 100644 index 0000000000..6700621026 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/postgres-secret.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: db-details +data: + db-user: {{ "postgres" | b64enc }} + {{- if .Release.IsInstall }} + db-password: {{ randAlphaNum 15 | b64enc | quote }} + {{ else }} + db-password: {{ index (lookup "v1" "Secret" .Release.Namespace "db-details").data "db-password" }} + {{ end }} diff --git a/charts/home-assistant/1.0.0/templates/postgres-service.yaml b/charts/home-assistant/1.0.0/templates/postgres-service.yaml new file mode 100644 index 0000000000..c6603fd62b --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/postgres-service.yaml @@ -0,0 +1,6 @@ +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "postgres-tcp" "port" 5432 "targetPort" 5432) }} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +{{ $_1 := set $values "commonService" (dict "type" "ClusterIP" "ports" $ports ) }} +{{ include "common.classes.service" $values }} diff --git a/charts/home-assistant/1.0.0/templates/pre-install-job.yaml b/charts/home-assistant/1.0.0/templates/pre-install-job.yaml new file mode 100644 index 0000000000..2c4074efc9 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/pre-install-job.yaml @@ -0,0 +1,33 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ template "common.names.fullname" . }}-preinstall-job" + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} + helm.sh/chart: {{ template "common.names.chart" . }} + annotations: + "helm.sh/hook": pre-install + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: "{{ template "common.names.fullname" . }}-preinstall-hook" + labels: + app.kubernetes.io/managed-by: {{ .Release.Service | quote }} + app.kubernetes.io/instance: {{ .Release.Name | quote }} + helm.sh/chart: {{ template "common.names.chart" . }} + spec: + restartPolicy: Never + containers: + - name: pre-install-job + image: "alpine:latest" + command: + - "chown" + - "-R" + - "{{ .Values.ownerUID }}:{{ .Values.ownerGID }}" + - "{{ .Values.appVolumeMounts.config.mountPath }}" + - "{{ .Values.appVolumeMounts.media.mountPath }}" + volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }} + volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }} diff --git a/charts/home-assistant/1.0.0/templates/service.yaml b/charts/home-assistant/1.0.0/templates/service.yaml new file mode 100644 index 0000000000..79b48458e5 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/service.yaml @@ -0,0 +1,10 @@ +{{ $svc := .Values.service }} +{{ $selectors := list }} +{{ $selectors = mustAppend $selectors (dict "key" "app" "value" (include "common.names.name" .) ) }} +{{ $selectors = mustAppend $selectors (dict "key" "release" "value" .Release.Name ) }} +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "web" "port" .Values.web_port "nodePort" .Values.web_port "targetPort" 8123) }} +{{ $params := . }} +{{ $_ := set $params "commonService" (dict "type" "NodePort" "ports" $ports ) }} +{{ $_1 := set .Values "extraSelectorLabels" $selectors }} +{{ include "common.classes.service" $params }} diff --git a/charts/home-assistant/1.0.0/templates/tests/deployment-check.yaml b/charts/home-assistant/1.0.0/templates/tests/deployment-check.yaml new file mode 100644 index 0000000000..7e888eb0b9 --- /dev/null +++ b/charts/home-assistant/1.0.0/templates/tests/deployment-check.yaml @@ -0,0 +1,21 @@ +{{- $serviceName := (include "common.names.fullname" .) -}} +apiVersion: v1 +kind: Pod +metadata: + name: {{ .Release.Name }}-test-pod + labels: + app: {{ .Release.Name }} + release: {{ .Release.Name }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: test-curl + image: alpine/curl + imagePullPolicy: "IfNotPresent" + command: + - /bin/sh + - -ec + - | + curl --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 15 --retry-max-time 90 --retry-all-errors -ksf http://{{ $serviceName }}:{{.Values.web_port}}/ + restartPolicy: Never diff --git a/charts/home-assistant/1.0.0/test_values.yaml b/charts/home-assistant/1.0.0/test_values.yaml new file mode 100644 index 0000000000..22dd97d8de --- /dev/null +++ b/charts/home-assistant/1.0.0/test_values.yaml @@ -0,0 +1,37 @@ +image: + pullPolicy: IfNotPresent + repository: homeassistant/home-assistant + tag: "2022.5.3" +environmentVariables: [] +extraAppVolumeMounts: [] +web_port: 32000 +dnsConfig: + options: [] +emptyDirVolumes: true +appVolumeMounts: + config: + emptyDir: true + mountPath: /config + media: + emptyDir: true + mountPath: /media +ownerUID: 568 +ownerGID: 568 +hostNetwork: false +timezone: "America/Los_Angeles" + +postgresAppVolumeMounts: + postgres-backup: + emptyDir: true + mountPath: /postgres_backups + postgres-data: + emptyDir: true + mountPath: /var/lib/postgresql/data +postgresql: + backupVolume: + datasetName: ix-postgres_backups + mountPath: /postgres_backups + dataVolume: + datasetName: ix-postgres_data + mountPath: /var/lib/postgresql/data +ixChartContext: {} diff --git a/charts/home-assistant/item.yaml b/charts/home-assistant/item.yaml new file mode 100644 index 0000000000..2a5998ac2b --- /dev/null +++ b/charts/home-assistant/item.yaml @@ -0,0 +1,3 @@ +icon_url: https://truecharts.org/_static/img/appicons/home-assistant.png +categories: +- home-automation diff --git a/charts/home-assistant/upgrade_info.json b/charts/home-assistant/upgrade_info.json new file mode 100644 index 0000000000..5bf84fb901 --- /dev/null +++ b/charts/home-assistant/upgrade_info.json @@ -0,0 +1 @@ +{"filename": "ix_values.yaml", "keys": ["image"]} diff --git a/charts/home-assistant/upgrade_strategy b/charts/home-assistant/upgrade_strategy new file mode 100755 index 0000000000..7b17b7c084 --- /dev/null +++ b/charts/home-assistant/upgrade_strategy @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +import json +import sys + +from catalog_update.upgrade_strategy import semantic_versioning + + +def newer_mapping(image_tags): + key = list(image_tags.keys())[0] + tags = {t: t for t in image_tags[key]} + version = semantic_versioning(list(tags)) + if not version: + return {} + + return { + 'tags': {key: tags[version]}, + 'app_version': version, + } + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + print(json.dumps(newer_mapping(json.loads(sys.argv[1])))) diff --git a/test/home-assistant/1.0.0/questions.yaml b/test/home-assistant/1.0.0/questions.yaml index 23e00e2522..2afb8ed3fb 100644 --- a/test/home-assistant/1.0.0/questions.yaml +++ b/test/home-assistant/1.0.0/questions.yaml @@ -154,6 +154,90 @@ questions: schema: type: hostpath required: true + - variable: media + label: "Storage Volume for Media" + schema: + type: dict + attrs: + - variable: datasetName + label: "Media Storage Volume Dataset Name" + schema: + type: string + hidden: true + $ref: + - "normalize/ixVolume" + show_if: [["hostPathEnabled", "=", false]] + default: "ix-media" + editable: false + - variable: mountPath + label: "Media Storage Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + hidden: true + editable: true + default: "/media" + - variable: hostPathEnabled + label: "Enable Custom Host Path for Home Assistant Media Storage Volume" + schema: + type: boolean + default: false + show_subquestions_if: true + subquestions: + - variable: hostPath + label: "Host Path for Home Assistant Media Storage Volume" + schema: + type: hostpath + required: true + + + - variable: postgresAppVolumeMounts + label: "Postgres Storage" + group: "Storage" + schema: + type: dict + hidden: true + attrs: + - variable: postgres-data + label: "Postgres Data Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Postgres Data Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_data" + editable: false + - variable: mountPath + label: "Postgresql Data Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/var/lib/postgresql/data" + - variable: postgres-backup + label: "Postgres Backup Volume" + schema: + type: dict + attrs: + - variable: datasetName + label: "Postgres Backup Volume Name" + schema: + type: string + $ref: + - "normalize/ixVolume" + default: "ix-postgres_backups" + editable: false + - variable: mountPath + label: "Postgresql Backup Mount Path" + description: "Path where the volume will be mounted inside the pod" + schema: + type: path + editable: false + default: "/postgres_backups" - variable: extraAppVolumeMounts label: "Extra Host Path Volumes" diff --git a/test/home-assistant/1.0.0/templates/_postgres.tpl b/test/home-assistant/1.0.0/templates/_postgres.tpl new file mode 100644 index 0000000000..dcb7404691 --- /dev/null +++ b/test/home-assistant/1.0.0/templates/_postgres.tpl @@ -0,0 +1,49 @@ +{{/* +Get Home assistance Postgres Database Name +*/}} +{{- define "postgres.DatabaseName" -}} +{{- print "homeassistance" -}} +{{- end -}} + + +{{- define "postgres.imageName" -}} +{{- print "postgres:13.1" -}} +{{- end -}} + + +{{/* +Retrieve postgres backup name +This will return a unique name based on revision and chart numbers specified. +*/}} +{{- define "postgres.backupName" -}} +{{- $upgradeDict := .Values.ixChartContext.upgradeMetadata -}} +{{- printf "postgres-backup-from-%s-to-%s-revision-%d" $upgradeDict.oldChartVersion $upgradeDict.newChartVersion (int64 $upgradeDict.preUpgradeRevision) -}} +{{- end }} + + +{{/* +Retrieve postgres credentials for environment variables configuration +*/}} +{{- define "postgres.envVariableConfiguration" -}} +{{ $envList := list }} +{{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user") }} +{{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password") }} +{{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) }} +{{- end -}} + + +{{/* +Retrieve postgres volume configuration +*/}} +{{- define "postgres.volumeConfiguration" -}} +{{ include "common.storage.configureAppVolumes" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts "emptyDirVolumes" .Values.emptyDirVolumes "ixVolumes" .Values.ixVolumes) | nindent 0 }} +{{- end -}} + + +{{/* +Retrieve postgres volume mounts configuration +*/}} +{{- define "postgres.volumeMountsConfiguration" -}} +{{ include "common.storage.configureAppVolumeMountsInContainer" (dict "appVolumeMounts" .Values.postgresAppVolumeMounts ) | nindent 0 }} +{{- end -}} + diff --git a/test/home-assistant/1.0.0/templates/backup-postgres-config.yaml b/test/home-assistant/1.0.0/templates/backup-postgres-config.yaml new file mode 100644 index 0000000000..c9ccf66dba --- /dev/null +++ b/test/home-assistant/1.0.0/templates/backup-postgres-config.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "postgres-backup-hook-config-map" + annotations: + rollme: {{ randAlphaNum 5 | quote }} +data: + entrypoint.sh: |- + #!/bin/sh + cmd="/docker-entrypoint.sh postgres" + eval "${cmd}" & disown; + until pg_isready; do + sleep 5; + done; + pg_dump -U $POSTGRES_USER -d {{ template "postgres.DatabaseName" . }} > /postgres_backups/$BACKUP_NAME; diff --git a/test/home-assistant/1.0.0/templates/backup-postgres-hook.yaml b/test/home-assistant/1.0.0/templates/backup-postgres-hook.yaml new file mode 100644 index 0000000000..fe1b71ea24 --- /dev/null +++ b/test/home-assistant/1.0.0/templates/backup-postgres-hook.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ixChartContext.isUpgrade -}} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +apiVersion: batch/v1 +kind: Job +metadata: + name: "pre-upgrade-hook" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded + rollme: {{ randAlphaNum 5 | quote }} +spec: + template: + metadata: + name: "pre-upgrade-hook" + spec: + restartPolicy: Never + containers: + - name: {{ .Chart.Name }}-postgres-backup + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: {{ include "postgres.envVariableConfiguration" $values | nindent 10 }} + - name: BACKUP_NAME + value: {{ template "postgres.backupName" . }} + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + - name: backup-script-configmap + mountPath: /bin/backup_entrypoint.sh + readOnly: true + subPath: entrypoint.sh + command: + - "/bin/backup_entrypoint.sh" + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} + - name: backup-script-configmap + configMap: + defaultMode: 0700 + name: "postgres-backup-hook-config-map" +{{- end -}} diff --git a/test/home-assistant/1.0.0/templates/deployment.yaml b/test/home-assistant/1.0.0/templates/deployment.yaml index e1a01f6745..d7592023c1 100644 --- a/test/home-assistant/1.0.0/templates/deployment.yaml +++ b/test/home-assistant/1.0.0/templates/deployment.yaml @@ -1,3 +1,6 @@ +{{ $postgres_values := (. | mustDeepCopy) }} +{{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }} + apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }} kind: Deployment metadata: @@ -27,6 +30,28 @@ spec: annotations: {{ include "common.annotations" . | nindent 8 }} spec: hostNetwork: {{ .Values.hostNetwork }} + initContainers: + - name: init-postgresdb + image: {{ template "postgres.imageName" . }} + command: ['sh', '-c', "until pg_isready -h {{ template "common.names.fullname" $postgres_values }}; do echo waiting for postgres; sleep 2; done"] + imagePullPolicy: {{ .Values.image.pullPolicy }} + - name: init-configs + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - "sh" + - "/config/init/init.sh" + env: + {{ $envList := (default list .Values.environmentVariables) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_HOST" "value" (printf "%s:5432" (include "common.names.fullname" $postgres_values))) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user")}} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password")}} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }} + volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }} + - name: initial-config-script + mountPath: /config/init + containers: - name: {{ .Chart.Name }} {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} @@ -35,18 +60,25 @@ spec: - name: extrappvolume-{{ $index }} mountPath: {{ $hostPathConfiguration.mountPath }} {{ end }} + ports: - name: web containerPort: 8123 env: - {{ $secretName := (include "common.names.fullname" .) }} + {{ $databaseName := (include "postgres.DatabaseName" .)}} {{ $envList := (default list .Values.environmentVariables) }} {{ $envList = mustAppend $envList (dict "name" "PUID" "value" .Values.ownerUID) }} {{ $envList = mustAppend $envList (dict "name" "PGID" "value" .Values.ownerGID) }} {{ $envList = mustAppend $envList (dict "name" "TZ" "value" .Values.timezone) }} {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 12 }} + {{ include "common.networking.dnsConfiguration" .Values | nindent 6 }} volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }} + - name: initial-config-script + configMap: + defaultMode: 0700 + name: "home-assistance-initial-script-configmap" + {{ range $index, $hostPathConfiguration := .Values.extraAppVolumeMounts }} - name: extrappvolume-{{ $index }} hostPath: diff --git a/test/home-assistant/1.0.0/templates/home-assistance-init-config.yaml b/test/home-assistant/1.0.0/templates/home-assistance-init-config.yaml new file mode 100644 index 0000000000..5a4c03183a --- /dev/null +++ b/test/home-assistant/1.0.0/templates/home-assistance-init-config.yaml @@ -0,0 +1,40 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: "home-assistance-initial-script-configmap" + annotations: + rollme: {{ randAlphaNum 5 | quote }} +data: + configuration.yaml.default: |- + # Configure a default setup of Home Assistant (frontend, api, etc) + default_config: + + # Text to speech + tts: + - platform: google_translate + + + init.sh: |- + #!/bin/sh + if test -f "/config/configuration.yaml"; then + echo "configuration.yaml exists." + if grep -q recorder: "/config/configuration.yaml"; then + echo "configuration.yaml already contains recorder" + else + cat /config/init/recorder.default >> /config/configuration.yaml + echo " postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" >> /config/configuration.yaml + fi + else + echo "configuration.yaml does NOT exist." + cp /config/init/configuration.yaml.default /config/configuration.yaml + cat /config/init/recorder.default >> /config/configuration.yaml + echo " postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}" >> /config/configuration.yaml + cat /config/init/http.default >> /config/configuration.yaml + fi + recorder.default: |- + + recorder: + purge_keep_days: 30 + commit_interval: 3 + db_url: + diff --git a/test/home-assistant/1.0.0/templates/postgres-config.yaml b/test/home-assistant/1.0.0/templates/postgres-config.yaml new file mode 100644 index 0000000000..8a0c284c51 --- /dev/null +++ b/test/home-assistant/1.0.0/templates/postgres-config.yaml @@ -0,0 +1,8 @@ +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: posgress-configmap +data: + database_url: {{ template "common.names.fullname" $values }} diff --git a/test/home-assistant/1.0.0/templates/postgres-deployment.yaml b/test/home-assistant/1.0.0/templates/postgres-deployment.yaml new file mode 100644 index 0000000000..802ca73911 --- /dev/null +++ b/test/home-assistant/1.0.0/templates/postgres-deployment.yaml @@ -0,0 +1,24 @@ +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +{{ include "common.deployment.common_config" $values | nindent 0 }} +spec: {{ include "common.deployment.common_spec" $values | nindent 2 }} + template: {{ include "common.deployment.pod.metadata" $values | nindent 4 }} + spec: + hostNetwork: {{ .Values.hostNetwork }} + containers: + - name: {{ .Chart.Name }}-postgres + image: {{ template "postgres.imageName" . }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + {{ $envList := (default list .Values.environmentVariables) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_DB" "value" (include "postgres.DatabaseName" .)) }} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_USER" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-user")}} + {{ $envList = mustAppend $envList (dict "name" "POSTGRES_PASSWORD" "valueFromSecret" true "secretName" "db-details" "secretKey" "db-password")}} + {{ include "common.containers.environmentVariables" (dict "environmentVariables" $envList) | nindent 10 }} + + volumeMounts: {{ include "postgres.volumeMountsConfiguration" $values | nindent 10 }} + ports: + - name: postgres-tcp + containerPort: 5432 + protocol: TCP + volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} diff --git a/test/home-assistant/1.0.0/templates/postgres-secret.yaml b/test/home-assistant/1.0.0/templates/postgres-secret.yaml new file mode 100644 index 0000000000..6700621026 --- /dev/null +++ b/test/home-assistant/1.0.0/templates/postgres-secret.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: db-details +data: + db-user: {{ "postgres" | b64enc }} + {{- if .Release.IsInstall }} + db-password: {{ randAlphaNum 15 | b64enc | quote }} + {{ else }} + db-password: {{ index (lookup "v1" "Secret" .Release.Namespace "db-details").data "db-password" }} + {{ end }} diff --git a/test/home-assistant/1.0.0/templates/postgres-service.yaml b/test/home-assistant/1.0.0/templates/postgres-service.yaml new file mode 100644 index 0000000000..c6603fd62b --- /dev/null +++ b/test/home-assistant/1.0.0/templates/postgres-service.yaml @@ -0,0 +1,6 @@ +{{ $ports := list }} +{{ $ports = mustAppend $ports (dict "name" "postgres-tcp" "port" 5432 "targetPort" 5432) }} +{{ $values := (. | mustDeepCopy) }} +{{ $_ := set $values "common" (dict "nameSuffix" "postgres") }} +{{ $_1 := set $values "commonService" (dict "type" "ClusterIP" "ports" $ports ) }} +{{ include "common.classes.service" $values }} diff --git a/test/home-assistant/1.0.0/templates/pre-install-job.yaml b/test/home-assistant/1.0.0/templates/pre-install-job.yaml index 4c8aa92a0a..2c4074efc9 100644 --- a/test/home-assistant/1.0.0/templates/pre-install-job.yaml +++ b/test/home-assistant/1.0.0/templates/pre-install-job.yaml @@ -28,5 +28,6 @@ spec: - "-R" - "{{ .Values.ownerUID }}:{{ .Values.ownerGID }}" - "{{ .Values.appVolumeMounts.config.mountPath }}" + - "{{ .Values.appVolumeMounts.media.mountPath }}" volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }} volumes: {{ include "common.storage.configureAppVolumes" .Values | nindent 8 }} diff --git a/test/home-assistant/1.0.0/test_values.yaml b/test/home-assistant/1.0.0/test_values.yaml index 289b4adc1c..22dd97d8de 100644 --- a/test/home-assistant/1.0.0/test_values.yaml +++ b/test/home-assistant/1.0.0/test_values.yaml @@ -12,7 +12,26 @@ appVolumeMounts: config: emptyDir: true mountPath: /config + media: + emptyDir: true + mountPath: /media ownerUID: 568 ownerGID: 568 hostNetwork: false timezone: "America/Los_Angeles" + +postgresAppVolumeMounts: + postgres-backup: + emptyDir: true + mountPath: /postgres_backups + postgres-data: + emptyDir: true + mountPath: /var/lib/postgresql/data +postgresql: + backupVolume: + datasetName: ix-postgres_backups + mountPath: /postgres_backups + dataVolume: + datasetName: ix-postgres_data + mountPath: /var/lib/postgresql/data +ixChartContext: {}