Skip to content

Commit

Permalink
feat: add namespace selector for ServiceMonitor (#135)
Browse files Browse the repository at this point in the history
Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>
Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
  • Loading branch information
Aris Boutselis and arbreezy committed May 31, 2023
1 parent 1b267a6 commit 075caf5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions chart/operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create the name of the service account to use.
*/}}
{{- define "k8sgpt-operator.namespace" -}}
{{- default .Release.Namespace }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "chart.fullname" . }}-controller-manager-metrics-monitor
namespace: {{ .Values.serviceMonitor.namespace | default (include "k8sgpt-operator.namespace" . ) }}
labels:
app.kubernetes.io/component: metrics
app.kubernetes.io/created-by: k8sgpt-operator
Expand All @@ -13,6 +14,11 @@ metadata:
{{- toYaml .Values.serviceMonitor.additionalLabels | nindent 4 }}
{{- end }}
spec:
{{- if .Values.serviceMonitor.namespace }}
namespaceSelector:
matchNames:
- {{ include "k8sgpt-operator.namespace" . }}
{{- end }}
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
path: /metrics
Expand All @@ -23,4 +29,4 @@ spec:
selector:
matchLabels:
control-plane: controller-manager
{{ end -}}
{{ end -}}
2 changes: 2 additions & 0 deletions chart/operator/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
serviceMonitor:
enabled: false
additionalLabels: {}
# The namespace where Prometheus expects to find the serviceMonitor
# namespace: ""
grafanaDashboard:
enabled: false
folder:
Expand Down

0 comments on commit 075caf5

Please sign in to comment.