diff --git a/library/ix-dev/charts/home-assistant/Chart.lock b/library/ix-dev/charts/home-assistant/Chart.lock index eac01eafc6..54416569a7 100644 --- a/library/ix-dev/charts/home-assistant/Chart.lock +++ b/library/ix-dev/charts/home-assistant/Chart.lock @@ -1,6 +1,6 @@ dependencies: - name: common - repository: file://../../../common/2304.0.1 - version: 2304.0.1 -digest: sha256:1ed155c6760e1166e2cb75b52bc5e81c6bdf0252c16ff5ede001157077c41670 -generated: "2023-04-24T13:39:38.938872433+03:00" + repository: file://../../../common + version: 1.2.9 +digest: sha256:af1a9a1f87e3e48453c9f25f909f5ebcd7fa6e25162b7b425448ba752bcdbc5c +generated: "2024-01-19T14:50:50.732430258+02:00" diff --git a/library/ix-dev/charts/home-assistant/Chart.yaml b/library/ix-dev/charts/home-assistant/Chart.yaml index 206d27b540..e0aece608b 100644 --- a/library/ix-dev/charts/home-assistant/Chart.yaml +++ b/library/ix-dev/charts/home-assistant/Chart.yaml @@ -3,7 +3,7 @@ description: Home Assistant App for TrueNAS SCALE annotations: title: Home Assistant type: application -version: 1.0.130 +version: 2.0.0 apiVersion: v2 appVersion: 2024.1.3 kubeVersion: '>=1.16.0-0' @@ -13,8 +13,8 @@ maintainers: email: dev@ixsystems.com dependencies: - name: common - repository: file://../../../common/2304.0.1 - version: 2304.0.1 + 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: diff --git a/library/ix-dev/charts/home-assistant/charts/common-1.2.9.tgz b/library/ix-dev/charts/home-assistant/charts/common-1.2.9.tgz new file mode 100644 index 0000000000..4b09cad699 Binary files /dev/null and b/library/ix-dev/charts/home-assistant/charts/common-1.2.9.tgz differ diff --git a/library/ix-dev/charts/home-assistant/charts/common-2304.0.1.tgz b/library/ix-dev/charts/home-assistant/charts/common-2304.0.1.tgz deleted file mode 100644 index 59275459fa..0000000000 Binary files a/library/ix-dev/charts/home-assistant/charts/common-2304.0.1.tgz and /dev/null differ diff --git a/library/ix-dev/charts/home-assistant/ci/basic-values.yaml b/library/ix-dev/charts/home-assistant/ci/basic-values.yaml new file mode 100644 index 0000000000..cdb0941383 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/ci/test-values.yaml b/library/ix-dev/charts/home-assistant/ci/test-values.yaml deleted file mode 100644 index daaca32669..0000000000 --- a/library/ix-dev/charts/home-assistant/ci/test-values.yaml +++ /dev/null @@ -1,32 +0,0 @@ -appVolumeMounts: - config: - emptyDir: true - mountPath: /config - media: - emptyDir: true - mountPath: /media -dnsConfig: - options: [] -emptyDirVolumes: true -environmentVariables: [] -extraAppVolumeMounts: [] -hostNetwork: false -ixChartContext: {} -ownerGID: 568 -ownerUID: 568 -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 -timezone: America/Los_Angeles -web_port: 32000 diff --git a/library/ix-dev/charts/home-assistant/metadata.yaml b/library/ix-dev/charts/home-assistant/metadata.yaml index 6bc89067db..61486a5797 100644 --- a/library/ix-dev/charts/home-assistant/metadata.yaml +++ b/library/ix-dev/charts/home-assistant/metadata.yaml @@ -4,38 +4,14 @@ runAsContext: gid: 0 uid: 0 description: Home-Assistant runs as root user. - - userName: root - groupName: root - gid: 0 - uid: 0 - description: Postgres runs as root user. + - userName: postgres + groupName: postgres + gid: 999 + uid: 999 + description: Postgres runs as a non-root user. capabilities: - - name: CHOWN - description: Home Assistant and Postgres are able to chown files. - - name: FOWNER - description: Home Assistant and Postgres are able to bypass permission checks for it's sub-processes. - - name: SYS_CHROOT - description: Home Assistant and Postgres are able to use chroot. - - name: MKNOD - description: Home Assistant and Postgres are able to create device nodes. - - name: DAC_OVERRIDE - description: Home Assistant and Postgres are able to bypass permission checks. - - name: FSETID - description: Home Assistant and Postgres are able to set file capabilities. - - name: KILL - description: Home Assistant and Postgres are able to kill processes. - - name: SETGID - description: Home Assistant and Postgres are able to set group ID for it's sub-processes. - - name: SETUID - description: Home Assistant and Postgres are able to set user ID for it's sub-processes. - - name: SETPCAP - description: Home Assistant and Postgres are able to set process capabilities. - name: NET_BIND_SERVICE - description: Home Assistant and Postgres are able to bind to privileged ports. - - name: SETFCAP - description: Home Assistant and Postgres are able to set file capabilities. + description: Home Assistant is able to bind to privileged ports. - name: NET_RAW - description: Home Assistant and Postgres are able to use raw sockets. - - name: AUDIT_WRITE - description: Home Assistant and Postgres are able to write to audit log. + description: Home Assistant is able to use raw sockets. hostMounts: [] diff --git a/library/ix-dev/charts/home-assistant/migrations/migrate b/library/ix-dev/charts/home-assistant/migrations/migrate new file mode 100755 index 0000000000..b38d51c4e5 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/questions.yaml b/library/ix-dev/charts/home-assistant/questions.yaml index feb5225536..dc122cdb0e 100644 --- a/library/ix-dev/charts/home-assistant/questions.yaml +++ b/library/ix-dev/charts/home-assistant/questions.yaml @@ -1,292 +1,633 @@ 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" - - name: "Resource Limits" - description: "Set CPU/memory limits for Kubernetes Pod" + - 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: - - "http" + - "$kubernetes-resource_configmap_portal_protocol" host: - - "$node_ip" + - "$kubernetes-resource_configmap_portal_host" ports: - - "$variable-web_port" - path: "/" + - "$kubernetes-resource_configmap_portal_port" + path: "$kubernetes-resource_configmap_portal_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" + - variable: TZ + group: Home Assistant Configuration + label: Timezone schema: type: string + default: Etc/UTC + required: true $ref: - - "definitions/timezone" + - definitions/timezone - - variable: hostNetwork - label: "Enable Host Network" - group: "Networking" - schema: - type: boolean - default: false - - - variable: dnsConfig - label: "DNS Configuration" - group: "Advanced DNS Settings" + - variable: podOptions + label: "" + group: Advanced Pod Configuration 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" + - variable: dnsConfig + label: Advanced DNS Configuration schema: type: dict attrs: - - variable: name - label: "Name" + - variable: options + label: DNS Options schema: - type: string - - variable: value - label: "Value" - schema: - type: string + 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: appVolumeMounts - label: "Home Assistant Storage" - group: "Storage" + - 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: "Storage Volume for Configuration" + label: Home Assistant Configuration Storage + description: The path to store Home Assistant Configuration. schema: type: dict attrs: - - variable: datasetName - label: "Configuration Storage Volume Dataset Name" + - 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 - hidden: true + 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" - 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" + 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: 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: + 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 for Home Assistant Configuration Storage Volume" + label: Host Path + description: The host path to use for storage. schema: type: hostpath + show_if: [["aclEnable", "=", false]] required: true + - variable: media - label: "Storage Volume for Media" + label: Home Assistant Media Storage + description: The path to store Home Assistant Media. schema: type: dict attrs: - - variable: datasetName - label: "Media Storage Volume Dataset Name" + - 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 - hidden: true + 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" - 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" + 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: 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: + 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 for Home Assistant Media Storage Volume" + 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: postgresAppVolumeMounts - label: "Postgres Storage" - group: "Storage" + - 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 - hidden: true attrs: - - variable: postgres-data - label: "Postgres Data Volume" + - variable: limits + label: Limits schema: type: dict attrs: - - variable: datasetName - label: "Postgres Data Volume Name" + - variable: cpu + label: CPU + description: CPU limit for WG-Easy. 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" + 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 - $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 + 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 - - variable: hostPath - label: "Host Path" - description: "Host path" - schema: - type: hostpath - required: true - - - variable: enableResourceLimits - label: "Enable Pod resource limits" - group: "Resource Limits" - schema: - type: boolean - default: false - - variable: cpuLimit - label: "CPU Limit" - description: "CPU resource limit allow plain integer values with suffix m(milli) e.g 1000m, 100." - group: "Resource Limits" - schema: - type: string - show_if: [["enableResourceLimits", "=", true]] - valid_chars: "^\\d+(?:\\.\\d+(?!.*m$)|m?$)" - default: "4000m" - - variable: memLimit - label: "Memory Limit" - group: "Resource Limits" - description: "Memory limits is specified by number of bytes. Followed by quantity suffix like E,P,T,G,M,k and Ei,Pi,Ti,Mi,Gi,Ki can also be used. e.g 129e6, 129M, 128974848000m, 123Mi" - schema: - type: string - show_if: [["enableResourceLimits", "=", true]] - valid_chars: "^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$" - default: "8Gi" diff --git a/library/ix-dev/charts/home-assistant/templates/_configuration.tpl b/library/ix-dev/charts/home-assistant/templates/_configuration.tpl new file mode 100644 index 0000000000..1c7e97d784 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/_home-assistant.tpl b/library/ix-dev/charts/home-assistant/templates/_home-assistant.tpl new file mode 100644 index 0000000000..3b5b583ed6 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/_migration.tpl b/library/ix-dev/charts/home-assistant/templates/_migration.tpl new file mode 100644 index 0000000000..2fe0d8f0f4 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/_persistance.tpl b/library/ix-dev/charts/home-assistant/templates/_persistance.tpl new file mode 100644 index 0000000000..2ad49df7d7 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/_portal.tpl b/library/ix-dev/charts/home-assistant/templates/_portal.tpl new file mode 100644 index 0000000000..0a5eef5182 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/_postgres.tpl b/library/ix-dev/charts/home-assistant/templates/_postgres.tpl index dcb7404691..f72ff4ebec 100644 --- a/library/ix-dev/charts/home-assistant/templates/_postgres.tpl +++ b/library/ix-dev/charts/home-assistant/templates/_postgres.tpl @@ -1,49 +1,12 @@ -{{/* -Get Home assistance Postgres Database Name -*/}} -{{- define "postgres.DatabaseName" -}} -{{- print "homeassistance" -}} +{{- 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 -}} - - -{{- 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/library/ix-dev/charts/home-assistant/templates/_service.tpl b/library/ix-dev/charts/home-assistant/templates/_service.tpl new file mode 100644 index 0000000000..4506dcddb0 --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/backup-postgres-config.yaml b/library/ix-dev/charts/home-assistant/templates/backup-postgres-config.yaml deleted file mode 100644 index c9ccf66dba..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/backup-postgres-config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -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/library/ix-dev/charts/home-assistant/templates/common.yaml b/library/ix-dev/charts/home-assistant/templates/common.yaml new file mode 100644 index 0000000000..506148fb9f --- /dev/null +++ b/library/ix-dev/charts/home-assistant/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/library/ix-dev/charts/home-assistant/templates/deployment.yaml b/library/ix-dev/charts/home-assistant/templates/deployment.yaml deleted file mode 100644 index fac5d0cc73..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/deployment.yaml +++ /dev/null @@ -1,120 +0,0 @@ -{{ include "common.storage.hostPathValidate" .Values }} -{{ $postgres_values := (. | mustDeepCopy) }} -{{ $_ := set $postgres_values "common" (dict "nameSuffix" "postgres") }} - -apiVersion: {{ template "common.capabilities.deployment.apiVersion" . }} -kind: Deployment -metadata: - name: {{ template "common.names.fullname" . }}-ha - 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: - {{ if .Values.hostNetwork }} - hostNetwork: true - dnsPolicy: ClusterFirstWithHostNet - {{ else }} - hostNetwork: false - dnsPolicy: ClusterFirst - {{ end }} - initContainers: - - name: init-postgresdb - image: {{ template "postgres.imageName" . }} - command: ['sh', '-c', "until pg_isready -h {{ template "common.names.fullname" $postgres_values }}-ha; 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-ha: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.resources.limitation" . | nindent 10 }} - {{ 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 - {{- if not .Values.hostNetwork }} - hostPort: null - {{- end }} - readinessProbe: - tcpSocket: - port: 8123 - initialDelaySeconds: 10 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 5 - successThreshold: 2 - livenessProbe: - tcpSocket: - port: 8123 - initialDelaySeconds: 10 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 5 - successThreshold: 1 - startupProbe: - tcpSocket: - port: 8123 - initialDelaySeconds: 10 - periodSeconds: 5 - timeoutSeconds: 2 - failureThreshold: 60 - successThreshold: 1 - 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/library/ix-dev/charts/home-assistant/templates/home-assistance-init-config.yaml b/library/ix-dev/charts/home-assistant/templates/home-assistance-init-config.yaml deleted file mode 100644 index 5a4c03183a..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/home-assistance-init-config.yaml +++ /dev/null @@ -1,40 +0,0 @@ -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/library/ix-dev/charts/home-assistant/templates/postgres-config.yaml b/library/ix-dev/charts/home-assistant/templates/postgres-config.yaml deleted file mode 100644 index 8a0c284c51..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/postgres-config.yaml +++ /dev/null @@ -1,8 +0,0 @@ -{{ $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/library/ix-dev/charts/home-assistant/templates/postgres-deployment.yaml b/library/ix-dev/charts/home-assistant/templates/postgres-deployment.yaml deleted file mode 100644 index c369bf86dd..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/postgres-deployment.yaml +++ /dev/null @@ -1,56 +0,0 @@ -{{ $values := (. | mustDeepCopy) }} -{{ $_ := set $values "common" (dict "nameSuffix" "postgres-ha") }} -{{ 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 - readinessProbe: - exec: - command: - - sh - - -c - - "until pg_isready -U ${POSTGRES_USER} -h localhost; do sleep 2; done" - initialDelaySeconds: 10 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 5 - successThreshold: 2 - livenessProbe: - exec: - command: - - sh - - -c - - "until pg_isready -U ${POSTGRES_USER} -h localhost; do sleep 2; done" - initialDelaySeconds: 10 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 5 - successThreshold: 1 - startupProbe: - exec: - command: - - sh - - -c - - "until pg_isready -U ${POSTGRES_USER} -h localhost; do sleep 2; done" - initialDelaySeconds: 10 - periodSeconds: 5 - timeoutSeconds: 2 - failureThreshold: 60 - successThreshold: 1 - volumes: {{ include "postgres.volumeConfiguration" $values | nindent 8 }} diff --git a/library/ix-dev/charts/home-assistant/templates/postgres-secret.yaml b/library/ix-dev/charts/home-assistant/templates/postgres-secret.yaml deleted file mode 100644 index 0a93ebe57b..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/postgres-secret.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: db-details -data: - db-user: {{ "postgres" | b64enc }} - {{- with (lookup "v1" "Secret" .Release.Namespace "db-details") }} - db-password: {{ index .data "db-password" }} - {{ else }} - db-password: {{ randAlphaNum 15 | b64enc | quote }} - {{ end }} diff --git a/library/ix-dev/charts/home-assistant/templates/postgres-service.yaml b/library/ix-dev/charts/home-assistant/templates/postgres-service.yaml deleted file mode 100644 index 2a29b9cf1c..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/postgres-service.yaml +++ /dev/null @@ -1,6 +0,0 @@ -{{ $ports := list }} -{{ $ports = mustAppend $ports (dict "name" "postgres-tcp" "port" 5432 "targetPort" 5432) }} -{{ $values := (. | mustDeepCopy) }} -{{ $_ := set $values "common" (dict "nameSuffix" "postgres-ha") }} -{{ $_1 := set $values "commonService" (dict "type" "ClusterIP" "ports" $ports ) }} -{{ include "common.classes.service" $values }} diff --git a/library/ix-dev/charts/home-assistant/templates/pre-install-job.yaml b/library/ix-dev/charts/home-assistant/templates/pre-install-job.yaml deleted file mode 100644 index 2c4074efc9..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/pre-install-job.yaml +++ /dev/null @@ -1,33 +0,0 @@ -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/library/ix-dev/charts/home-assistant/templates/service.yaml b/library/ix-dev/charts/home-assistant/templates/service.yaml deleted file mode 100644 index 79b48458e5..0000000000 --- a/library/ix-dev/charts/home-assistant/templates/service.yaml +++ /dev/null @@ -1,10 +0,0 @@ -{{ $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/library/ix-dev/charts/home-assistant/values.yaml b/library/ix-dev/charts/home-assistant/values.yaml index 6805e3a049..beddd167b1 100644 --- a/library/ix-dev/charts/home-assistant/values.yaml +++ b/library/ix-dev/charts/home-assistant/values.yaml @@ -2,3 +2,69 @@ 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" }}