From 9c6371bdd964c756407bed9a47ff1dcdd3cd8166 Mon Sep 17 00:00:00 2001 From: merlindorin Date: Sat, 2 Mar 2024 21:46:15 +0100 Subject: [PATCH] feat: add helm chart --- helm/exporter-unifi-protect/Chart.yaml | 2 +- .../templates/deployment.yaml | 46 +++++++--- .../templates/metrics/podmonitor.yaml | 45 +++++++++ .../templates/metrics/prometheusrule.yaml | 19 ++++ .../templates/metrics/service.yaml | 21 +++++ .../templates/metrics/servicemonitor.yaml | 45 +++++++++ helm/exporter-unifi-protect/values.yaml | 92 ++++++++++++++++++- 7 files changed, 257 insertions(+), 13 deletions(-) create mode 100644 helm/exporter-unifi-protect/templates/metrics/podmonitor.yaml create mode 100644 helm/exporter-unifi-protect/templates/metrics/prometheusrule.yaml create mode 100644 helm/exporter-unifi-protect/templates/metrics/service.yaml create mode 100644 helm/exporter-unifi-protect/templates/metrics/servicemonitor.yaml diff --git a/helm/exporter-unifi-protect/Chart.yaml b/helm/exporter-unifi-protect/Chart.yaml index 98befb7..8810499 100644 --- a/helm/exporter-unifi-protect/Chart.yaml +++ b/helm/exporter-unifi-protect/Chart.yaml @@ -21,4 +21,4 @@ version: 0.1.0 # 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: "v0.0.2" +appVersion: "v0.0.5" diff --git a/helm/exporter-unifi-protect/templates/deployment.yaml b/helm/exporter-unifi-protect/templates/deployment.yaml index 6cb5b7d..095e131 100644 --- a/helm/exporter-unifi-protect/templates/deployment.yaml +++ b/helm/exporter-unifi-protect/templates/deployment.yaml @@ -37,26 +37,50 @@ spec: image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: - - name: HOST - value: xxx - - name: PASSWORD - value: yyy - - name: USERNAME - value: eeee + {{- if .Values.unifi.host.secretName }} + - name: UNIFI_HOST + valueFrom: + secretKeyRef: + name: {{ .Values.unifi.host.secretName | quote }} + key: {{ .Values.unifi.host.secretKey | default "host" | quote }} + {{- else if .Values.unifi.host.raw}} + - name: UNIFI_HOST + value: {{ .Values.unifi.host.raw | quote }} + {{- end }} + {{- if .Values.unifi.password.secretName }} + - name: UNIFI_PASSWORD + valueFrom: + secretKeyRef: + name: {{ .Values.unifi.password.secretName | quote }} + key: {{ .Values.unifi.password.secretKey | default "password" | quote }} + {{- else if .Values.unifi.password.raw}} + - name: UNIFI_PASSWORD + value: {{ .Values.unifi.password.raw | quote }} + {{- end }} + {{- if .Values.unifi.username.secretName }} + - name: UNIFI_USERNAME + valueFrom: + secretKeyRef: + name: {{ .Values.unifi.username.secretName | quote }} + key: {{ .Values.unifi.username.secretKey | default "username" | quote }} + {{- else if .Values.unifi.username.raw}} + - name: UNIFI_USERNAME + value: {{ .Values.unifi.username.raw }} + {{- end }} - name: DEBUG - value: "true" + value: {{ .Values.debug | quote }} ports: - name: http containerPort: {{ .Values.service.port }} protocol: TCP livenessProbe: httpGet: - path: / - port: http + path: /-/healthy + port: {{ .Values.service.port }} readinessProbe: httpGet: - path: / - port: http + path: /-/healthy + port: {{ .Values.service.port }} resources: {{- toYaml .Values.resources | nindent 12 }} {{- with .Values.volumeMounts }} diff --git a/helm/exporter-unifi-protect/templates/metrics/podmonitor.yaml b/helm/exporter-unifi-protect/templates/metrics/podmonitor.yaml new file mode 100644 index 0000000..9d10d95 --- /dev/null +++ b/helm/exporter-unifi-protect/templates/metrics/podmonitor.yaml @@ -0,0 +1,45 @@ +{{- if and (.Values.metrics.enabled) (.Values.metrics.podMonitor.enabled) }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ template "exporter-unifi-protect.fullname" . }} + namespace: {{ .Values.metrics.podMonitor.namespace | default .Release.Namespace | quote }} + labels: + {{- include "exporter-unifi-protect.labels" . | nindent 4 }} + {{- with .Values.metrics.podMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + podMetricsEndpoints: + - port: http-metrics + {{- if .Values.metrics.podMonitor.honorLabels }} + honorLabels: {{ .Values.metrics.podMonitor.honorLabels }} + {{- end }} + {{- if .Values.metrics.podMonitor.interval }} + interval: {{ .Values.metrics.podMonitor.interval | quote }} + {{- end }} + {{- with .Values.metrics.podMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + path: {{ .Values.metrics.podMonitor.path | quote }} + {{- with .Values.metrics.podMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.metrics.podMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.metrics.podMonitor.scrapeTimeout | quote }} + {{- end }} + {{- if .Values.metrics.podMonitor.jobLabel }} + jobLabel: {{ .Values.metrics.podMonitor.jobLabel | quote }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace | quote }} + selector: + matchLabels: + {{- include "exporter-unifi-protect.selectorLabels" . | nindent 6 }} + {{- with .Values.metrics.podMonitor.selector }} + {{- toYaml . | nindent 6 }} + {{- end }} +{{- end }} diff --git a/helm/exporter-unifi-protect/templates/metrics/prometheusrule.yaml b/helm/exporter-unifi-protect/templates/metrics/prometheusrule.yaml new file mode 100644 index 0000000..e25810f --- /dev/null +++ b/helm/exporter-unifi-protect/templates/metrics/prometheusrule.yaml @@ -0,0 +1,19 @@ +{{- if and (.Values.metrics.enabled) (.Values.metrics.prometheusRule.enabled) }} +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: {{ template "exporter-unifi-protect.fullname" . }} + namespace: {{ .Values.metrics.prometheusRule.namespace | default .Release.Namespace | quote }} + labels: + {{- include "exporter-unifi-protect.labels" . | nindent 4 }} + {{- with .Values.metrics.prometheusRule.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + groups: + - name: {{ include "exporter-unifi-protect.fullname" . }} + rules: + {{- with .Values.metrics.prometheusRule.rules }} + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/helm/exporter-unifi-protect/templates/metrics/service.yaml b/helm/exporter-unifi-protect/templates/metrics/service.yaml new file mode 100644 index 0000000..946f20b --- /dev/null +++ b/helm/exporter-unifi-protect/templates/metrics/service.yaml @@ -0,0 +1,21 @@ +{{- if .Values.metrics.enabled }} +apiVersion: v1 +kind: Service +metadata: + {{- if .Values.metrics.service.annotations }} + annotations: + {{- tpl (toYaml .Values.metrics.service.annotations) . | nindent 4 }} + {{- end }} + name: {{ include "exporter-unifi-protect.fullname" . }}-metrics + labels: + {{- include "exporter-unifi-protect.labels" . | nindent 4 }} +spec: + type: ClusterIP + ports: + - port: {{ .Values.metrics.service.port }} + targetPort: http + protocol: TCP + name: http-metrics + selector: + {{- include "exporter-unifi-protect.selectorLabels" . | nindent 4 }} +{{- end }} diff --git a/helm/exporter-unifi-protect/templates/metrics/servicemonitor.yaml b/helm/exporter-unifi-protect/templates/metrics/servicemonitor.yaml new file mode 100644 index 0000000..74df398 --- /dev/null +++ b/helm/exporter-unifi-protect/templates/metrics/servicemonitor.yaml @@ -0,0 +1,45 @@ +{{- if and (.Values.metrics.enabled) (.Values.metrics.serviceMonitor.enabled) }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "exporter-unifi-protect.fullname" . }} + namespace: {{ .Values.metrics.serviceMonitor.namespace | default .Release.Namespace | quote }} + labels: + {{- include "exporter-unifi-protect.labels" . | nindent 4 }} + {{- with .Values.metrics.serviceMonitor.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + endpoints: + - port: http-metrics + {{- if .Values.metrics.serviceMonitor.honorLabels }} + honorLabels: {{ .Values.metrics.serviceMonitor.honorLabels }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.interval }} + interval: {{ .Values.metrics.serviceMonitor.interval | quote }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + path: {{ .Values.metrics.serviceMonitor.path | quote }} + {{- with .Values.metrics.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout | quote }} + {{- end }} + {{- if .Values.metrics.serviceMonitor.jobLabel }} + jobLabel: {{ .Values.metrics.serviceMonitor.jobLabel | quote }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace | quote }} + selector: + matchLabels: + {{- include "exporter-unifi-protect.selectorLabels" . | nindent 6 }} + {{- with .Values.metrics.serviceMonitor.selector }} + {{- toYaml . | nindent 6 }} + {{- end }} +{{- end }} diff --git a/helm/exporter-unifi-protect/values.yaml b/helm/exporter-unifi-protect/values.yaml index 471117c..a2e1e74 100644 --- a/helm/exporter-unifi-protect/values.yaml +++ b/helm/exporter-unifi-protect/values.yaml @@ -1,3 +1,16 @@ +debug: false + +unifi: + host: "" + password: + secretName: "" + secretKey: "" + raw: "" + username: + secretName: "" + secretKey: "" + raw: "" + # Default values for exporter-unifi-protect. # This is a YAML-formatted file. # Declare variables to be passed into your templates. @@ -41,7 +54,7 @@ securityContext: {} service: type: ClusterIP - port: 80 + port: 9090 ingress: enabled: false @@ -96,3 +109,80 @@ nodeSelector: {} tolerations: [] affinity: {} + +metrics: + # -- enable the Prometheus + enabled: false + prometheusRule: + # -- Create a PrometheusRule for Prometheus Operator + enabled: false + # -- Additional labels that can be used so PrometheusRule will be discovered by Prometheus + additionalLabels: {} + # -- Namespace for the PrometheusRule Resource (defaults to the Release Namespace) + namespace: "" + # -- PrometheusRule definitions + rules: [] + # - alert: PrometheusConfigReloadFailed + # annotations: + # description: Reloading Prometheus' configuration has failed for {{`{{`}}$labels.namespace{{`}}`}}/{{`{{`}}$labels.pod{{`}}`}} + # summary: Reloading Prometheus' configuration failed + # expr: prometheus_config_last_reload_successful{job="{{ $prometheusJob }}",namespace="{{ $namespace }}"} == 0 + # for: 10m + # labels: + # severity: warning + service: + # -- Annotations for Prometheus to auto-discover the metrics endpoint + # @default -- see [values.yaml](./values.yaml) + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "{{ .Values.metrics.service.port }}" + # -- Prometheus Exporter service port + port: 9090 + # -- Control where client requests go, to the same pod or round-robin. Values: ClientIP or None + sessionAffinity: None + serviceMonitor: + # -- Create ServiceMonitor Resource for scraping metrics using Prometheus Operator + enabled: true + # -- Additional labels that can be used so ServiceMonitor will be discovered by Prometheus + additionalLabels: {} + # -- Specify honorLabels parameter to add the scrape endpoint + honorLabels: false + # -- Interval at which metrics should be scraped. + interval: "30s" + # -- The name of the label on the target service to use as the job name in Prometheus + jobLabel: "" + # -- MetricRelabelConfigs to apply to samples before ingestion + metricRelabelings: {} + # -- Namespace for the ServiceMonitor Resource (defaults to the Release Namespace) + namespace: "" + # -- The path used by Prometheus to scrape metrics + path: "/metrics" + # -- RelabelConfigs to apply to samples before scraping + relabelings: {} + # -- Timeout after which the scrape is ended + scrapeTimeout: "" + # -- Prometheus instance selector labels + selector: {} + podMonitor: + # -- Create PodMonitor Resource for scraping metrics using Prometheus Operator + enabled: false + # -- Additional labels that can be used so ServiceMonitor will be discovered by Prometheus + additionalLabels: {} + # -- Specify honorLabels parameter to add the scrape endpoint + honorLabels: false + # -- Interval at which metrics should be scraped. + interval: "30s" + # -- The name of the label on the target service to use as the job name in Prometheus + jobLabel: "" + # -- MetricRelabelConfigs to apply to samples before ingestion + metricRelabelings: {} + # -- Namespace for the ServiceMonitor Resource (defaults to the Release Namespace) + namespace: "" + # -- The path used by Prometheus to scrape metrics + path: "/metrics" + # -- RelabelConfigs to apply to samples before scraping + relabelings: {} + # -- Timeout after which the scrape is ended + scrapeTimeout: "" + # -- Prometheus instance selector labels + selector: {}