From d6932fe553e00e3f7e6d9962d1023d4ffbac6bec Mon Sep 17 00:00:00 2001 From: Vegetto Date: Sat, 4 Apr 2020 12:45:46 +0200 Subject: [PATCH] [stable/home-assistant] Add AppDaemon (#21587) * add support for additionalPorts and vseditor - support additionalPorts - vseditor changed logic for no passwords - support to enable access to editor when home assistant does not start Signed-off-by: Vegetto * [home-assistant] Add AppDaemon Leverages the support in HACS to download apps for AppDaemon. Signed-off-by: Vegetto * Fix enablement for appdaemon Signed-off-by: Vegetto * Add home-assistant config folder to appDaemon container Signed-off-by: Vegetto * increase version Signed-off-by: Vegetto --- stable/home-assistant/Chart.yaml | 2 +- stable/home-assistant/README.md | 25 ++++++++++ .../templates/appdaemon-ingress.yaml | 39 +++++++++++++++ .../home-assistant/templates/deployment.yaml | 46 ++++++++++++++++++ stable/home-assistant/templates/secret.yaml | 19 +++++++- stable/home-assistant/templates/service.yaml | 9 ++++ stable/home-assistant/values.yaml | 47 ++++++++++++++++++- 7 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 stable/home-assistant/templates/appdaemon-ingress.yaml diff --git a/stable/home-assistant/Chart.yaml b/stable/home-assistant/Chart.yaml index ee246397cc..6f31702046 100644 --- a/stable/home-assistant/Chart.yaml +++ b/stable/home-assistant/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: 0.107.7 description: Home Assistant name: home-assistant -version: 0.12.5 +version: 0.12.6 keywords: - home-assistant - hass diff --git a/stable/home-assistant/README.md b/stable/home-assistant/README.md index f650124547..7f06dc83a0 100644 --- a/stable/home-assistant/README.md +++ b/stable/home-assistant/README.md @@ -144,6 +144,27 @@ The following tables lists the configurable parameters of the Home Assistant cha | `vscode.service.externalIPs` | External IPs for the VS Code UI | `[]` | | `vscode.service.loadBalancerIP` | Loadbalancer IP for the VS Code UI | `` | | `vscode.service.loadBalancerSourceRanges` | Loadbalancer client IP restriction range for the VS Code UI | `[]` | +| `appdaemon.enabled` | Enable the optional [Appdaemon Sidecar](https://appdaemon.readthedocs.io/en/latest/) | `false` | +| `appdaemon.image.repository` | Image repository | `acockburn/appdaemon` | +| `appdaemon.image.tag` | Image tag | `3.0.5`| +| `appdaemon.image.pullPolicy` | Image pull policy | `IfNotPresent` | +| `appdaemon.haToken` | Home Assistant API token - you need to generate it in your Home Assistant profile and then copy here | `` | +| `appdaemon.extraEnv` | Extra ENV vars to pass to the AppDaemon container | `{}` | +| `appdaemon.ingress.enabled` | Enables Ingress for the AppDaemon UI | `false` | +| `appdaemon.ingress.annotations` | Ingress annotations for the AppDaemon UI | `{}` | +| `appdaemon.ingress.hosts` | Ingress accepted hostnames for the AppDaemonUI | `appdaemon.local` | +| `appdaemon.ingress.tls` | Ingress TLS configuration for the AppDaemon UI | `[]` | +| `appdaemon.resources` | CPU/Memory resource requests/limits for the AppDaemon | `{}` | +| `appdaemon.securityContext` | Security context to be added to hass-appdaemon container | `{}` | +| `appdaemon.service.type` | Kubernetes service type for the AppDaemon UI | `ClusterIP` | +| `appdaemon.service.port` | Kubernetes port where the AppDaemon UI is exposed| `5050` | +| `appdaemon.service.nodePort` | nodePort to listen on for the AppDaemon UI | `` | +| `appdaemon.service.annotations` | Service annotations for the AppDaemon UI | `{}` | +| `appdaemon.service.labels` | Service labels to use for the AppDaemon UI | `{}` | +| `appdaemon.service.clusterIP` | Cluster IP for the AppDaemon UI | `` | +| `appdaemon.service.externalIPs` | External IPs for the AppDaemon UI | `[]` | +| `appdaemon.service.loadBalancerIP` | Loadbalancer IP for the AppDaemon UI | `` | +| `appdaemon.service.loadBalancerSourceRanges` | Loadbalancer client IP restriction range for the VS Code UI | `[]` | | `resources` | CPU/Memory resource requests/limits or the home-assistant GUI | `{}` | | `nodeSelector` | Node labels for pod assignment or the home-assistant GUI | `{}` | | `tolerations` | Toleration labels for pod assignment or the home-assistant GUI | `[]` | @@ -190,6 +211,10 @@ Much of the home assistant configuration occurs inside the various files persist [VS Code Server](https://github.com/cdr/code-server) is added as an optional sidecar container to Home Assistant with access to the home assistant configuration for easy in-browser editing and manipulation of Home Assistant. If using this, it is possible to manually install the [Home Assistant Config Helper Extension](https://github.com/keesschollaart81/vscode-home-assistant) in order to have a deeper integration with Home Assistant within VS Code while editing the configuration files. +### AppDaemon +[AppDaemon](https://www.home-assistant.io/docs/ecosystem/appdaemon/) is added as an optional sidecar container to Home Assistant with access to the home assistant configuration `/config/appdaemon`. This allows downloading apps with [HACS](https://github.com/hacs/integration) +[Home Assistant Configurator UI](https://github.com/danielperna84/hass-configurator) is added as an optional sidecar container to Home Assistant with access to the home assistant configuration for easy in-browser editing and manipulation of Home Assistant. + ## Git sync secret In order to sync the home assistant from a git repo, you have to store a ssh key as a kubernetes git secret diff --git a/stable/home-assistant/templates/appdaemon-ingress.yaml b/stable/home-assistant/templates/appdaemon-ingress.yaml new file mode 100644 index 0000000000..589baa3e49 --- /dev/null +++ b/stable/home-assistant/templates/appdaemon-ingress.yaml @@ -0,0 +1,39 @@ +{{- if (.Values.appdaemon.enabled) and (.Values.appdaemon.ingress.enabled) }} +{{- $fullName := include "home-assistant.fullname" . -}} +{{- $servicePort := .Values.appdaemon.service.port -}} +{{- $ingressPath := .Values.appdaemon.ingress.path -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }}-appdaemon + labels: + app.kubernetes.io/name: {{ include "home-assistant.name" . }} + helm.sh/chart: {{ include "home-assistant.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- with .Values.appdaemon.ingress.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if .Values.appdaemon.ingress.tls }} + tls: + {{- range .Values.appdaemon.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.appdaemon.ingress.hosts }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $servicePort }} + {{- end }} +{{- end }} diff --git a/stable/home-assistant/templates/deployment.yaml b/stable/home-assistant/templates/deployment.yaml index 9c7c2c8107..9be0c1a925 100644 --- a/stable/home-assistant/templates/deployment.yaml +++ b/stable/home-assistant/templates/deployment.yaml @@ -270,6 +270,52 @@ spec: resources: {{ toYaml .Values.vscode.resources | indent 12 }} {{- end }} + {{- if .Values.appdaemon.enabled }} + - name: appdaemon + image: "{{ .Values.appdaemon.image.repository }}:{{ .Values.appdaemon.image.tag }}" + imagePullPolicy: {{ .Values.appdaemon.image.pullPolicy }} + ports: + - name: appdaemon + containerPort: {{ .Values.appdaemon.service.port }} + protocol: TCP + env: + - name: HA_URL + value: "http://localhost:{{ .Values.service.port }}" + {{- if .Values.appdaemon.ingress.enabled }} + - name: DASH_URL + #value: http{{ if .Values.appdaemon.ingress.tls }}s{{ end }}://{{ index .Values.appdaemon.ingress.hosts 0 }} + value: http://0.0.0.0:{{ .Values.appdaemon.service.port }} + {{- end }} + {{- if .Values.appdaemon.haToken }} + - name: TOKEN + valueFrom: + secretKeyRef: + name: {{ template "home-assistant.fullname" . }}-appdaemon + key: token + {{- end }} + {{- range $key, $value := .Values.vscode.extraEnv }} + - name: {{ $key }} + value: {{ $value }} + {{- end }} + volumeMounts: + - mountPath: /ha-conf + name: config + - mountPath: /conf + subPath: appdaemon + name: config + {{- if .Values.extraVolumeMounts }}{{ toYaml .Values.extraVolumeMounts | trim | nindent 10 }}{{ end }} + {{- if .Values.usePodSecurityContext }} + securityContext: + runAsUser: {{ default 0 .Values.runAsUser }} + {{- if and (.Values.runAsUser) (.Values.fsGroup) }} + {{- if not (eq .Values.runAsUser 0.0) }} + fsGroup: {{ .Values.fsGroup }} + {{- end }} + {{- end }} + {{- end }} + resources: +{{ toYaml .Values.appdaemon.resources | indent 12 }} + {{- end }} volumes: - name: config {{- if .Values.persistence.enabled }} diff --git a/stable/home-assistant/templates/secret.yaml b/stable/home-assistant/templates/secret.yaml index 296a37d830..9cf83a4fde 100644 --- a/stable/home-assistant/templates/secret.yaml +++ b/stable/home-assistant/templates/secret.yaml @@ -36,4 +36,21 @@ data: {{- if .Values.vscode.password }} password: {{ .Values.vscode.password | b64enc | quote }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} +--- +{{- if .Values.appdaemon.enabled }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ template "home-assistant.fullname" . }}-appdaemon + labels: + app.kubernetes.io/name: {{ include "home-assistant.name" . }} + helm.sh/chart: {{ include "home-assistant.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +type: Opaque +data: + {{- if .Values.appdaemon.haToken }} + token: {{ .Values.appdaemon.haToken | b64enc | quote }} + {{- end }} +{{- end }} diff --git a/stable/home-assistant/templates/service.yaml b/stable/home-assistant/templates/service.yaml index 754a781422..e44ecece02 100644 --- a/stable/home-assistant/templates/service.yaml +++ b/stable/home-assistant/templates/service.yaml @@ -63,6 +63,15 @@ spec: nodePort: {{.Values.vscode.service.nodePort}} {{ end }} {{- end }} +{{- if .Values.appdaemon.enabled }} + - name: appdaemon + port: {{ .Values.appdaemon.service.port }} + protocol: TCP + targetPort: 5050 +{{ if (and (eq .Values.appdaemon.service.type "NodePort") (not (empty .Values.appdaemon.service.nodePort))) }} + nodePort: {{.Values.appdaemon.service.nodePort}} +{{ end }} +{{- end }} {{- if .Values.service.additionalPorts }} {{- .Values.service.additionalPorts | toYaml | indent 4 }} {{- end }} diff --git a/stable/home-assistant/values.yaml b/stable/home-assistant/values.yaml index 2322fe5356..0599eaedc6 100644 --- a/stable/home-assistant/values.yaml +++ b/stable/home-assistant/values.yaml @@ -34,7 +34,7 @@ service: type: ClusterIP port: 8123 portName: api - additionalPorts: {} + additionalPorts: [] # - name: homematicproxy # port: 2001 # targetPort: 2001 @@ -263,6 +263,51 @@ vscode: loadBalancerSourceRanges: [] # nodePort: 30000 +appdaemon: + enabled: false + + ## code-server container image + ## + image: + repository: acockburn/appdaemon + tag: 3.0.5 + pullPolicy: IfNotPresent + + ## Home Assistant API token + # haToken: + + ## Additional hass-vscode container environment variable + ## For instance to add a http_proxy + ## + extraEnv: {} + + ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + path: / + hosts: + - appdaemon.local + tls: [] + # - secretName: appdaemon-tls + # hosts: + # - appdaemon.local + + service: + type: ClusterIP + port: 5050 + annotations: {} + labels: {} + clusterIP: "" + ## List of IP addresses at which the hass-appdaemon service is available + ## Ref: https://kubernetes.io/docs/user-guide/services/#external-ips + ## + externalIPs: [] + loadBalancerIP: "" + loadBalancerSourceRanges: [] + # nodePort: 30000 + resources: {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little