Publish new changes in catalog

This commit is contained in:
sonicaj
2024-01-22 11:20:57 +00:00
parent 10138ab528
commit cdd53e89eb
20 changed files with 1181 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# Patterns to ignore when building packages.
*.png

View File

@@ -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"

View File

@@ -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

View File

@@ -0,0 +1,3 @@
# Introduction
home assistant App for TrueNAS SCALE

View File

@@ -0,0 +1 @@
home-assistant App for TrueNAS SCALE

Binary file not shown.

View File

@@ -0,0 +1,15 @@
haNetwork:
webPort: 31000
haStorage:
config:
type: pvc
media:
type: pvc
pgData:
type: pvc
pgBackup:
type: emptyDir
emptyDirConfig:
medium: ""
size: ""

View File

@@ -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
<details>
<summary>Database Details</summary>
- Database: `{{ .Values.haDbName }}`
- Username: `{{ .Values.haDbUser }}`
- Password: `{{ .Values.haDbPass }}`
- Host: `{{ .Values.haDbHost }}.{{ .Release.Namespace }}.svc.cluster.local`
- Port: `5432`
</details>
{{- $_ := unset .Values "haDbUser" }}
{{- $_ := unset .Values "haDbName" }}
{{- $_ := unset .Values "haDbPass" }}
{{- $_ := unset .Values "haDbHost" }}

View File

@@ -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: []

View File

@@ -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()))))

View File

@@ -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.</br>
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.</br>
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.</br>
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.</br>
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.</br>
Host Path: Is a path that already exists on the system.</br>
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</br>
- Plain Integer - eg. 1</br>
- Float - eg. 0.5</br>
- 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</br>
- Suffixed with E/P/T/G/M/K - eg. 1G</br>
- Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi</br>
- Plain Integer in bytes - eg. 1024</br>
- Exponent - eg. 134e6
default: "8Gi"
required: true

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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" . -}}

View File

@@ -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.