Skip to content

Commit

Permalink
Allow setting selectors for built-in ServiceMonitors
Browse files Browse the repository at this point in the history
This will make it easier to install the chart in environments where
resources cannot be created in the kube-system namespace, such as a
tightly scoped ArgoCD AppProject.

Without this change, to use the built-in ServiceMonitors with
service.enabled=false, the operator is expected to create services in
the kube-system namespace that have labels that exactly match what the
chart is expecting.

With this change, I can create these service resources with my own
naming conventions and labels, and inform the ServiceMonitor on how to
select them.

Signed-off-by: Andrew Titmuss <[email protected]>
  • Loading branch information
iandrewt committed Feb 28, 2024
1 parent 8847218 commit 1221e66
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion charts/kube-prometheus-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name: kube-prometheus-stack
sources:
- https://github.com/prometheus-community/helm-charts
- https://github.com/prometheus-operator/kube-prometheus
version: 56.13.1
version: 56.14.0
appVersion: v0.71.2
kubeVersion: ">=1.19.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ metadata:
{{- end }}
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
spec:
jobLabel: jobLabel
jobLabel: {{ .Values.coreDns.serviceMonitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.coreDns.serviceMonitor | nindent 2 }}
selector:
{{- if .Values.coreDns.serviceMonitor.selector }}
{{ tpl (toYaml .Values.coreDns.serviceMonitor.selector | nindent 4) . }}
{{- else }}
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-coredns
release: {{ $.Release.Name | quote }}
{{- end }}
namespaceSelector:
matchNames:
- "kube-system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ metadata:
{{- end }}
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
spec:
jobLabel: jobLabel
jobLabel: {{ .Values.kubeControllerManager.serviceMonitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.kubeControllerManager.serviceMonitor | nindent 2 }}
selector:
{{- if .Values.kubeControllerManager.serviceMonitor.selector }}
{{ tpl (toYaml .Values.kubeControllerManager.serviceMonitor.selector | nindent 4) . }}
{{- else }}
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-kube-controller-manager
release: {{ $.Release.Name | quote }}
{{- end }}
namespaceSelector:
matchNames:
- "kube-system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ metadata:
{{- end }}
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
spec:
jobLabel: jobLabel
jobLabel: {{ .Values.kubeDns.serviceMonitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.kubeDns.serviceMonitor | nindent 2 }}
selector:
{{- if .Values.kubeDns.serviceMonitor.selector }}
{{ tpl (toYaml .Values.kubeDns.serviceMonitor.selector | nindent 4) . }}
{{- else }}
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-kube-dns
release: {{ $.Release.Name | quote }}
{{- end }}
namespaceSelector:
matchNames:
- "kube-system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ metadata:
{{- end }}
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
spec:
jobLabel: jobLabel
jobLabel: {{ .Values.kubeEtcd.serviceMonitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.kubeEtcd.serviceMonitor | nindent 4 }}
selector:
{{- if .Values.kubeEtcd.serviceMonitor.selector }}
{{ tpl (toYaml .Values.kubeEtcd.serviceMonitor.selector | nindent 4) . }}
{{- else }}
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-kube-etcd
release: {{ $.Release.Name | quote }}
{{- end }}
namespaceSelector:
matchNames:
- "kube-system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ metadata:
{{- end }}
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
spec:
jobLabel: jobLabel
jobLabel: {{ .Values.kubeProxy.serviceMonitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.kubeProxy.serviceMonitor | nindent 2 }}
selector:
{{- if .Values.kubeProxy.serviceMonitor.selector }}
{{ tpl (toYaml .Values.kubeProxy.serviceMonitor.selector | nindent 4) . }}
{{- else }}
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-kube-proxy
release: {{ $.Release.Name | quote }}
{{- end }}
namespaceSelector:
matchNames:
- "kube-system"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ metadata:
{{- end }}
{{ include "kube-prometheus-stack.labels" . | indent 4 }}
spec:
jobLabel: jobLabel
jobLabel: {{ .Values.kubeScheduler.serviceMonitor.jobLabel }}
{{- include "servicemonitor.scrapeLimits" .Values.kubeScheduler.serviceMonitor | nindent 2 }}
selector:
{{- if .Values.kubeScheduler.serviceMonitor.selector }}
{{ tpl (toYaml .Values.kubeScheduler.serviceMonitor.selector | nindent 4) . }}
{{- else }}
matchLabels:
app: {{ template "kube-prometheus-stack.name" . }}-kube-scheduler
release: {{ $.Release.Name | quote }}
{{- end }}
namespaceSelector:
matchNames:
- "kube-system"
Expand Down
30 changes: 30 additions & 0 deletions charts/kube-prometheus-stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,11 @@ kubeControllerManager:
##
proxyUrl: ""

jobLabel: jobLabel
selector: {}
# matchLabels:
# component: kube-controller-manager

## Enable scraping kube-controller-manager over https.
## Requires proper certs (not self-signed) and delegated authentication/authorization checks.
## If null or unset, the value is determined dynamically based on target Kubernetes version.
Expand Down Expand Up @@ -1562,6 +1567,11 @@ coreDns:
##
proxyUrl: ""

jobLabel: jobLabel
selector: {}
# matchLabels:
# k8s-app: kube-dns

## MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
##
Expand Down Expand Up @@ -1628,6 +1638,11 @@ kubeDns:
##
proxyUrl: ""

jobLabel: jobLabel
selector: {}
# matchLabels:
# k8s-app: kube-dns

## MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
##
Expand Down Expand Up @@ -1739,6 +1754,11 @@ kubeEtcd:
certFile: ""
keyFile: ""

jobLabel: jobLabel
selector: {}
# matchLabels:
# component: etcd

## MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
##
Expand Down Expand Up @@ -1822,6 +1842,11 @@ kubeScheduler:
##
https: null

jobLabel: jobLabel
selector: {}
# matchLabels:
# component: kube-scheduler

## Skip TLS certificate validation when scraping
insecureSkipVerify: null

Expand Down Expand Up @@ -1901,6 +1926,11 @@ kubeProxy:
##
proxyUrl: ""

jobLabel: jobLabel
selector: {}
# matchLabels:
# k8s-app: kube-proxy

## Enable scraping kube-proxy over https.
## Requires proper certs (not self-signed) and delegated authentication/authorization checks
##
Expand Down

0 comments on commit 1221e66

Please sign in to comment.