_configuration.tpl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. {{- define "home-assistant.configuration" -}}
  2. {{- $fullname := (include "ix.v1.common.lib.chart.names.fullname" $) -}}
  3. {{- $dbHost := (printf "%s-postgres" $fullname) -}}
  4. {{- $dbUser := "home-assistant" -}}
  5. {{- $dbName := "home-assistant" -}}
  6. {{- $dbPass := (randAlphaNum 32) -}}
  7. {{/* Fetch secrets from pre-migration secret */}}
  8. {{- with (lookup "v1" "Secret" .Release.Namespace "db-details") -}}
  9. {{- $dbUser = ((index .data "db-user") | b64dec) -}}
  10. {{- $dbPass = ((index .data "db-password") | b64dec) -}}
  11. {{/* Previous installs had a typo */}}
  12. {{- $dbName = "homeassistance" -}}
  13. {{- end -}}
  14. {{- with (lookup "v1" "Secret" .Release.Namespace (printf "%s-postgres-creds" $fullname)) -}}
  15. {{- $dbUser = ((index .data "POSTGRES_USER") | b64dec) -}}
  16. {{- $dbPass = ((index .data "POSTGRES_PASSWORD") | b64dec) -}}
  17. {{- $dbName = ((index .data "POSTGRES_DB") | b64dec) -}}
  18. {{- end -}}
  19. {{/* Temporary set dynamic db details on values,
  20. so we can print them on the notes */}}
  21. {{- $_ := set .Values "haDbPass" $dbPass -}}
  22. {{- $_ := set .Values "haDbHost" $dbHost -}}
  23. {{- $_ := set .Values "haDbName" $dbName -}}
  24. {{- $_ := set .Values "haDbUser" $dbUser -}}
  25. {{- $dbURL := (printf "postgres://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) -}}
  26. {{- $haDBURL := (printf "postgresql://%s:%s@%s:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName) }}
  27. secret:
  28. postgres-creds:
  29. enabled: true
  30. data:
  31. POSTGRES_USER: {{ $dbUser }}
  32. POSTGRES_DB: {{ $dbName }}
  33. POSTGRES_PASSWORD: {{ $dbPass }}
  34. POSTGRES_HOST: {{ $dbHost }}
  35. POSTGRES_URL: {{ $dbURL }}
  36. {{- if eq (include "home-assistant.is-migration" $) "true" }}
  37. postgres-backup-creds:
  38. enabled: true
  39. annotations:
  40. helm.sh/hook: "pre-upgrade"
  41. helm.sh/hook-delete-policy: "hook-succeeded"
  42. helm.sh/hook-weight: "1"
  43. data:
  44. POSTGRES_USER: {{ $dbUser }}
  45. POSTGRES_DB: {{ $dbName }}
  46. POSTGRES_PASSWORD: {{ $dbPass }}
  47. POSTGRES_HOST: {{ $dbHost }}-ha
  48. POSTGRES_URL: {{ printf "postgres://%s:%s@%s-ha:5432/%s?sslmode=disable" $dbUser $dbPass $dbHost $dbName }}
  49. {{- end }}
  50. ha-config:
  51. enabled: true
  52. data:
  53. configuration.default: |
  54. # Configure a default setup of Home Assistant (frontend, api, etc)
  55. default_config:
  56. # Text to speech
  57. tts:
  58. - platform: google_translate
  59. recorder.default: |
  60. recorder:
  61. purge_keep_days: 30
  62. commit_interval: 3
  63. db_url: {{ $haDBURL }}
  64. script.sh: |
  65. #!/bin/sh
  66. config="/config/configuration.yaml"
  67. default="/default/init"
  68. # Attemp to get read/write access
  69. chmod +rw "$config" || echo "Failed to set permissions on [$config]"
  70. if [ ! -f "$config" ]; then
  71. echo "File [$config] does NOT exist. Creating..."
  72. cp "$default/configuration.default" "$config"
  73. fi
  74. if ! grep -q "recorder:" "$config"; then
  75. echo "Section [recorder] does NOT exist in [$config]. Appending..."
  76. cat "$default/recorder.default" >> "$config"
  77. fi
  78. echo "Ensure DB URL is up to date"
  79. yq -i '.recorder.db_url = "{{ $haDBURL }}"' "$config"
  80. echo "Done"
  81. {{- end -}}