From ee113fef8c6f84f2c1857acbe299bca20c9dbe96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Dunand?= Date: Tue, 11 Feb 2025 15:55:15 +0100 Subject: [PATCH] feat(zfs-exporter): added zfs-exporter helm chart --- charts/zfs-exporter/.helmignore | 23 +++++ charts/zfs-exporter/Chart.yaml | 6 ++ charts/zfs-exporter/templates/NOTES.txt | 1 + charts/zfs-exporter/templates/_helpers.tpl | 62 +++++++++++++ charts/zfs-exporter/templates/configmap.yaml | 25 ++++++ charts/zfs-exporter/templates/daemonset.yaml | 87 +++++++++++++++++++ charts/zfs-exporter/templates/service.yaml | 16 ++++ .../templates/serviceaccount.yaml | 12 +++ .../templates/servicemonitor.yaml | 16 ++++ charts/zfs-exporter/values.yaml | 48 ++++++++++ 10 files changed, 296 insertions(+) create mode 100644 charts/zfs-exporter/.helmignore create mode 100644 charts/zfs-exporter/Chart.yaml create mode 100644 charts/zfs-exporter/templates/NOTES.txt create mode 100644 charts/zfs-exporter/templates/_helpers.tpl create mode 100644 charts/zfs-exporter/templates/configmap.yaml create mode 100644 charts/zfs-exporter/templates/daemonset.yaml create mode 100644 charts/zfs-exporter/templates/service.yaml create mode 100644 charts/zfs-exporter/templates/serviceaccount.yaml create mode 100644 charts/zfs-exporter/templates/servicemonitor.yaml create mode 100644 charts/zfs-exporter/values.yaml diff --git a/charts/zfs-exporter/.helmignore b/charts/zfs-exporter/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/zfs-exporter/.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/zfs-exporter/Chart.yaml b/charts/zfs-exporter/Chart.yaml new file mode 100644 index 0000000..0ee6ab2 --- /dev/null +++ b/charts/zfs-exporter/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: zfs-exporter +description: A Helm chart of https://github.com/pdf/zfs_exporter for Kubernetes +type: application +version: "1.1.0" +appVersion: "v2.3.4" diff --git a/charts/zfs-exporter/templates/NOTES.txt b/charts/zfs-exporter/templates/NOTES.txt new file mode 100644 index 0000000..d0b12f6 --- /dev/null +++ b/charts/zfs-exporter/templates/NOTES.txt @@ -0,0 +1 @@ +Zfs-exporter deployed. diff --git a/charts/zfs-exporter/templates/_helpers.tpl b/charts/zfs-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..5b16a24 --- /dev/null +++ b/charts/zfs-exporter/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "zfs-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 "zfs-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 "zfs-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "zfs-exporter.labels" -}} +helm.sh/chart: {{ include "zfs-exporter.chart" . }} +{{ include "zfs-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "zfs-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "zfs-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "zfs-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "zfs-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/zfs-exporter/templates/configmap.yaml b/charts/zfs-exporter/templates/configmap.yaml new file mode 100644 index 0000000..02b11db --- /dev/null +++ b/charts/zfs-exporter/templates/configmap.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + {{- include "zfs-exporter.labels" . | nindent 4 }} + name: zfspv-bin +data: + zfs: | + #!/bin/sh + if [ -x /host/sbin/zfs ]; then + chroot /host /sbin/zfs "$@" + elif [ -x /host/usr/sbin/zfs ]; then + chroot /host /usr/sbin/zfs "$@" + else + chroot /host "zfs" "$@" + fi + zpool: | + #!/bin/sh + if [ -x /host/sbin/zpool ]; then + chroot /host /sbin/zpool "$@" + elif [ -x /host/usr/sbin/zpool ]; then + chroot /host /usr/sbin/zpool "$@" + else + chroot /host "zpool" "$@" + fi diff --git a/charts/zfs-exporter/templates/daemonset.yaml b/charts/zfs-exporter/templates/daemonset.yaml new file mode 100644 index 0000000..2c0aa74 --- /dev/null +++ b/charts/zfs-exporter/templates/daemonset.yaml @@ -0,0 +1,87 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ include "zfs-exporter.fullname" . }} + labels: + {{- include "zfs-exporter.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "zfs-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "zfs-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "zfs-exporter.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- with .Values.priorityClassName }} + priorityClassName: {{ . | quote }} + {{- end }} + 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: 9134 + hostPort: 9134 + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + volumeMounts: + - name: device-dir + mountPath: /dev + - name: chroot-zfs + mountPath: /sbin/zfs + subPath: zfs + - name: chroot-zfs + mountPath: /sbin/zpool + subPath: zpool + - name: host-root + mountPath: /host + mountPropagation: "HostToContainer" + readOnly: true + 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 }} + volumes: + - hostPath: + path: /dev + type: Directory + name: device-dir + - configMap: + defaultMode: 365 + name: zfspv-bin + name: chroot-zfs + - hostPath: + path: / + type: Directory + name: host-root diff --git a/charts/zfs-exporter/templates/service.yaml b/charts/zfs-exporter/templates/service.yaml new file mode 100644 index 0000000..18ca8c7 --- /dev/null +++ b/charts/zfs-exporter/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "zfs-exporter.fullname" . }} + labels: + {{- include "zfs-exporter.labels" . | nindent 4 }} +spec: + type: ClusterIP + port: 9134 + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "zfs-exporter.selectorLabels" . | nindent 4 }} diff --git a/charts/zfs-exporter/templates/serviceaccount.yaml b/charts/zfs-exporter/templates/serviceaccount.yaml new file mode 100644 index 0000000..5485919 --- /dev/null +++ b/charts/zfs-exporter/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "zfs-exporter.serviceAccountName" . }} + labels: + {{- include "zfs-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/zfs-exporter/templates/servicemonitor.yaml b/charts/zfs-exporter/templates/servicemonitor.yaml new file mode 100644 index 0000000..3bf7570 --- /dev/null +++ b/charts/zfs-exporter/templates/servicemonitor.yaml @@ -0,0 +1,16 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + {{- include "zfs-exporter.labels" . | nindent 4 }} + {{- with .Values.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + name: {{ include "zfs-exporter.fullname" . }} +spec: + endpoints: + - port: http + scheme: http + selector: + matchLabels: + {{- include "zfs-exporter.selectorLabels" . | nindent 6 }} diff --git a/charts/zfs-exporter/values.yaml b/charts/zfs-exporter/values.yaml new file mode 100644 index 0000000..30f9758 --- /dev/null +++ b/charts/zfs-exporter/values.yaml @@ -0,0 +1,48 @@ +image: + repository: enix/zfs-exporter + pullPolicy: IfNotPresent + tag: "v2.3.4" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + +securityContext: + privileged: true + allowPrivilegeEscalation: true + +service: + type: ClusterIP + port: 9134 + +resources: + limits: + cpu: 100m + memory: 64Mi + requests: + cpu: 30m + memory: 64Mi + +priorityClassName: "" + +nodeSelector: {} + +tolerations: {} + +affinity: {} + +serviceMonitor: + additionalLabels: {}