From d733be90e3771c577df510b3bda37745fc9e5638 Mon Sep 17 00:00:00 2001 From: Miguel Angel Santiago Date: Sun, 9 Aug 2020 14:06:29 +0200 Subject: [PATCH] [zigbee2mqtt] ui application (#296) * Including UI with lint Signed-off-by: Miguel Angel Santiago * Ingress deactivated by default Signed-off-by: Miguel Angel Santiago * Version 0.2.0 Signed-off-by: Miguel Angel Santiago * Add ui settings Signed-off-by: Miguel Angel Santiago * Display the application URL Signed-off-by: Miguel Angel Santiago * Protect boolean as string Signed-off-by: Miguel Angel Santiago * Remove warning from lint Signed-off-by: Miguel Angel Santiago * Move probes, service and ingress within ui values Signed-off-by: Miguel Angel Santiago * Revert "Move probes, service and ingress within ui values" This reverts commit 08a91e316bb81aee43739ed51f89d378541cf255. * Using generic configmap por assistant settings Signed-off-by: Miguel Angel Santiago * Move probes, services and ingress within assistant section Signed-off-by: Miguel Angel Santiago * Some wording Signed-off-by: Miguel Angel Santiago Co-authored-by: Miguel Angel Santiago --- charts/zigbee2mqtt/Chart.yaml | 4 +- charts/zigbee2mqtt/templates/NOTES.txt | 21 +++++++ charts/zigbee2mqtt/templates/configmap.yaml | 37 +++++++++++ charts/zigbee2mqtt/templates/ingress.yaml | 35 +++++++++++ charts/zigbee2mqtt/templates/service.yaml | 50 +++++++++++++++ .../zigbee2mqtt/templates/statefullset.yaml | 28 +++++++++ charts/zigbee2mqtt/values.yaml | 63 ++++++++++++++++++- 7 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 charts/zigbee2mqtt/templates/ingress.yaml create mode 100644 charts/zigbee2mqtt/templates/service.yaml diff --git a/charts/zigbee2mqtt/Chart.yaml b/charts/zigbee2mqtt/Chart.yaml index 91d39ef0..69ec0693 100644 --- a/charts/zigbee2mqtt/Chart.yaml +++ b/charts/zigbee2mqtt/Chart.yaml @@ -3,7 +3,7 @@ name: zigbee2mqtt type: application description: Bridges events and allows you to control your Zigbee devices via MQTT appVersion: 1.14.1 -version: 0.1.0 +version: 0.2.0 keywords: - zigbee - mqtt @@ -14,3 +14,5 @@ sources: maintainers: - name: ishioni email: helm@movishell.pl + - name: masantiago + email: miguelangel.santiago@hotmail.com diff --git a/charts/zigbee2mqtt/templates/NOTES.txt b/charts/zigbee2mqtt/templates/NOTES.txt index e53184f5..8fbc618b 100644 --- a/charts/zigbee2mqtt/templates/NOTES.txt +++ b/charts/zigbee2mqtt/templates/NOTES.txt @@ -7,3 +7,24 @@ WARNING: You have not set a network key, which makes zigbee2mqtt run with a well Please read https://www.zigbee2mqtt.io/how_tos/how_to_secure_network.html {{- end }} {{- end }} +{{- if .Values.assistant.enabled }} +Get the Z2MA URL by running these commands: +{{- if .Values.assistant.ingress.enabled }} +{{- range .Values.assistant.ingress.hosts }} + http{{ if $.Values.assistant.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.assistant.ingress.path }} +{{- end }} +{{- else if contains "NodePort" .Values.assistant.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "zigbee2mqtt.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.assistant.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ include "zigbee2mqtt.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "zigbee2mqtt.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.assistant.service.port }} +{{- else if contains "ClusterIP" .Values.assistant.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "zigbee2mqtt.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:5000 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 5000:80 +{{- end }} +{{- end }} diff --git a/charts/zigbee2mqtt/templates/configmap.yaml b/charts/zigbee2mqtt/templates/configmap.yaml index f28536d1..2587e4ec 100644 --- a/charts/zigbee2mqtt/templates/configmap.yaml +++ b/charts/zigbee2mqtt/templates/configmap.yaml @@ -9,3 +9,40 @@ data: {{- with .Values.config }} {{- toYaml . | nindent 4 }} {{- end }} +--- +{{- if .Values.assistant.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "zigbee2mqtt.fullname" . }}assistant + labels: +{{ include "zigbee2mqtt.labels" . | indent 4 }} +data: + TZ: {{ .Values.timezone | quote }} + {{- $server := default "mqtt://localhost:1883" .Values.config.mqtt.server }} + {{- $protocol := (split "://" $server)._0 }} + {{- $host := (split ":" (split "://" $server)._1)._0 }} + {{- $port := (split ":" $server)._2 }} + Z2MA_SETTINGS__MQTTSERVER: {{ $host }} + {{- if eq $protocol "mqtts"}} + Z2MA_SETTINGS__MQTTSECURE: "true" + {{- end }} + {{- if $port }} + Z2MA_SETTINGS__MQTTPORT: {{ $port }} + {{- end }} + {{- if .Values.config.mqtt.user }} + Z2MA_SETTINGS__MQTTUSERNAME: {{ .Values.config.mqtt.user }} + {{- end }} + {{- if .Values.config.mqtt.password }} + Z2MA_SETTINGS__MQTTPASSWORD: {{ .Values.config.mqtt.password }} + {{- end }} + {{- if .Values.config.mqtt.base_topic }} + Z2MA_SETTINGS__BASETOPIC: {{ .Values.config.mqtt.base_topic }} + {{- end }} + {{- if and .Values.config.homeassistant .Values.config.advanced.homeassistant_discovery_topic }} + Z2MA_SETTINGS__HOMEASSISTANTDISCOVERYBASETOPIC: {{ .Values.config.advanced.homeassistant_discovery_topic }} + {{- end }} + {{- range $key, $val := .Values.assistant.config }} + Z2MA_SETTINGS__{{ $key | upper }}: {{ $val | quote }} + {{- end }} +{{- end }} diff --git a/charts/zigbee2mqtt/templates/ingress.yaml b/charts/zigbee2mqtt/templates/ingress.yaml new file mode 100644 index 00000000..84d465af --- /dev/null +++ b/charts/zigbee2mqtt/templates/ingress.yaml @@ -0,0 +1,35 @@ +{{- if and .Values.assistant.enabled .Values.assistant.ingress.enabled -}} +{{- $fullName := include "zigbee2mqtt.fullname" . -}} +{{- $ingressPath := .Values.assistant.ingress.path -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }} + labels: +{{ include "zigbee2mqtt.labels" . | indent 4 }} + {{- with .Values.assistant.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.assistant.ingress.tls }} + tls: + {{- range .Values.assistant.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.assistant.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: http + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/zigbee2mqtt/templates/service.yaml b/charts/zigbee2mqtt/templates/service.yaml new file mode 100644 index 00000000..5cea3e2a --- /dev/null +++ b/charts/zigbee2mqtt/templates/service.yaml @@ -0,0 +1,50 @@ +{{- if .Values.assistant.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "zigbee2mqtt.fullname" . }} + labels: +{{ include "zigbee2mqtt.labels" . | indent 4 }} +{{- if .Values.assistant.service.labels }} +{{ toYaml .Values.assistant.service.labels | indent 4 }} +{{- end }} +{{- with .Values.assistant.service.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} +spec: +{{- if (or (eq .Values.assistant.service.type "ClusterIP") (empty .Values.assistant.service.type)) }} + type: ClusterIP + {{- if .Values.assistant.service.clusterIP }} + clusterIP: {{ .Values.assistant.service.clusterIP }} + {{end}} +{{- else if eq .Values.assistant.service.type "LoadBalancer" }} + type: {{ .Values.assistant.service.type }} + {{- if .Values.assistant.service.loadBalancerIP }} + loadBalancerIP: {{ .Values.assistant.service.loadBalancerIP }} + {{- end }} + {{- if .Values.assistant.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: +{{ toYaml .Values.assistant.service.loadBalancerSourceRanges | indent 4 }} + {{- end -}} +{{- else }} + type: {{ .Values.assistant.service.type }} +{{- end }} +{{- if .Values.assistant.service.externalIPs }} + externalIPs: +{{ toYaml .Values.assistant.service.externalIPs | indent 4 }} +{{- end }} + {{- if .Values.assistant.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.assistant.service.externalTrafficPolicy }} + {{- end }} + ports: + - name: http + port: {{ .Values.assistant.service.port }} + protocol: TCP + targetPort: http +{{ if (and (eq .Values.assistant.service.type "NodePort") (not (empty .Values.assistant.service.nodePort))) }} + nodePort: {{.Values.assistant.service.nodePort}} +{{ end }} + selector: + {{- include "zigbee2mqtt.selectorLabels" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/zigbee2mqtt/templates/statefullset.yaml b/charts/zigbee2mqtt/templates/statefullset.yaml index 3f2ef0cd..2c85bf43 100644 --- a/charts/zigbee2mqtt/templates/statefullset.yaml +++ b/charts/zigbee2mqtt/templates/statefullset.yaml @@ -51,6 +51,34 @@ spec: mountPath: /data - name: sniffer mountPath: {{ .Values.config.serial.port }} + {{- if .Values.assistant.enabled }} + - name: {{ .Chart.Name }}assistant + image: "{{ .Values.assistant.image.repository }}:{{ .Values.assistant.image.tag | default "latest" }}" + imagePullPolicy: {{ .Values.assistant.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + scheme: HTTP + initialDelaySeconds: {{ .Values.assistant.probes.liveness.initialDelaySeconds }} + failureThreshold: {{ .Values.assistant.probes.liveness.failureThreshold }} + timeoutSeconds: {{ .Values.assistant.probes.liveness.timeoutSeconds }} + readinessProbe: + httpGet: + path: / + port: http + scheme: HTTP + initialDelaySeconds: {{ .Values.assistant.probes.readiness.initialDelaySeconds }} + failureThreshold: {{ .Values.assistant.probes.readiness.failureThreshold }} + timeoutSeconds: {{ .Values.assistant.probes.readiness.timeoutSeconds }} + envFrom: + - configMapRef: + name: {{ include "zigbee2mqtt.fullname" . }}assistant + {{- end }} volumes: - name: zigbee2mqtt configMap: diff --git a/charts/zigbee2mqtt/values.yaml b/charts/zigbee2mqtt/values.yaml index 3621c159..42d8eed7 100644 --- a/charts/zigbee2mqtt/values.yaml +++ b/charts/zigbee2mqtt/values.yaml @@ -39,8 +39,69 @@ config: log_output: - console +assistant: + enabled: true + image: + repository: carldebilly/zigbee2mqttassistant + pullPolicy: IfNotPresent + # Overrides the image tag whose default is latest. + tag: "" + # Config values from https://github.com/yllibed/Zigbee2MqttAssistant + # MQTT (connection or topic) parameters are retrieved from general config, but they can be overriden. + # All of them are case insensitive. + config: + lowBatteryThreshold: 30 + allowJoinTimeout: 20 + autosetLastSeen: false + devicesPollingSchedule: "*/12 * * * *" + networkScanSchedule: "0 */3 * * *" + + probes: + liveness: + initialDelaySeconds: 30 + failureThreshold: 5 + timeoutSeconds: 10 + readiness: + initialDelaySeconds: 30 + failureThreshold: 5 + timeoutSeconds: 10 + + service: + type: ClusterIP + port: 8091 + ## Specify the nodePort value for the LoadBalancer and NodePort service types. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport + ## + # nodePort: + ## Provide any additional annotations which may be required. This can be used to + ## set the LoadBalancer service type to internal only. + ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer + ## + annotations: {} + labels: {} + ## Use loadBalancerIP to request a specific static IP, + ## otherwise leave blank + ## + loadBalancerIP: + # loadBalancerSourceRanges: [] + ## Set the externalTrafficPolicy in the Service to either Cluster or Local + # externalTrafficPolicy: Cluster + + ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + path: / + hosts: + - chart-example.local + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + persistence: - enabled: False + enabled: false annotations: {} ## zigbee2mqtt data Persistent Volume Storage Class ## If defined, storageClassName: