diff --git a/charts/esphome/Chart.yaml b/charts/esphome/Chart.yaml new file mode 100644 index 0000000..15f57a8 --- /dev/null +++ b/charts/esphome/Chart.yaml @@ -0,0 +1,15 @@ +--- +apiVersion: v2 +appVersion: 2024.2.1 +description: ESPHome +name: esphome +version: 0.0.1 +keywords: +- esphome +type: application +home: https://github.com/JacekZubielik/helm-charts/tree/master/charts/esphome +icon: https://esphome.io/_images/logo-text.svg +sources: +- https://github.com/esphome/esphome +maintainers: + - name: jacekzubielik diff --git a/charts/esphome/templates/NOTES.txt b/charts/esphome/templates/NOTES.txt new file mode 100644 index 0000000..948b6ac --- /dev/null +++ b/charts/esphome/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "app.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.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 {{ template "app.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "app.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "app.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:80 +{{- end }} diff --git a/charts/esphome/templates/_helpers.tpl b/charts/esphome/templates/_helpers.tpl new file mode 100644 index 0000000..94ae4ff --- /dev/null +++ b/charts/esphome/templates/_helpers.tpl @@ -0,0 +1,50 @@ +{{/* Expand the name of the chart. */}} +{{- define "app.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. */}} +{{- define "app.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* Create chart name and version as used by the chart label. */}} +{{- define "app.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* Common labels */}} +{{- define "app.labels" -}} +helm.sh/chart: {{ include "app.chart" . }} +{{ include "app.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* Selector labels */}} +{{- define "app.selectorLabels" -}} +app.kubernetes.io/name: {{ include "app.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* Create the name of the service account to use */}} +{{- define "app.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "app.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/esphome/templates/deployment.yaml b/charts/esphome/templates/deployment.yaml new file mode 100644 index 0000000..d064b37 --- /dev/null +++ b/charts/esphome/templates/deployment.yaml @@ -0,0 +1,140 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "app.fullname" . }} + labels: + {{- include "app.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicas }} + revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} + selector: + matchLabels: + {{- include "app.selectorLabels" . | nindent 6 }} + strategy: + type: {{ .Values.strategyType }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "app.selectorLabels" . | nindent 8 }} + {{- if .Values.podLabels }} + {{- toYaml .Values.podLabels | nindent 8 }} + {{- end }} + spec: + {{- with .Values.image.PullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + shareProcessNamespace: {{ .Values.sidecarSingleProcessNamespace }} + serviceAccountName: {{ include "app.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.securityContext | nindent 8 }} + {{- if .Values.hostNetwork }} + hostNetwork: {{ .Values.hostNetwork }} + dnsPolicy: ClusterFirstWithHostNet + {{- end }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + {{- range $key, $value := .Values.extraEnv }} + - name: {{ $key | }} + value: {{ $value | }} + {{- end }} + {{- range $name, $opts := .Values.extraEnvSecrets }} + - name: {{ $name }} + valueFrom: + secretKeyRef: + name: {{ $opts.secret }} + key: {{ $opts.key }} + {{- end }} + envFrom: + {{- range .Values.extraSecretForEnvFrom }} + - secretRef: + name: {{ . }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + ports: + - name: api + containerPort: {{ .Values.service.httpPort }} + protocol: TCP + - name: metrics + containerPort: {{ .Values.service.metricsPort }} + protocol: TCP + {{- if .Values.livenessProbe.enabled }} + livenessProbe: + httpGet: + path: /ping + port: {{ .Values.service.httpPort }} + scheme: {{ .Values.livenessProbe.scheme }} + periodSeconds: {{ .Values.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.livenessProbe.failureThreshold }} + initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds}} + {{- end }} + {{- if .Values.readinessProbe.enabled }} + readinessProbe: + httpGet: + path: /ping + port: {{ .Values.service.httpPort }} + scheme: {{ .Values.livenessProbe.scheme }} + periodSeconds: {{ .Values.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} + successThreshold: {{ .Values.readinessProbe.successThreshold }} + failureThreshold: {{ .Values.readinessProbe.failureThreshold }} + initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds}} + {{- end }} + volumeMounts: + - mountPath: /config + name: config-storage + {{- range .Values.hostMounts }} + {{- if .mountPath }} + - mountPath: {{ .mountPath }} + {{- else }} + - mountPath: {{ .hostPath }} + {{- end }} + name: {{ .name }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: config-storage + {{- if .Values.persistence.enabled }} + {{- if .Values.persistence.configstorage.hostPath }} + hostPath: + path: {{.Values.persistence.configstorage.hostPath}} + {{- else }} + persistentVolumeClaim: + claimName: {{ if .Values.persistence.existingClaim }}{{ .Values.persistence.existingClaim }}{{- else }}{{ template "app.fullname" . }}{{- end }} + {{- end }} + {{- else }} + emptyDir: {} + {{ end }} + {{- range .Values.hostMounts }} + - name: {{ .name }} + hostPath: + path: {{.hostPath}} + {{- if .type }} + type: {{ .type }} + {{- end }} + {{- end }} + diff --git a/charts/esphome/templates/ingress.yaml b/charts/esphome/templates/ingress.yaml new file mode 100644 index 0000000..f62bf39 --- /dev/null +++ b/charts/esphome/templates/ingress.yaml @@ -0,0 +1,64 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "app.fullname" . -}} +{{- $servicePort := .Values.service.http -}} +{{- $ingressPath := .Values.ingress.path -}} +{{- $new := false }} +{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" -}} +apiVersion: networking.k8s.io/v1 +{{- $new = true }} +{{- else }} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "app.labels" . | nindent 4 }} + annotations: + {{- if not $new }} + kubernetes.io/ingress.class: {{ required "If ingress.enabled is set to true, ingress.class is required" .Values.ingress.class }} + {{- end }} + {{- if .Values.ingress.annotations }} + {{- toYaml .Values.ingress.annotations | nindent 4 }} + {{- end }} +spec: + {{- if $new }} + ingressClassName: {{ required "If ingress.enabled is set to true, ingress.class is required" .Values.ingress.class }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- if $new }} + {{- range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + pathType: Prefix + backend: + service: + name: {{ $fullName }} + port: + number: {{ $servicePort }} + {{- end }} + {{- else }} + {{- range .Values.ingress.hosts }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $servicePort }} + {{- end }} + {{- end }} +{{- end }} + diff --git a/charts/esphome/templates/pvc.yaml b/charts/esphome/templates/pvc.yaml new file mode 100644 index 0000000..a24f0b3 --- /dev/null +++ b/charts/esphome/templates/pvc.yaml @@ -0,0 +1,21 @@ +{{- if and .Values.persistence.pvc.enabled (not .Values.persistence.configstorage.hostPath) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ template "app.fullname" . }} + labels: + {{- include "app.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.persistence.pvc.accessMode }} + resources: + requests: + storage: {{ .Values.persistence.pvc.size }} + {{- if .Values.persistence.pvc.storageClass }} + {{- if (eq "-" .Values.persistence.pvc.storageClass) }} + storageClassName: "" + {{- else }} + storageClassName: "{{ .Values.persistence.pvc.storageClass }}" + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/esphome/templates/service.yaml b/charts/esphome/templates/service.yaml new file mode 100644 index 0000000..642050b --- /dev/null +++ b/charts/esphome/templates/service.yaml @@ -0,0 +1,41 @@ +apiVersion: v1 +kind: Service +metadata: + {{- if .Values.service.annotations }} + annotations: + {{- toYaml .Values.service.annotations | nindent 4 }} + {{- end }} + name: {{ template "app.fullname" . }} + labels: + {{- include "app.labels" . | nindent 4 }} + {{- if .Values.service.labels }} + {{ toYaml .Values.service.labels | indent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + {{- if .Values.service.externalIPs }} + externalIPs: + {{- toYaml .Values.service.externalIPs | nindent 4 }} + {{- end }} + {{- if .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} + {{- end }} + {{- if .Values.service.loadBalancerIP }} + loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + {{- if .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }} + {{- end }} + publishNotReadyAddresses: {{ .Values.service.publishNotReadyAddresses }} + ports: + - name: api + port: {{ .Values.service.httpPort }} + protocol: TCP + targetPort: {{ .Values.service.httpPort }} + - name: metrics + port: {{ .Values.service.metricsPort }} + protocol: TCP + targetPort: metrics + selector: + {{- include "app.selectorLabels" . | nindent 4 }} \ No newline at end of file diff --git a/charts/esphome/templates/serviceaccount.yaml b/charts/esphome/templates/serviceaccount.yaml new file mode 100644 index 0000000..446a8c9 --- /dev/null +++ b/charts/esphome/templates/serviceaccount.yaml @@ -0,0 +1,16 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: +{{- if .Values.serviceAccount.annotations }} + annotations: +{{- toYaml .Values.serviceAccount.annotations | nindent 4 }} +{{- end }} + name: {{ template "app.fullname" . }} + labels: +{{- include "app.labels" . | nindent 4 }} +{{- if .Values.serviceAccount.labels }} +{{ toYaml .Values.serviceAccount.labels | indent 4 }} +{{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} +{{- end }} diff --git a/charts/esphome/templates/servicemonitor.yaml b/charts/esphome/templates/servicemonitor.yaml new file mode 100644 index 0000000..92293f3 --- /dev/null +++ b/charts/esphome/templates/servicemonitor.yaml @@ -0,0 +1,67 @@ +{{- if and ( .Values.monitoring.serviceMonitor.enabled ) ( .Values.monitoring.enabled ) }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "app.fullname" . }}-prometheus-exporter + labels: + {{- include "app.labels" . | nindent 4 }} + {{- with .Values.monitoring.serviceMonitor.selector }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.monitoring.serviceMonitor.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.monitoring.serviceMonitor.namespace }} + namespace: {{ .Values.monitoring.serviceMonitor.namespace }} + {{- end }} +spec: + selector: + matchLabels: + {{- include "app.selectorLabels" . | nindent 6 }} + {{- if .Values.podLabels }} + {{- toYaml .Values.podLabels | nindent 6 }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + endpoints: + - targetPort: {{ .Values.service.metricsPort }} + path: /metrics + {{- with .Values.monitoring.serviceMonitor.honorLabels }} + honorLabels: {{ . }} + {{- end }} + {{- if .Values.monitoring.serviceMonitor.interval }} + interval: {{ .Values.monitoring.serviceMonitor.interval }} + {{- end }} + {{- if .Values.monitoring.serviceMonitor.scrapeTimeout}} + scrapeTimeout: {{ .Values.monitoring.serviceMonitor.scrapeTimeout }} + {{- end }} + {{- with .Values.monitoring.serviceMonitor.scheme }} + scheme: {{ . }} + {{- end }} + {{- with .Values.monitoring.serviceMonitor.tlsConfig }} + tlsConfig: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.monitoring.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.monitoring.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- if .Values.monitoring.serviceMonitor.bearerTokenFile }} + bearerTokenFile: {{ .Values.monitoring.serviceMonitor.bearerTokenFile }} + {{- end }} + {{- if .Values.monitoring.serviceMonitor.bearerTokenSecret }} + bearerTokenSecret: + name: {{ .Values.monitoring.serviceMonitor.bearerTokenSecret.name }} + key: {{ .Values.monitoring.serviceMonitor.bearerTokenSecret.key }} + {{- if .Values.monitoring.serviceMonitor.bearerTokenSecret.optional }} + optional: {{ .Values.monitoring.serviceMonitor.bearerTokenSecret.optional }} + {{- end }} + {{- end }} + jobLabel: {{ template "app.fullname" . }}-prometheus-exporter +{{- end }} \ No newline at end of file diff --git a/charts/esphome/values.yaml b/charts/esphome/values.yaml new file mode 100644 index 0000000..7582a8e --- /dev/null +++ b/charts/esphome/values.yaml @@ -0,0 +1,154 @@ +image: + repository: esphome/esphome + tag: "" + pullPolicy: IfNotPresent + pullSecrets: [] +nameOverride: "" +fullnameOverride: "" +revisionHistoryLimit: 2 +hostNetwork: false +replicas: 1 +strategyType: RollingUpdate +serviceAccount: + create: true + annotations: {} + automountServiceAccountToken: false +podAnnotations: {} +podLabels: {} +extraEnv: {} +extraEnvSecrets: + # This will set ${MQTT_PASSWORD} to the 'password' key from the 'mqtt' secret + # MQTT_PASSWORD: + # secret: mqtt + # key: password +## If you'd like to provide your own Kubernetes Secret object instead of passing your values +## individually, pass in the name of a created + populated Secret. +## All secrets will be mounted as environment variables, with each key/value mapping to a +## corresponding environment variable. +extraSecretForEnvFrom: [] +# - esphome-secrets +podSecurityContext: + privileged: false + # fsGroup: 2000 +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 +service: + annotations: {} + # prometheus.io/scrape: "false" + # prometheus.io/port: {{ .Values.service.metricsPort }} + labels: {} + type: ClusterIP + externalIPs: [] + loadBalancerIP: "" + externalTrafficPolicy: {} + loadBalancerSourceRanges: [] + publishNotReadyAddresses: false + httpPort: 6052 + metricsPort: 9100 +monitoring: + enabled: false + serviceMonitor: + enabled: false + labels: {} + honorLabels: true + interval: 60s + selector: {} + namespace: {} + scrapeTimeout: 10s + scheme: http + tlsConfig: {} + relabelings: [] + # - sourceLabels: [__meta_kubernetes_pod_node_name] + # separator: ; + # regex: ^(.*)$ + # target_label: nodename + # replacement: $1 + # action: replace + metricRelabelings: [] + # - action: keep + # regex: 'kube_(daemonset|deployment|pod|namespace|node|statefulset).+' + # sourceLabels: [__name__] + bearerTokenFile: {} + # (use long lived access tokens) + bearerTokenSecret: {} + # name: + # key: + # optional: +livenessProbe: + enabled: true + scheme: HTTP + periodSeconds: 60 + timeoutSeconds: 10 + successThreshold: 1 + failureThreshold: 6 + initialDelaySeconds: 30 +readinessProbe: + enabled: true + scheme: HTTP + periodSeconds: 60 + timeoutSeconds: 10 + successThreshold: 1 + failureThreshold: 6 + initialDelaySeconds: 30 +ingress: + enabled: false + # className: "" + annotations: + nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" + nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" + nginx.ingress.kubernetes.io/server-snippets: | + location / { + proxy_set_header Upgrade $http_upgrade; + proxy_http_version 1.1; + proxy_set_header X-Forwarded-Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $host; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_cache_bypass $http_upgrade; + } + hosts: + - host: esphome.local + paths: + - path: / + pathType: ImplementationSpecific + tls: + [] + # - secretName: letsencrypt-staging + # hosts: + # - esphome.local +resources: {} +# requests: +# cpu: "1" +# memory: "256Mi" +# limits: +# cpu: "1" +# memory: "512Mi" +nodeSelector: + kubernetes.io/hostname: {} +affinity: {} +tolerations: [] +persistence: + enabled: false + configstorage: + hostPath: {} + pvc: + enabled: false + accessModes: + - {} + resources: + requests: + storage: 2Gi + storageClassName: "" +# Mount devices or folders from the host machine. Can be used for USB device mounting. +hostMounts: [] + # - name: zha + # hostPath: /dev/serial/by-id/usb-Silicon_Labs_HubZ_Smart_Home_Controller_6120245D-if01-port0