first commit

This commit is contained in:
2023-11-11 09:53:16 +01:00
commit d7a10faf7c
13 changed files with 651 additions and 0 deletions

22
templates/NOTES.txt Normal file
View File

@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "fhem.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 --namespace {{ .Release.Namespace }} svc -w {{ include "fhem.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "fhem.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
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.kubernetes.io/name={{ include "fhem.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}

62
templates/_helpers.tpl Normal file
View File

@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "fhem.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 "fhem.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 "fhem.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "fhem.labels" -}}
helm.sh/chart: {{ include "fhem.chart" . }}
{{ include "fhem.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "fhem.selectorLabels" -}}
app.kubernetes.io/name: {{ include "fhem.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "fhem.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "fhem.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

133
templates/deployment.yaml Normal file
View File

@@ -0,0 +1,133 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "fhem.fullname" . }}
labels:
{{- include "fhem.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
{{- if .Values.updateStrategy }}
strategy:
type: {{- toYaml .Values.updateStrategy | nindent 6 }}
{{- end }}
selector:
matchLabels:
{{- include "fhem.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "fhem.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "fhem.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
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: fhemweb
containerPort: {{ .Values.containerPorts.fhemweb }}
protocol: TCP
livenessProbe:
httpGet:
path: /fhem
port: fhemweb
readinessProbe:
httpGet:
path: /fhem
port: fhemweb
volumeMounts:
- name: fhem-data
mountPath: /opt/fhem
subPath: fhem/
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
- name: APT_PKGS
value: {{ default "" .Values.aptPkgs | quote }}
- name: CPAN_PKGS
value: {{ default "" .Values.cpanPkgs | quote }}
- name: PIP_PKGS
value: {{ default "" .Values.pipPkgs | quote }}
- name: NPM_PKGS
value: {{ default "" .Values.npmPkgs | quote }}
- name: LOGFILE
value: {{ default "./log/fhem-%Y-%m-%d.log" .Values.logfile | quote }}
- name: TELNETPORT
value: {{ default "7072" .Values.telnetport | quote }}
- name: FHEM_UID
value: {{ default "6061" .Values.fhemUID | quote }}
- name: FHEM_GID
value: {{ default "6061" .Values.fhemGID | quote }}
- name: FHEM_PERM_DIR
value: {{ default "0750" .Values.fhemPermDir | quote }}
- name: FHEM_PERM_FILE
value: {{ default "0640" .Values.fhemPermFile | quote }}
- name: UMASK
value: {{ default "0037" .Values.umask | quote }}
- name: BLUETOOTH_GID
value: {{ default "6001" .Values.bluetoothGID | quote }}
- name: GPIO_GID
value: {{ default "6002" .Values.gpioGID | quote }}
- name: I2C_GID
value: {{ default "6003" .Values.i2cGID | quote }}
- name: TIMEOUT
value: {{ default "" .Values.timeout | quote }}
- name: LANG
value: {{ default "en_US.UTF-8" .Values.lang | quote }}
- name: LANGUAGE
value: {{ default "en_US:en" .Values.language | quote }}
- name: LC_ADDRESS
value: {{ default "de_DE.UTF-8" .Values.lcAddress | quote }}
- name: LC_MEASUREMENT
value: {{ default "de_DE.UTF-8" .Values.measurement | quote }}
- name: LC_MESSAGES
value: {{ default "en_DK.UTF-8" .Values.lcMessages | quote }}
- name: LC_MONETARY
value: {{ default "de_DE.UTF-8" .Values.lcMonetary | quote }}
- name: LC_NAME
value: {{ default "de_DE.UTF-8" .Values.lcName | quote }}
- name: LC_NUMERIC
value: {{ default "de_DE.UTF-8" .Values.lcNumeric | quote }}
- name: LC_PAPER
value: {{ default "de_DE.UTF-8" .Values.lcPaper | quote }}
- name: LC_TELEPHONE
value: {{ default "de_DE.UTF-8" .Values.lcTelephone | quote }}
- name: LC_TIME
value: {{ default "de_DE.UTF-8" .Values.lcTime | quote }}
- name: TZ
value: {{ default "Europe/Berlin" .Values.timezone | quote }}
- name: CONFIGTYPE
value: {{ default "" .Values.configtype | quote }}
{{- 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: fhem-data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ include "fhem.fullname" . }}
{{- end }}
restartPolicy: {{ default "Always" .Values.restartPolicy | quote }}

28
templates/hpa.yaml Normal file
View File

@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "fhem.fullname" . }}
labels:
{{- include "fhem.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "fhem.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}

61
templates/ingress.yaml Normal file
View File

@@ -0,0 +1,61 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "fhem.fullname" . -}}
{{- $svcFhemWebPort := .Values.service.ports.fhemweb -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "fhem.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcFhemWebPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcFhemWebPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

22
templates/pvc.yaml Normal file
View File

@@ -0,0 +1,22 @@
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim ) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "fhem.fullname" . }}
labels:
{{- include "fhem.labels" . | nindent 4 }}
annotations:
volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }}
spec:
accessModes:
{{- if not (empty .Values.persistence.accessModes) }}
{{- range .Values.persistence.accessModes }}
- {{ . | quote }}
{{- end }}
{{- else }}
- {{ .Values.persistence.accessMode | quote }}
{{- end }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- end -}}

32
templates/service.yaml Normal file
View File

@@ -0,0 +1,32 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "fhem.fullname" . }}
labels:
{{- include "fhem.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
{{- if and (eq .Values.service.type "LoadBalancer") (not (empty .Values.service.loadBalancerIP)) }}
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{- end }}
{{- if or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort") }}
externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }}
{{- end }}
{{- if and .Values.service.clusterIP (eq .Values.service.type "ClusterIP") }}
clusterIP: {{ .Values.service.clusterIP }}
{{- end }}
{{- if and (eq .Values.service.type "LoadBalancer") (not (empty .Values.service.loadBalancerSourceRanges)) }}
loadBalancerSourceRanges: {{ .Values.service.loadBalancerSourceRanges }}
{{- end }}
ports:
- name: fhemweb
port: {{ .Values.service.ports.fhemweb }}
targetPort: {{ .Values.containerPorts.fhemweb }}
{{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePorts.http))) }}
nodePort: {{ .Values.service.nodePorts.fhemweb }}
{{- end }}
{{- if .Values.service.extraPorts }}
{{- include "common.tplvalues.render" (dict "value" .Values.service.extraPorts "context" $) | nindent 4 }}
{{- end }}
selector:
{{- include "fhem.selectorLabels" . | nindent 4 }}

View File

@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "fhem.serviceAccountName" . }}
labels:
{{- include "fhem.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

View File

@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "fhem.fullname" . }}-test-connection"
labels:
{{- include "fhem.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "fhem.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never