Skip to content

Commit

Permalink
Add kubernetes helm chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-fritz committed May 25, 2024
1 parent 91a35d8 commit 0179e43
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ completions/
bin/
reports/
.sonarcloud.properties
test-values.yaml
24 changes: 24 additions & 0 deletions charts/knx-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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/
test-values.yaml
24 changes: 24 additions & 0 deletions charts/knx-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: knx-exporter-helm
description: The KNX Prometheus Exporter is a small bridge to export values measured by KNX sensors to Prometheus.

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
16 changes: 16 additions & 0 deletions charts/knx-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1. Get the application URL by running these commands:
{{- if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "knx-exporter.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "knx-exporter.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "knx-exporter.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 "knx-exporter.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 changes: 62 additions & 0 deletions charts/knx-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "knx-exporter.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 "knx-exporter.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 "knx-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "knx-exporter.labels" -}}
helm.sh/chart: {{ include "knx-exporter.chart" . }}
{{ include "knx-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "knx-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "knx-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "knx-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "knx-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions charts/knx-exporter/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "knx-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "knx-exporter.labels" . | nindent 4 }}
data:
knx-exporter.yaml: |
connection:
type: {{ .Values.connection.type | quote}}
endpoint: {{ .Values.connection.endpoint | quote }}
physicalAddress: {{ .Values.connection.physicalAddress | quote }}
{{- with .Values.connection.tunnelConfig }}
tunnelConfig:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.connection.routerConfig }}
routerConfig:
{{- toYaml . | nindent 8 }}
{{- end }}
metricsPrefix: {{ .Values.metricsPrefix | quote }}
addressConfigs:
{{- toYaml .Values.addressConfigs | nindent 6 }}
{{- with .Values.readStartupInterval }}
readStartupInterval: {{ . }}
{{- end }}
93 changes: 93 additions & 0 deletions charts/knx-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "knx-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "knx-exporter.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "knx-exporter.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "knx-exporter.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "knx-exporter.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
args:
- run
- -f
- /etc/knx-exporter/knx-exporter.yaml
- -p
- {{ .Values.service.port | quote }}
- --withGoMetrics={{ .Values.exportGoMetrics }}
- -r
- health
{{- with .Values.logging}}
{{- with .format }}
- --log_format={{ . }}
{{- end }}
{{- with .level }}
- --log_level={{ . }}
{{- end }}
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: config
mountPath: /etc/knx-exporter/
readOnly: true
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
- name: config
configMap:
name: {{ include "knx-exporter.fullname" . }}
items:
- key: knx-exporter.yaml
path: knx-exporter.yaml
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- 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 }}
16 changes: 16 additions & 0 deletions charts/knx-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "knx-exporter.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "knx-exporter.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "knx-exporter.selectorLabels" . | nindent 4 }}
14 changes: 14 additions & 0 deletions charts/knx-exporter/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "knx-exporter.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "knx-exporter.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
27 changes: 27 additions & 0 deletions charts/knx-exporter/templates/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- if not .Values.connection }}
{{- fail "Missing connection configuration" }}
{{- end }}

{{- if not .Values.connection.endpoint }}
{{- fail "Missing knx endpoint in `connection.endpoint`." }}
{{- end }}

{{- if not .Values.connection.physicalAddress }}
{{- fail "Missing physical knx address in `connection.physicalAddress`." }}
{{- end }}

{{- if not .Values.connection.type }}
{{- fail "Missing connection type in `connection.type`." }}
{{- end }}

{{- if not (or (eq .Values.connection.type "Tunnel") (eq .Values.connection.type "Router")) }}
{{- fail "Connection type must be either `Tunnel` or `Router`" }}
{{- end }}

{{- if and (eq .Values.connection.type "Tunnel") (not .Values.connection.tunnelConfig) }}
{{- fail "Connection type is Tunnel but `connection.tunnelConfig` is empty." }}
{{- end }}

{{- if and (eq .Values.connection.type "Router") (not .Values.connection.routerConfig) }}
{{- fail "Connection type is Router but `connection.routerConfig` is empty." }}
{{- end }}
Loading

0 comments on commit 0179e43

Please sign in to comment.