add helm chart
This commit is contained in:
parent
29e3a7db82
commit
7335be6cac
10 changed files with 347 additions and 0 deletions
|
|
@ -1,3 +1,32 @@
|
|||
include:
|
||||
- project: 'infra/ci'
|
||||
file: '/pipelines/docker.yml'
|
||||
|
||||
Helm:
|
||||
stage: bundle
|
||||
image: alpine:latest
|
||||
dependencies:
|
||||
- Docker
|
||||
before_script:
|
||||
- apk add curl bash openssl git
|
||||
- curl -L https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4 | bash
|
||||
script:
|
||||
- helm dependency update charts/shelly-prometheus-exporter
|
||||
|
||||
- "export NEXT_PATCH_VERSION=\"$(cat charts/shelly-prometheus-exporter/Chart.yaml | grep ^version: | cut -d ' ' -f 2 | awk -F. '{print $1 \".\" $2 \".\"}')\""
|
||||
- "sed -i \"s/^ tag: .*/ tag: $CI_COMMIT_SHA/\" charts/shelly-prometheus-exporter/values.yaml"
|
||||
- helm lint charts/shelly-prometheus-exporter
|
||||
- helm package charts/shelly-prometheus-exporter --version "${NEXT_PATCH_VERSION}${CI_PIPELINE_IID}"
|
||||
artifacts:
|
||||
paths:
|
||||
- shelly-prometheus-exporter-*.tgz
|
||||
|
||||
Deploy Helm:
|
||||
image: curlimages/curl:latest
|
||||
stage: deploy
|
||||
script:
|
||||
- HELM_TGZ=$(ls shelly-prometheus-exporter-*.tgz)
|
||||
- CLEANED_BRANCH=$(echo "${CI_COMMIT_BRANCH}" | sed 's/[^a-zA-Z0-9]/-/g')
|
||||
- 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@${HELM_TGZ}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/${CLEANED_BRANCH}/charts"'
|
||||
dependencies:
|
||||
- Helm
|
||||
26
Readme.md
26
Readme.md
|
|
@ -44,3 +44,29 @@ To export more values, add an entry to the `mappings` table in [metrics.go](metr
|
|||
```sh
|
||||
MQTT_BROKER=tcp://192.168.1.10:1883 MQTT_WILDCARD_TOPIC=+ go run .
|
||||
```
|
||||
|
||||
## Helm
|
||||
|
||||
A chart is located in [charts/shelly-prometheus-exporter](charts/shelly-prometheus-exporter). It deploys the exporter,
|
||||
a Service and a `ServiceMonitor` (requires the Prometheus Operator CRDs, disable with `serviceMonitor.enabled=false`).
|
||||
|
||||
Inline connection settings:
|
||||
|
||||
```sh
|
||||
helm install shelly-exporter charts/shelly-prometheus-exporter \
|
||||
--set mqtt.broker=tcp://192.168.1.10:1883 \
|
||||
--set mqtt.username=exporter --set mqtt.password=secret \
|
||||
--set mqtt.wildcardTopic=+
|
||||
```
|
||||
|
||||
Existing secret (keys `MQTT_BROKER`, optional `MQTT_USERNAME` / `MQTT_PASSWORD`, configurable via `mqtt.existingSecretKeys`):
|
||||
|
||||
```sh
|
||||
kubectl create secret generic shelly-mqtt \
|
||||
--from-literal=MQTT_BROKER=tcp://192.168.1.10:1883 \
|
||||
--from-literal=MQTT_USERNAME=exporter --from-literal=MQTT_PASSWORD=secret
|
||||
|
||||
helm install shelly-exporter charts/shelly-prometheus-exporter \
|
||||
--set mqtt.existingSecret=shelly-mqtt \
|
||||
--set 'mqtt.topics={shellyplussmoke-halle-2,shellyplussmoke-funkzentrale}'
|
||||
```
|
||||
|
|
|
|||
5
charts/shelly-prometheus-exporter/.helmignore
Normal file
5
charts/shelly-prometheus-exporter/.helmignore
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.DS_Store
|
||||
.git/
|
||||
*.swp
|
||||
*.bak
|
||||
*.tmp
|
||||
6
charts/shelly-prometheus-exporter/Chart.yaml
Normal file
6
charts/shelly-prometheus-exporter/Chart.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: v2
|
||||
name: shelly-prometheus-exporter
|
||||
description: Prometheus exporter for Shelly devices via MQTT
|
||||
type: application
|
||||
version: 0.1.0
|
||||
appVersion: "latest"
|
||||
32
charts/shelly-prometheus-exporter/templates/_helpers.tpl
Normal file
32
charts/shelly-prometheus-exporter/templates/_helpers.tpl
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{{- define "shelly-exporter.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "shelly-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 }}
|
||||
|
||||
{{- define "shelly-exporter.labels" -}}
|
||||
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{ include "shelly-exporter.selectorLabels" . }}
|
||||
app.kubernetes.io/version: {{ (default .Chart.AppVersion .Values.image.tag) | quote }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "shelly-exporter.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "shelly-exporter.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "shelly-exporter.secretName" -}}
|
||||
{{- default (include "shelly-exporter.fullname" .) .Values.mqtt.existingSecret }}
|
||||
{{- end }}
|
||||
110
charts/shelly-prometheus-exporter/templates/deployment.yaml
Normal file
110
charts/shelly-prometheus-exporter/templates/deployment.yaml
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
{{- if and (not .Values.mqtt.topics) (not .Values.mqtt.wildcardTopic) }}
|
||||
{{- fail "at least one of mqtt.topics or mqtt.wildcardTopic is required" }}
|
||||
{{- end }}
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "shelly-exporter.fullname" . }}
|
||||
labels:
|
||||
{{- include "shelly-exporter.labels" . | nindent 4 }}
|
||||
spec:
|
||||
# A single replica only: multiple instances would fight over the MQTT client ID
|
||||
replicas: 1
|
||||
strategy:
|
||||
type: Recreate
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "shelly-exporter.selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
annotations:
|
||||
{{- if not .Values.mqtt.existingSecret }}
|
||||
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
|
||||
{{- end }}
|
||||
{{- with .Values.podAnnotations }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "shelly-exporter.selectorLabels" . | nindent 8 }}
|
||||
{{- with .Values.podLabels }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
automountServiceAccountToken: false
|
||||
securityContext:
|
||||
{{- toYaml .Values.podSecurityContext | nindent 8 }}
|
||||
containers:
|
||||
- name: exporter
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
{{- with .Values.image.pullPolicy }}
|
||||
imagePullPolicy: {{ . }}
|
||||
{{- end }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.securityContext | nindent 12 }}
|
||||
env:
|
||||
- name: LISTEN_ADDRESS
|
||||
value: ":{{ .Values.service.port }}"
|
||||
- name: LOG_LEVEL
|
||||
value: {{ .Values.logLevel | quote }}
|
||||
- name: MQTT_BROKER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "shelly-exporter.secretName" . }}
|
||||
key: {{ .Values.mqtt.existingSecretKeys.broker }}
|
||||
- name: MQTT_USERNAME
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "shelly-exporter.secretName" . }}
|
||||
key: {{ .Values.mqtt.existingSecretKeys.username }}
|
||||
optional: true
|
||||
- name: MQTT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ include "shelly-exporter.secretName" . }}
|
||||
key: {{ .Values.mqtt.existingSecretKeys.password }}
|
||||
optional: true
|
||||
- name: MQTT_CLIENT_ID
|
||||
value: {{ default (include "shelly-exporter.fullname" .) .Values.mqtt.clientId | quote }}
|
||||
- name: MQTT_QOS
|
||||
value: {{ .Values.mqtt.qos | quote }}
|
||||
{{- with .Values.mqtt.topics }}
|
||||
- name: MQTT_TOPICS
|
||||
value: {{ join "," . | quote }}
|
||||
{{- end }}
|
||||
{{- with .Values.mqtt.wildcardTopic }}
|
||||
- name: MQTT_WILDCARD_TOPIC
|
||||
value: {{ . | quote }}
|
||||
{{- end }}
|
||||
{{- with .Values.extraEnv }}
|
||||
{{- toYaml . | nindent 12 }}
|
||||
{{- end }}
|
||||
ports:
|
||||
- name: metrics
|
||||
containerPort: {{ .Values.service.port }}
|
||||
protocol: TCP
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /metrics
|
||||
port: metrics
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /metrics
|
||||
port: metrics
|
||||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
17
charts/shelly-prometheus-exporter/templates/secret.yaml
Normal file
17
charts/shelly-prometheus-exporter/templates/secret.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{{- if not .Values.mqtt.existingSecret }}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: {{ include "shelly-exporter.fullname" . }}
|
||||
labels:
|
||||
{{- include "shelly-exporter.labels" . | nindent 4 }}
|
||||
type: Opaque
|
||||
stringData:
|
||||
{{ .Values.mqtt.existingSecretKeys.broker }}: {{ required "mqtt.broker or mqtt.existingSecret is required" .Values.mqtt.broker | quote }}
|
||||
{{- with .Values.mqtt.username }}
|
||||
{{ $.Values.mqtt.existingSecretKeys.username }}: {{ . | quote }}
|
||||
{{- end }}
|
||||
{{- with .Values.mqtt.password }}
|
||||
{{ $.Values.mqtt.existingSecretKeys.password }}: {{ . | quote }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
15
charts/shelly-prometheus-exporter/templates/service.yaml
Normal file
15
charts/shelly-prometheus-exporter/templates/service.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "shelly-exporter.fullname" . }}
|
||||
labels:
|
||||
{{- include "shelly-exporter.labels" . | nindent 4 }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- name: metrics
|
||||
port: {{ .Values.service.port }}
|
||||
targetPort: metrics
|
||||
protocol: TCP
|
||||
selector:
|
||||
{{- include "shelly-exporter.selectorLabels" . | nindent 4 }}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
{{- if .Values.serviceMonitor.enabled }}
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
metadata:
|
||||
name: {{ include "shelly-exporter.fullname" . }}
|
||||
labels:
|
||||
{{- include "shelly-exporter.labels" . | nindent 4 }}
|
||||
{{- with .Values.serviceMonitor.labels }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "shelly-exporter.selectorLabels" . | nindent 6 }}
|
||||
endpoints:
|
||||
- port: metrics
|
||||
path: /metrics
|
||||
interval: {{ .Values.serviceMonitor.interval }}
|
||||
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
|
||||
{{- with .Values.serviceMonitor.relabelings }}
|
||||
relabelings:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.serviceMonitor.metricRelabelings }}
|
||||
metricRelabelings:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
79
charts/shelly-prometheus-exporter/values.yaml
Normal file
79
charts/shelly-prometheus-exporter/values.yaml
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
image:
|
||||
repository: jonasled.dev/jonasled/shelly-prometheus-exporter
|
||||
# Defaults to the chart appVersion
|
||||
tag: ""
|
||||
# Empty uses the Kubernetes default (Always for "latest", IfNotPresent otherwise)
|
||||
pullPolicy: ""
|
||||
|
||||
imagePullSecrets: []
|
||||
nameOverride: ""
|
||||
fullnameOverride: ""
|
||||
|
||||
mqtt:
|
||||
# Inline connection settings. Ignored when existingSecret is set.
|
||||
# Broker URL, e.g. tcp://192.168.1.10:1883 or ssl://broker:8883
|
||||
broker: ""
|
||||
# Leave username/password empty for brokers without authentication
|
||||
username: ""
|
||||
password: ""
|
||||
|
||||
# Use an existing secret instead of the inline values above.
|
||||
# The username and password keys are optional in the secret.
|
||||
existingSecret: ""
|
||||
existingSecretKeys:
|
||||
broker: MQTT_BROKER
|
||||
username: MQTT_USERNAME
|
||||
password: MQTT_PASSWORD
|
||||
|
||||
# Defaults to the release fullname. Must be unique per broker.
|
||||
clientId: ""
|
||||
qos: 0
|
||||
# Explicit device topic prefixes, e.g. [shellyplussmoke-halle-2]
|
||||
topics: []
|
||||
# Topic prefix with MQTT wildcard, e.g. "+" or "shellies/+"
|
||||
wildcardTopic: ""
|
||||
|
||||
# ERROR, WARN, INFO or DEBUG
|
||||
logLevel: INFO
|
||||
|
||||
# Additional environment variables for the container
|
||||
extraEnv: []
|
||||
|
||||
service:
|
||||
type: ClusterIP
|
||||
port: 9784
|
||||
|
||||
serviceMonitor:
|
||||
enabled: true
|
||||
interval: 30s
|
||||
scrapeTimeout: 10s
|
||||
# Additional labels, e.g. to match the serviceMonitorSelector of your Prometheus
|
||||
labels: {}
|
||||
relabelings: []
|
||||
metricRelabelings: []
|
||||
|
||||
podAnnotations: {}
|
||||
podLabels: {}
|
||||
|
||||
podSecurityContext:
|
||||
runAsNonRoot: true
|
||||
seccompProfile:
|
||||
type: RuntimeDefault
|
||||
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
readOnlyRootFilesystem: true
|
||||
capabilities:
|
||||
drop:
|
||||
- ALL
|
||||
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 16Mi
|
||||
limits:
|
||||
memory: 64Mi
|
||||
|
||||
nodeSelector: {}
|
||||
tolerations: []
|
||||
affinity: {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue