From 931ef940d42f64c2a8ddb73790ff36ee71657869 Mon Sep 17 00:00:00 2001 From: Alex Manning Date: Tue, 28 Feb 2023 20:42:51 +0000 Subject: [PATCH] Add esphome. --- .woodpecker/{common.yaml => esphome.yaml} | 4 +- charts/common/Chart.yaml | 5 -- charts/common/values.yaml | 0 charts/esphome/.helmignore | 23 ++++++ charts/esphome/Chart.yaml | 6 ++ .../templates/_helpers.tpl | 20 +++--- charts/esphome/templates/deployment.yaml | 70 +++++++++++++++++++ charts/esphome/templates/ingress.yaml | 20 ++++++ charts/esphome/templates/pvc.yaml | 17 +++++ charts/esphome/templates/service.yaml | 21 ++++++ charts/esphome/values.yaml | 57 +++++++++++++++ 11 files changed, 226 insertions(+), 17 deletions(-) rename .woodpecker/{common.yaml => esphome.yaml} (81%) delete mode 100644 charts/common/Chart.yaml delete mode 100644 charts/common/values.yaml create mode 100644 charts/esphome/.helmignore create mode 100644 charts/esphome/Chart.yaml rename charts/{common => esphome}/templates/_helpers.tpl (74%) create mode 100644 charts/esphome/templates/deployment.yaml create mode 100644 charts/esphome/templates/ingress.yaml create mode 100644 charts/esphome/templates/pvc.yaml create mode 100644 charts/esphome/templates/service.yaml create mode 100644 charts/esphome/values.yaml diff --git a/.woodpecker/common.yaml b/.woodpecker/esphome.yaml similarity index 81% rename from .woodpecker/common.yaml rename to .woodpecker/esphome.yaml index f295299..49e6a0f 100644 --- a/.woodpecker/common.yaml +++ b/.woodpecker/esphome.yaml @@ -1,6 +1,6 @@ --- when: - path: "charts/common/*" + path: "charts/esphome/*" branches: - main pipeline: @@ -10,4 +10,4 @@ pipeline: commands: - helm plugin install https://github.com/chartmuseum/helm-push - helm repo add therepo $HELM_REPO --username $HELM_USER --password $HELM_PASSWORD - - helm cm-push charts/common therepo + - helm cm-push charts/esphome therepo diff --git a/charts/common/Chart.yaml b/charts/common/Chart.yaml deleted file mode 100644 index ed16f28..0000000 --- a/charts/common/Chart.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -apiVersion: v2 -name: a09-common -type: library -version: 0.1.1 diff --git a/charts/common/values.yaml b/charts/common/values.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/charts/esphome/.helmignore b/charts/esphome/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/esphome/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/esphome/Chart.yaml b/charts/esphome/Chart.yaml new file mode 100644 index 0000000..61aad62 --- /dev/null +++ b/charts/esphome/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: esphome +description: A Helm chart for esphome. +type: application +version: 0.1.0 +appVersion: "2023.2.4" diff --git a/charts/common/templates/_helpers.tpl b/charts/esphome/templates/_helpers.tpl similarity index 74% rename from charts/common/templates/_helpers.tpl rename to charts/esphome/templates/_helpers.tpl index 7f04e75..6d0ba2d 100644 --- a/charts/common/templates/_helpers.tpl +++ b/charts/esphome/templates/_helpers.tpl @@ -1,7 +1,7 @@ {{/* Expand the name of the chart. */}} -{{- define "a09-common.name" -}} +{{- define "esphome.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} @@ -10,7 +10,7 @@ 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 "a09-common.fullname" -}} +{{- define "esphome.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "a09-common.chart" -}} +{{- define "esphome.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} -{{- define "a09-common.labels" -}} -helm.sh/chart: {{ include "a09-common.chart" . }} -{{ include "a09-common.selectorLabels" . }} +{{- define "esphome.labels" -}} +helm.sh/chart: {{ include "esphome.chart" . }} +{{ include "esphome.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels */}} -{{- define "a09-common.selectorLabels" -}} -app.kubernetes.io/name: {{ include "a09-common.name" . }} +{{- define "esphome.selectorLabels" -}} +app.kubernetes.io/name: {{ include "esphome.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* Create the name of the service account to use */}} -{{- define "a09-common.serviceAccountName" -}} +{{- define "esphome.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} -{{- default (include "a09-common.fullname" .) .Values.serviceAccount.name }} +{{- default (include "esphome.fullname" .) .Values.serviceAccount.name }} {{- else }} {{- default "default" .Values.serviceAccount.name }} {{- end }} diff --git a/charts/esphome/templates/deployment.yaml b/charts/esphome/templates/deployment.yaml new file mode 100644 index 0000000..4037c22 --- /dev/null +++ b/charts/esphome/templates/deployment.yaml @@ -0,0 +1,70 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "esphome.fullname" . }} + labels: + {{- include "esphome.labels" . | nindent 4 }} +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + hass.kube.a09.uk/automationService: esphome + {{- include "esphome.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + hass.kube.a09.uk/automationService: esphome + {{- include "esphome.selectorLabels" . | nindent 8 }} + spec: + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "esphome.serviceAccountName" . }}-esphome + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + priorityClassName: {{ .Values.priorityClassName }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 6052 + protocol: TCP + livenessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: config + mountPath: /config + {{- 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 + persistentVolumeClaim: + claimName: {{ include "esphome.fullname" . }}-config diff --git a/charts/esphome/templates/ingress.yaml b/charts/esphome/templates/ingress.yaml new file mode 100644 index 0000000..98f0a45 --- /dev/null +++ b/charts/esphome/templates/ingress.yaml @@ -0,0 +1,20 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "esphome.fullname" . }} + labels: + {{- include "esphome.labels" . | nindent 4 }} +spec: + rules: + - host: {{ .Values.ingress.host }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ include "esphome.fullname" . }} + port: + name: http +{{- end }} diff --git a/charts/esphome/templates/pvc.yaml b/charts/esphome/templates/pvc.yaml new file mode 100644 index 0000000..f81e4e0 --- /dev/null +++ b/charts/esphome/templates/pvc.yaml @@ -0,0 +1,17 @@ +{{- if not .Values.pvc.existingClaim -}} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "esphome.fullname" . }}-config + labels: + {{- include "esphome.labels" . | nindent 4 }} + annotations: + helm.sh/resource-policy: "keep" +spec: + accessModes: + - ReadWriteOnce + storageClassName: {{ .Values.pvc.storageClassName | quote }} + resources: + requests: + storage: {{ .Values.pvc.storage | quote }} +{{- end }} diff --git a/charts/esphome/templates/service.yaml b/charts/esphome/templates/service.yaml new file mode 100644 index 0000000..c7f22e1 --- /dev/null +++ b/charts/esphome/templates/service.yaml @@ -0,0 +1,21 @@ +{{- if .Values.esphome.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "esphome.fullname" . }} + labels: + {{- include "esphome.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: 6052 + targetPort: http + protocol: TCP + name: http + {{- with .Values.service.nodePort }} + nodePort: {{ . }} + {{- end }} + selector: + hass.kube.a09.uk/automationService: esphome + {{- include "esphome.selectorLabels" . | nindent 4 }} +{{- end }} diff --git a/charts/esphome/values.yaml b/charts/esphome/values.yaml new file mode 100644 index 0000000..8e4405b --- /dev/null +++ b/charts/esphome/values.yaml @@ -0,0 +1,57 @@ +# Default values for esphome. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: ghcr.io/esphome/esphome + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + host: "" + +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 + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +pvc: + existingClaim: false + storageClassName: "" + storage: 5Gi