Skip to content

Commit

Permalink
feat: add helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
merlindorin committed Mar 2, 2024
1 parent 7ccc2e7 commit 9c6371b
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 13 deletions.
2 changes: 1 addition & 1 deletion helm/exporter-unifi-protect/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
46 changes: 35 additions & 11 deletions helm/exporter-unifi-protect/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
45 changes: 45 additions & 0 deletions helm/exporter-unifi-protect/templates/metrics/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
19 changes: 19 additions & 0 deletions helm/exporter-unifi-protect/templates/metrics/prometheusrule.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 21 additions & 0 deletions helm/exporter-unifi-protect/templates/metrics/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
45 changes: 45 additions & 0 deletions helm/exporter-unifi-protect/templates/metrics/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
92 changes: 91 additions & 1 deletion helm/exporter-unifi-protect/values.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -41,7 +54,7 @@ securityContext: {}

service:
type: ClusterIP
port: 80
port: 9090

ingress:
enabled: false
Expand Down Expand Up @@ -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: {}

0 comments on commit 9c6371b

Please sign in to comment.