diff --git a/charts/home-assistant/2.0.0/.helmignore b/charts/home-assistant/2.0.0/.helmignore new file mode 100644 index 0000000000..c1347c2c27 --- /dev/null +++ b/charts/home-assistant/2.0.0/.helmignore @@ -0,0 +1,2 @@ +# Patterns to ignore when building packages. +*.png diff --git a/charts/home-assistant/2.0.0/Chart.lock b/charts/home-assistant/2.0.0/Chart.lock new file mode 100644 index 0000000000..54416569a7 --- /dev/null +++ b/charts/home-assistant/2.0.0/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: common + repository: file://../../../common + version: 1.2.9 +digest: sha256:af1a9a1f87e3e48453c9f25f909f5ebcd7fa6e25162b7b425448ba752bcdbc5c +generated: "2024-01-19T14:50:50.732430258+02:00" diff --git a/charts/home-assistant/2.0.0/Chart.yaml b/charts/home-assistant/2.0.0/Chart.yaml new file mode 100644 index 0000000000..e0aece608b --- /dev/null +++ b/charts/home-assistant/2.0.0/Chart.yaml @@ -0,0 +1,24 @@ +name: home-assistant +description: Home Assistant App for TrueNAS SCALE +annotations: + title: Home Assistant +type: application +version: 2.0.0 +apiVersion: v2 +appVersion: 2024.1.3 +kubeVersion: '>=1.16.0-0' +maintainers: + - name: truenas + url: https://www.truenas.com/ + email: dev@ixsystems.com +dependencies: + - name: common + repository: file://../../../common + version: 1.2.9 +home: https://github.com/home-assistant/home-assistant +icon: https://media.sys.truenas.net/apps/home-assistant/icons/icon.png +sources: + - https://github.com/home-assistant/home-assistant + - https://github.com/truenas/charts/tree/master/charts/home-assistant +keywords: + - home-automation diff --git a/charts/home-assistant/2.0.0/README.md b/charts/home-assistant/2.0.0/README.md new file mode 100644 index 0000000000..bcdded4f0a --- /dev/null +++ b/charts/home-assistant/2.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/2.0.0/app-readme.md b/charts/home-assistant/2.0.0/app-readme.md new file mode 100644 index 0000000000..15cfb6b108 --- /dev/null +++ b/charts/home-assistant/2.0.0/app-readme.md @@ -0,0 +1 @@ +home-assistant App for TrueNAS SCALE diff --git a/charts/home-assistant/2.0.0/charts/common-1.2.9.tgz b/charts/home-assistant/2.0.0/charts/common-1.2.9.tgz new file mode 100644 index 0000000000..4b09cad699 Binary files /dev/null and b/charts/home-assistant/2.0.0/charts/common-1.2.9.tgz differ diff --git a/charts/home-assistant/2.0.0/ci/basic-values.yaml b/charts/home-assistant/2.0.0/ci/basic-values.yaml new file mode 100644 index 0000000000..cdb0941383 --- /dev/null +++ b/charts/home-assistant/2.0.0/ci/basic-values.yaml @@ -0,0 +1,15 @@ +haNetwork: + webPort: 31000 + +haStorage: + config: + type: pvc + media: + type: pvc + pgData: + type: pvc + pgBackup: + type: emptyDir + emptyDirConfig: + medium: "" + size: "" diff --git a/charts/home-assistant/2.0.0/ix_values.yaml b/charts/home-assistant/2.0.0/ix_values.yaml new file mode 100644 index 0000000000..beddd167b1 --- /dev/null +++ b/charts/home-assistant/2.0.0/ix_values.yaml @@ -0,0 +1,70 @@ +image: + pullPolicy: IfNotPresent + repository: homeassistant/home-assistant + tag: 2024.1.3 + +# Keep using the same image +# as before the migration +haPostgresImage: + pullPolicy: IfNotPresent + repository: postgres + tag: "13.1" + +yqImage: + pullPolicy: IfNotPresent + repository: mikefarah/yq + tag: 4.40.5 + +podOptions: + dnsConfig: + options: [] + +haConfig: + additionalEnvs: [] + +haNetwork: + webPort: 20810 + hostNetwork: false + +haID: + user: 568 + group: 568 + +haStorage: + config: + type: ixVolume + ixVolumeConfig: + datasetName: config + media: + type: ixVolume + ixVolumeConfig: + datasetName: media + pgData: + type: ixVolume + ixVolumeConfig: + datasetName: pgData + pgBackup: + type: ixVolume + ixVolumeConfig: + datasetName: pgBackup + additionalStorages: [] + +notes: + custom: | + ## Database + You can connect to the database using the pgAdmin App from the catalog + +
+ Database Details + + - Database: `{{ .Values.haDbName }}` + - Username: `{{ .Values.haDbUser }}` + - Password: `{{ .Values.haDbPass }}` + - Host: `{{ .Values.haDbHost }}.{{ .Release.Namespace }}.svc.cluster.local` + - Port: `5432` + +
+ {{- $_ := unset .Values "haDbUser" }} + {{- $_ := unset .Values "haDbName" }} + {{- $_ := unset .Values "haDbPass" }} + {{- $_ := unset .Values "haDbHost" }} diff --git a/charts/home-assistant/2.0.0/metadata.yaml b/charts/home-assistant/2.0.0/metadata.yaml new file mode 100644 index 0000000000..61486a5797 --- /dev/null +++ b/charts/home-assistant/2.0.0/metadata.yaml @@ -0,0 +1,17 @@ +runAsContext: + - userName: root + groupName: root + gid: 0 + uid: 0 + description: Home-Assistant runs as root user. + - userName: postgres + groupName: postgres + gid: 999 + uid: 999 + description: Postgres runs as a non-root user. +capabilities: + - name: NET_BIND_SERVICE + description: Home Assistant is able to bind to privileged ports. + - name: NET_RAW + description: Home Assistant is able to use raw sockets. +hostMounts: [] diff --git a/charts/home-assistant/2.0.0/migrations/migrate b/charts/home-assistant/2.0.0/migrations/migrate new file mode 100755 index 0000000000..b38d51c4e5 --- /dev/null +++ b/charts/home-assistant/2.0.0/migrations/migrate @@ -0,0 +1,94 @@ +#!/usr/bin/python3 +import json +import os +import sys + +def migrate_volume(volume): + return { + 'type': 'hostPath', + 'hostPathConfig': { + 'hostPath': volume['hostPath'] + }, + } if volume.get('hostPathEnabled', False) else { + 'type': 'ixVolume', + 'ixVolumeConfig': { + 'datasetName': volume['datasetName'], + }, + } + +def migrate_common_lib(values): + delete_keys = [ + 'web_port', 'hostNetwork', 'cpuLimit', 'memLimit', 'enableResourceLimits', + 'dnsConfig', 'environmentVariables', 'appVolumeMounts', 'postgresAppVolumeMounts', + 'extraAppVolumeMounts', 'ownerUID', 'ownerGID', 'timezone' + ] + + values.update({ + # Migrate Network + 'haNetwork': { + 'webPort': values['web_port'], + 'hostNetwork': values['hostNetwork'], + }, + # Migrate Resources + 'resources': { + 'limits': { + 'cpu': values.get('cpuLimit', '4000m'), + 'memory': values.get('memLimit', '8Gi'), + } + }, + 'haID': { + 'user': values.get('ownerUID'), + 'group': values.get('ownerGID'), + }, + # Migrate DNS + 'podOptions': { + 'dnsConfig': { + 'options': [ + {'name': opt['name'], 'value': opt['value']} + for opt in values.get('dnsConfig', {}).get('options', []) + ] + } + }, + # Migrate Config + 'TZ': values.get('timezone'), + 'haConfig': { + 'additionalEnvs': values.get('environmentVariables', []), + }, + # Migrate Storage + 'haStorage': { + 'config': migrate_volume(values['appVolumeMounts']['config']), + 'media': migrate_volume(values['appVolumeMounts']['media']), + 'pgData': migrate_volume(values['postgresAppVolumeMounts']['postgres-data']), + 'pgBackup': migrate_volume(values['postgresAppVolumeMounts']['postgres-backup']), + 'additionalStorages': [ + { + 'type': 'hostPath', + 'hostPathConfig': {'hostPath': e['hostPath']}, + 'mountPath': e['mountPath'], + } + for e in values.get('extraAppVolumeMounts', []) + ], + }, + }) + + for k in delete_keys: + values.pop(k, None) + + return values + +def migrate(values): + # If this missing, we have already migrated + if not 'appVolumeMounts' in values.keys(): + return values + + + return migrate_common_lib(values) + + +if __name__ == '__main__': + if len(sys.argv) != 2: + exit(1) + + if os.path.exists(sys.argv[1]): + with open(sys.argv[1], 'r') as f: + print(json.dumps(migrate(json.loads(f.read())))) diff --git a/charts/home-assistant/2.0.0/questions.yaml b/charts/home-assistant/2.0.0/questions.yaml new file mode 100644 index 0000000000..dc122cdb0e --- /dev/null +++ b/charts/home-assistant/2.0.0/questions.yaml @@ -0,0 +1,633 @@ +groups: + - name: Home Assistant Configuration + description: Configure Home Assistant + - name: User and Group Configuration + description: Configure User and Group for Home Assistant + - name: Advanced Pod Configuration + description: Configure Advanced Pod Options for Home Assistant + - name: Network Configuration + description: Configure Network for Home Assistant + - name: Storage Configuration + description: Configure Storage for Home Assistant + - name: Resources Configuration + description: Configure Resources for Home Assistant + +portals: + web_portal: + protocols: + - "$kubernetes-resource_configmap_portal_protocol" + host: + - "$kubernetes-resource_configmap_portal_host" + ports: + - "$kubernetes-resource_configmap_portal_port" + path: "$kubernetes-resource_configmap_portal_path" + +questions: + - variable: TZ + group: Home Assistant Configuration + label: Timezone + schema: + type: string + default: Etc/UTC + required: true + $ref: + - definitions/timezone + + - variable: podOptions + label: "" + group: Advanced Pod Configuration + schema: + type: dict + attrs: + - variable: dnsConfig + label: Advanced DNS Configuration + schema: + type: dict + attrs: + - variable: options + label: DNS Options + schema: + type: list + items: + - variable: optionsEntry + label: DNS Option Entry + 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: haNetwork + label: "" + group: Network Configuration + schema: + type: dict + attrs: + - variable: webPort + label: Web Port + description: The port for the Home Assistant Web UI. + schema: + type: int + default: 20810 + min: 9000 + max: 65535 + required: true + - variable: hostNetwork + label: Host Network + schema: + type: boolean + default: true + + - variable: haID + label: "" + group: User and Group Configuration + schema: + type: dict + attrs: + - variable: user + label: User ID + description: The user id that Home Assistant files will be owned by. + schema: + type: int + min: 568 + default: 568 + required: true + - variable: group + label: Group ID + description: The group id that Home Assistant files will be owned by. + schema: + type: int + min: 568 + default: 568 + required: true + + + - variable: haStorage + label: "" + group: Storage Configuration + schema: + type: dict + attrs: + - variable: config + label: Home Assistant Configuration Storage + description: The path to store Home Assistant Configuration. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ Host Path: Is a path that already exists on the system. + schema: + type: string + required: true + immutable: true + default: ixVolume + enum: + - value: hostPath + description: Host Path (Path that already exists on the system) + - value: ixVolume + description: ixVolume (Dataset created automatically by the system) + - variable: ixVolumeConfig + label: ixVolume Configuration + description: The configuration for the ixVolume dataset. + schema: + type: dict + show_if: [["type", "=", "ixVolume"]] + $ref: + - "normalize/ixVolume" + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + default: false + - variable: datasetName + label: Dataset Name + description: The name of the dataset to use for storage. + schema: + type: string + required: true + immutable: true + hidden: true + default: "config" + - variable: aclEntries + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + - variable: hostPathConfig + label: Host Path Configuration + schema: + type: dict + show_if: [["type", "=", "hostPath"]] + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + default: false + - variable: acl + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + $ref: + - "normalize/acl" + - variable: hostPath + label: Host Path + description: The host path to use for storage. + schema: + type: hostpath + show_if: [["aclEnable", "=", false]] + required: true + + - variable: media + label: Home Assistant Media Storage + description: The path to store Home Assistant Media. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ Host Path: Is a path that already exists on the system. + schema: + type: string + required: true + immutable: true + default: ixVolume + enum: + - value: hostPath + description: Host Path (Path that already exists on the system) + - value: ixVolume + description: ixVolume (Dataset created automatically by the system) + - variable: ixVolumeConfig + label: ixVolume Configuration + description: The configuration for the ixVolume dataset. + schema: + type: dict + show_if: [["type", "=", "ixVolume"]] + $ref: + - "normalize/ixVolume" + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + default: false + - variable: datasetName + label: Dataset Name + description: The name of the dataset to use for storage. + schema: + type: string + required: true + immutable: true + hidden: true + default: "media" + - variable: aclEntries + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + - variable: hostPathConfig + label: Host Path Configuration + schema: + type: dict + show_if: [["type", "=", "hostPath"]] + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + default: false + - variable: acl + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + $ref: + - "normalize/acl" + - variable: hostPath + label: Host Path + description: The host path to use for storage. + schema: + type: hostpath + show_if: [["aclEnable", "=", false]] + required: true + + - variable: pgData + label: Home Assistant Postgres Data Storage + description: The path to store Home Assistant Postgres Data. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ Host Path: Is a path that already exists on the system. + schema: + type: string + required: true + immutable: true + default: ixVolume + enum: + - value: hostPath + description: Host Path (Path that already exists on the system) + - value: ixVolume + description: ixVolume (Dataset created automatically by the system) + - variable: ixVolumeConfig + label: ixVolume Configuration + description: The configuration for the ixVolume dataset. + schema: + type: dict + # Nothing to show for the user + hidden: true + show_if: [["type", "=", "ixVolume"]] + $ref: + - "normalize/ixVolume" + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + # Postgres does a CHMOD at startup + # Which fails with ACL + hidden: true + default: false + - variable: datasetName + label: Dataset Name + description: The name of the dataset to use for storage. + schema: + type: string + required: true + immutable: true + hidden: true + default: "pgData" + - variable: aclEntries + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + - variable: hostPathConfig + label: Host Path Configuration + schema: + type: dict + show_if: [["type", "=", "hostPath"]] + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + # Postgres does a CHMOD at startup + # Which fails with ACL + hidden: true + default: false + - variable: acl + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + $ref: + - "normalize/acl" + - variable: hostPath + label: Host Path + description: The host path to use for storage. + schema: + type: hostpath + show_if: [["aclEnable", "=", false]] + required: true + - variable: pgBackup + label: Home Assistant Postgres Backup Storage + description: The path to store Home Assistant Postgres Backup. + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ Host Path: Is a path that already exists on the system. + schema: + type: string + required: true + immutable: true + default: ixVolume + enum: + - value: hostPath + description: Host Path (Path that already exists on the system) + - value: ixVolume + description: ixVolume (Dataset created automatically by the system) + - variable: ixVolumeConfig + label: ixVolume Configuration + description: The configuration for the ixVolume dataset. + schema: + type: dict + # Nothing to show for the user + hidden: true + show_if: [["type", "=", "ixVolume"]] + $ref: + - "normalize/ixVolume" + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + # Postgres does a CHMOD at startup + # Which fails with ACL + hidden: true + default: false + - variable: datasetName + label: Dataset Name + description: The name of the dataset to use for storage. + schema: + type: string + required: true + immutable: true + hidden: true + default: "pgBackup" + - variable: aclEntries + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + - variable: hostPathConfig + label: Host Path Configuration + schema: + type: dict + show_if: [["type", "=", "hostPath"]] + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + # Postgres does a CHMOD at startup + # Which fails with ACL + hidden: true + default: false + - variable: acl + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + $ref: + - "normalize/acl" + - variable: hostPath + label: Host Path + description: The host path to use for storage. + schema: + type: hostpath + show_if: [["aclEnable", "=", false]] + required: true + + - variable: additionalStorages + label: Additional Storage + description: Additional storage for Home Assistant. + schema: + type: list + default: [] + items: + - variable: storageEntry + label: Storage Entry + schema: + type: dict + attrs: + - variable: type + label: Type + description: | + ixVolume: Is dataset created automatically by the system.
+ Host Path: Is a path that already exists on the system.
+ SMB Share: Is a SMB share that is mounted to a persistent volume claim. + schema: + type: string + required: true + default: "ixVolume" + immutable: true + enum: + - value: "hostPath" + description: Host Path (Path that already exists on the system) + - value: "ixVolume" + description: ixVolume (Dataset created automatically by the system) + - value: "smb-pv-pvc" + description: SMB Share (Mounts a persistent volume claim to a SMB share) + - variable: readOnly + label: Read Only + description: Mount the volume as read only. + schema: + type: boolean + default: false + - variable: mountPath + label: Mount Path + description: The path inside the container to mount the storage. + schema: + type: path + required: true + - variable: hostPathConfig + label: Host Path Configuration + schema: + type: dict + show_if: [["type", "=", "hostPath"]] + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + default: false + - variable: acl + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + $ref: + - "normalize/acl" + - variable: hostPath + label: Host Path + description: The host path to use for storage. + schema: + type: hostpath + show_if: [["aclEnable", "=", false]] + required: true + - variable: ixVolumeConfig + label: ixVolume Configuration + description: The configuration for the ixVolume dataset. + schema: + type: dict + show_if: [["type", "=", "ixVolume"]] + $ref: + - "normalize/ixVolume" + attrs: + - variable: aclEnable + label: Enable ACL + description: Enable ACL for the dataset. + schema: + type: boolean + default: false + - variable: datasetName + label: Dataset Name + description: The name of the dataset to use for storage. + schema: + type: string + required: true + immutable: true + default: "storage_entry" + - variable: aclEntries + label: ACL Configuration + schema: + type: dict + show_if: [["aclEnable", "=", true]] + attrs: [] + - variable: smbConfig + label: SMB Share Configuration + description: The configuration for the SMB Share. + schema: + type: dict + show_if: [["type", "=", "smb-pv-pvc"]] + attrs: + - variable: server + label: Server + description: The server for the SMB share. + schema: + type: string + required: true + - variable: share + label: Share + description: The share name for the SMB share. + schema: + type: string + required: true + - variable: domain + label: Domain (Optional) + description: The domain for the SMB share. + schema: + type: string + - variable: username + label: Username + description: The username for the SMB share. + schema: + type: string + required: true + - variable: password + label: Password + description: The password for the SMB share. + schema: + type: string + required: true + private: true + - variable: size + label: Size (in Gi) + description: The size of the volume quota. + schema: + type: int + required: true + min: 1 + default: 1 + + - variable: resources + group: Resources Configuration + label: "" + schema: + type: dict + attrs: + - variable: limits + label: Limits + schema: + type: dict + attrs: + - variable: cpu + label: CPU + description: CPU limit for WG-Easy. + schema: + type: string + max_length: 6 + valid_chars: '^(0\.[1-9]|[1-9][0-9]*)(\.[0-9]|m?)$' + valid_chars_error: | + Valid CPU limit formats are
+ - Plain Integer - eg. 1
+ - Float - eg. 0.5
+ - Milicpu - eg. 500m + default: "4000m" + required: true + - variable: memory + label: Memory + description: Memory limit for WG-Easy. + schema: + type: string + max_length: 12 + valid_chars: '^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$' + valid_chars_error: | + Valid Memory limit formats are
+ - Suffixed with E/P/T/G/M/K - eg. 1G
+ - Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi
+ - Plain Integer in bytes - eg. 1024
+ - Exponent - eg. 134e6 + default: "8Gi" + required: true diff --git a/charts/home-assistant/2.0.0/templates/_configuration.tpl b/charts/home-assistant/2.0.0/templates/_configuration.tpl new file mode 100644 index 0000000000..1c7e97d784 --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_configuration.tpl @@ -0,0 +1,85 @@ +{{- define "home-assistant.configuration" -}} + + {{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}} + + {{- $dbHost := (printf "%s-postgres" $fullname) -}} + {{- $dbUser := "home-assistant" -}} + {{- $dbName := "home-assistant" -}} + {{- $dbPass := (randAlphaNum 32) -}} + + {{/* Fetch secrets from pre-migration secret */}} + {{- with (lookup "v1" "Secret" .Release.Namespace "db-details") -}} + {{- $dbUser = ((index .data "db-user") | b64dec) -}} + {{- $dbPass = ((index .data "db-password") | b64dec) -}} + {{/* Previous installs had a typo */}} + {{- $dbName = "homeassistance" -}} + {{- end -}} + + {{- with (lookup "v1" "Secret" .Release.Namespace (printf "%s-postgres-creds" $fullname)) -}} + {{- $dbUser = ((index .data "POSTGRES_USER") | b64dec) -}} + {{- $dbPass = ((index .data "POSTGRES_PASSWORD") | b64dec) -}} + {{- $dbName = ((index .data "POSTGRES_DB") | b64dec) -}} + {{- end -}} + + {{/* Temporary set dynamic db details on values, + so we can print them on the notes */}} + {{- $_ := set .Values "haDbPass" $dbPass -}} + {{- $_ := set .Values "haDbHost" $dbHost -}} + {{- $_ := set .Values "haDbName" $dbName -}} + {{- $_ := set .Values "haDbUser" $dbUser -}} + + {{- $dbURL := (printf "postgres://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) -}} + {{- $haDBURL := (printf "postgresql://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) }} +secret: + postgres-creds: + enabled: true + data: + POSTGRES_USER: {{ $dbUser }} + POSTGRES_DB: {{ $dbName }} + POSTGRES_PASSWORD: {{ $dbPass }} + POSTGRES_HOST: {{ $dbHost }} + POSTGRES_URL: {{ $dbURL }} + {{- if eq (include "home-assistant.is-migration" $) "true" }} + postgres-backup-creds: + enabled: true + annotations: + helm.sh/hook: "pre-upgrade" + helm.sh/hook-delete-policy: "hook-succeeded" + helm.sh/hook-weight: "1" + data: + POSTGRES_USER: {{ $dbUser }} + POSTGRES_DB: {{ $dbName }} + POSTGRES_PASSWORD: {{ $dbPass }} + POSTGRES_HOST: {{ $dbHost }}-ha + POSTGRES_URL: {{ printf "postgres://%s:%s@%s-ha:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName }} + {{- end }} + ha-config: + enabled: true + data: + configuration.default: | + # Configure a default setup of Home Assistant (frontend, api, etc) + default_config: + # Text to speech + tts: + - platform: google_translate + recorder.default: | + recorder: + purge_keep_days: 30 + commit_interval: 3 + db_url: {{ $haDBURL }} + script.sh: | + #!/bin/sh + config="/config/configuration.yaml" + default="/default/init" + if [ ! -f "$config" ]; then + echo "File [$config] does NOT exist. Creating..." + cp "$default/configuration.default" "$config" + fi + if ! grep -q "recorder:" "$config"; then + echo "Section [recorder] does NOT exist in [$config]. Appending..." + cat "$default/recorder.default" >> "$config" + fi + echo "Ensure DB URL is up to date" + yq -i '.recorder.db_url = "{{ $haDBURL }}"' "$config" + echo "Done" +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/_home-assistant.tpl b/charts/home-assistant/2.0.0/templates/_home-assistant.tpl new file mode 100644 index 0000000000..3b5b583ed6 --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_home-assistant.tpl @@ -0,0 +1,63 @@ +{{- define "home-assistant.workload" -}} +workload: + home-assistant: + enabled: true + primary: true + type: Deployment + podSpec: + hostNetwork: {{ .Values.haNetwork.hostNetwork }} + securityContext: + fsGroup: {{ .Values.haID.group }} + containers: + home-assistant: + enabled: true + primary: true + imageSelector: image + securityContext: + runAsUser: 0 + runAsGroup: 0 + runAsNonRoot: false + readOnlyRootFilesystem: false + capabilities: + add: + - NET_BIND_SERVICE + - NET_RAW + fixedEnv: + PUID: {{ .Values.haID.user }} + {{ with .Values.haConfig.additionalEnvs }} + envList: + {{ range $env := . }} + - name: {{ $env.name }} + value: {{ $env.value }} + {{ end }} + {{ end }} + probes: + liveness: + enabled: true + type: http + path: /manifest.json + port: 8123 + readiness: + enabled: true + type: http + path: /manifest.json + port: 8123 + startup: + enabled: true + type: http + path: /manifest.json + port: 8123 + initContainers: + 01-init-config: + enabled: true + type: init + imageSelector: yqImage + securityContext: + runAsUser: 0 + runAsGroup: 0 + runAsNonRoot: false + readOnlyRootFilesystem: false + command: /default/init/script.sh + {{- include "ix.v1.common.app.postgresWait" (dict "name" "postgres-wait" + "secretName" "postgres-creds") | nindent 8 }} +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/_migration.tpl b/charts/home-assistant/2.0.0/templates/_migration.tpl new file mode 100644 index 0000000000..2fe0d8f0f4 --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_migration.tpl @@ -0,0 +1,48 @@ +{{- define "home-assistant.get-versions" -}} + {{- $oldChartVersion := "" -}} + {{- $newChartVersion := "" -}} + + {{/* Safely access the context, so it wont block CI */}} + {{- if hasKey .Values.global "ixChartContext" -}} + {{- if .Values.global.ixChartContext.upgradeMetadata -}} + + {{- $oldChartVersion = .Values.global.ixChartContext.upgradeMetadata.oldChartVersion -}} + {{- $newChartVersion = .Values.global.ixChartContext.upgradeMetadata.newChartVersion -}} + {{- if and (not $oldChartVersion) (not $newChartVersion) -}} + {{- fail "Upgrade Metadata is missing. Cannot proceed" -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{- toYaml (dict "old" $oldChartVersion "new" $newChartVersion) -}} +{{- end -}} + +{{- define "home-assistant.migration" -}} + {{- $versions := (fromYaml (include "home-assistant.get-versions" $)) -}} + {{- if and $versions.old $versions.new -}} + {{- $oldV := semver $versions.old -}} + {{- $newV := semver $versions.new -}} + + {{/* If new is v2.x.x */}} + {{- if eq ($newV.Major | int) 2 -}} + {{/* And old is v1.x.x, but lower than .130 */}} + {{- if and (eq $oldV.Major 1) (lt ($oldV.Patch | int) 130) -}} + {{/* Block the upgrade */}} + {{- fail "Migration to 2.x.x is only allowed from 1.0.130 or higher" -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{- define "home-assistant.is-migration" -}} + {{- $isMigration := "" -}} + {{- $versions := (fromYaml (include "home-assistant.get-versions" $)) -}} + {{- if $versions.old -}} + {{- $oldV := semver $versions.old -}} + {{- if and (eq $oldV.Major 1) (eq ($oldV.Patch | int) 130) -}} + {{- $isMigration = "true" -}} + {{- end -}} + {{- end -}} + + {{- $isMigration -}} +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/_persistance.tpl b/charts/home-assistant/2.0.0/templates/_persistance.tpl new file mode 100644 index 0000000000..2ad49df7d7 --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_persistance.tpl @@ -0,0 +1,56 @@ +{{- define "home-assistant.persistence" -}} +persistence: + config: + enabled: true + {{- include "ix.v1.common.app.storageOptions" (dict "storage" .Values.haStorage.config) | nindent 4 }} + targetSelector: + home-assistant: + home-assistant: + mountPath: /config + 01-init-config: + mountPath: /config + media: + enabled: true + {{- include "ix.v1.common.app.storageOptions" (dict "storage" .Values.haStorage.media) | nindent 4 }} + targetSelector: + home-assistant: + home-assistant: + mountPath: /media + default-config: + enabled: true + type: secret + objectName: ha-config + defaultMode: "0744" + items: + - key: configuration.default + path: configuration.default + - key: recorder.default + path: recorder.default + - key: script.sh + path: script.sh + targetSelector: + home-assistant: + 01-init-config: + mountPath: /default/init + tmp: + enabled: true + type: emptyDir + targetSelector: + home-assistant: + home-assistant: + mountPath: /tmp + {{- range $idx, $storage := .Values.haStorage.additionalStorages }} + {{ printf "ha-%v:" (int $idx) }} + enabled: true + {{- include "ix.v1.common.app.storageOptions" (dict "storage" $storage) | nindent 4 }} + targetSelector: + home-assistant: + home-assistant: + mountPath: {{ $storage.mountPath }} + {{- end }} + + {{- include "ix.v1.common.app.postgresPersistence" + (dict "pgData" .Values.haStorage.pgData + "pgBackup" .Values.haStorage.pgBackup + ) | nindent 2 }} +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/_portal.tpl b/charts/home-assistant/2.0.0/templates/_portal.tpl new file mode 100644 index 0000000000..0a5eef5182 --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_portal.tpl @@ -0,0 +1,12 @@ +{{- define "home-assistant.portal" -}} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: portal +data: + port: {{ .Values.haNetwork.webPort | quote }} + path: "/" + protocol: "http" + host: $node_ip +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/_postgres.tpl b/charts/home-assistant/2.0.0/templates/_postgres.tpl new file mode 100644 index 0000000000..f72ff4ebec --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_postgres.tpl @@ -0,0 +1,12 @@ +{{- define "postgres.workload" -}} + {{- $backupSecretName := "postgres-creds" -}} + {{- if eq (include "home-assistant.is-migration" $) "true" }} + {{- $backupSecretName = "postgres-backup-creds" -}} + {{- end }} +workload: +{{- include "ix.v1.common.app.postgres" (dict "secretName" "postgres-creds" + "backupSecretName" $backupSecretName + "resources" .Values.resources + "imageSelector" "haPostgresImage" + "ixChartContext" .Values.ixChartContext) | nindent 2 }} +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/_service.tpl b/charts/home-assistant/2.0.0/templates/_service.tpl new file mode 100644 index 0000000000..4506dcddb0 --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/_service.tpl @@ -0,0 +1,17 @@ +{{- define "home-assistant.service" -}} +service: + home-assistant: + enabled: true + primary: true + type: NodePort + targetSelector: home-assistant + ports: + webui: + enabled: true + primary: true + port: {{ .Values.haNetwork.webPort }} + nodePort: {{ .Values.haNetwork.webPort }} + targetPort: 8123 + targetSelector: home-assistant + {{- include "ix.v1.common.app.postgresService" $ | nindent 2 }} +{{- end -}} diff --git a/charts/home-assistant/2.0.0/templates/common.yaml b/charts/home-assistant/2.0.0/templates/common.yaml new file mode 100644 index 0000000000..506148fb9f --- /dev/null +++ b/charts/home-assistant/2.0.0/templates/common.yaml @@ -0,0 +1,19 @@ +{{- include "ix.v1.common.loader.init" . -}} + +{{- include "home-assistant.migration" $ -}} + +{{/* Merge the templates with Values */}} +{{- $_ := mustMergeOverwrite .Values (include "home-assistant.workload" $ | fromYaml) -}} +{{- $_ := mustMergeOverwrite .Values (include "home-assistant.service" $ | fromYaml) -}} +{{- $_ := mustMergeOverwrite .Values (include "home-assistant.persistence" $ | fromYaml) -}} +{{- $_ := mustMergeOverwrite .Values (include "home-assistant.configuration" $ | fromYaml) -}} +{{- $_ := mustMergeOverwrite .Values (include "postgres.workload" $ | fromYaml) -}} + +{{- if eq (include "home-assistant.is-migration" $) "true" }} + {{- $_ := set .Values.workload.postgres.podSpec.initContainers.permissions "type" "init" -}} +{{- end }} + +{{/* Create the configmap for portal manually*/}} +{{- include "home-assistant.portal" $ -}} + +{{- include "ix.v1.common.loader.apply" . -}} diff --git a/charts/home-assistant/2.0.0/to_keep_versions.md b/charts/home-assistant/2.0.0/to_keep_versions.md new file mode 100644 index 0000000000..7572c06f63 --- /dev/null +++ b/charts/home-assistant/2.0.0/to_keep_versions.md @@ -0,0 +1,4 @@ +# 1.0.130 + +This version is kept because it contains a fix that is needed for migration to v2.x.x +It should be safe to remove few months after v2.x.x is released.