Skip to content

Commit

Permalink
feat: add ServiceMonitor support kedacore#339
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaked committed Jan 4, 2023
1 parent 839a0be commit f1a850a
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
51 changes: 51 additions & 0 deletions keda/templates/17-keda-servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{- if and .Values.prometheus.operator.enabled .Values.prometheus.operator.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ .Values.operator.name }}
annotations:
{{- toYaml .Values.additionalAnnotations | nindent 4 }}
labels:
app.kubernetes.io/name: {{ .Values.operator.name }}
{{- include "keda.labels" . | indent 4 }}
{{- range $key, $value := .Values.prometheus.operator.serviceMonitor.additionalLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- with .Values.prometheus.operator.serviceMonitor.namespace }}
namespace: {{ . }}
{{- end }}
spec:
{{- with .Values.prometheus.operator.serviceMonitor.jobLabel }}
jobLabel: {{ . }}
{{- end }}
{{- with .Values.prometheus.operator.serviceMonitor.targetLabels }}
targetLabels:
{{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.prometheus.operator.serviceMonitor.podTargetLabels }}
podTargetLabels:
{{ toYaml . | indent 4 }}
{{- end }}
endpoints:
- port: {{ .Values.prometheus.operator.serviceMonitor.port }}
{{- with .Values.prometheus.operator.serviceMonitor.targetPort }}
targetPort: {{ . }}
{{- end }}
path: {{ .Values.prometheus.operator.serviceMonitor.path }}
{{- with .Values.prometheus.operator.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.prometheus.operator.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
{{- with .Values.prometheus.operator.serviceMonitor.relabellings }}
relabelings:
{{ toYaml . | indent 6 }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
app.kubernetes.io/name: {{ .Values.operator.name }}
{{- end }}
2 changes: 1 addition & 1 deletion keda/templates/22-metrics-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
{{- if .Values.additionalAnnotations }}
{{- toYaml .Values.additionalAnnotations | nindent 8 }}
{{- end }}
{{- if and .Values.prometheus.metricServer.enabled ( not .Values.prometheus.metricServer.podMonitor.enabled ) }}
{{- if and .Values.prometheus.metricServer.enabled ( not (and .Values.prometheus.metricServer.podMonitor.enabled .Values.prometheus.metricServer.serviceMonitor.enabled )) }}
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.prometheus.metricServer.port | quote }}
prometheus.io/path: {{ .Values.prometheus.metricServer.path }}
Expand Down
1 change: 1 addition & 0 deletions keda/templates/23-metrics-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: Service
metadata:
labels:
app.kubernetes.io/name: {{ .Values.operator.name }}-metrics-apiserver
app: {{ .Values.operator.name }}-metrics-apiserver
{{- include "keda.labels" . | indent 4 }}
name: {{ .Values.operator.name }}-metrics-apiserver
namespace: {{ .Release.Namespace }}
Expand Down
51 changes: 51 additions & 0 deletions keda/templates/27-metrics-servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{- if and .Values.prometheus.metricServer.enabled .Values.prometheus.metricServer.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ .Values.operator.name }}-metrics-apiserver
annotations:
{{- toYaml .Values.additionalAnnotations | nindent 4 }}
labels:
app.kubernetes.io/name: {{ .Values.operator.name }}
{{- include "keda.labels" . | indent 4 }}
{{- range $key, $value := .Values.prometheus.metricServer.serviceMonitor.additionalLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- with .Values.prometheus.metricServer.serviceMonitor.namespace }}
namespace: {{ . }}
{{- end }}
spec:
{{- with .Values.prometheus.metricServer.serviceMonitor.jobLabel }}
jobLabel: {{ . }}
{{- end }}
{{- with .Values.prometheus.metricServer.serviceMonitor.targetLabels }}
targetLabels:
{{ toYaml . | indent 4 }}
{{- end }}
{{- with .Values.prometheus.metricServer.serviceMonitor.podTargetLabels }}
podTargetLabels:
{{ toYaml . | indent 4 }}
{{- end }}
endpoints:
- port: {{ .Values.prometheus.metricServer.serviceMonitor.port }}
{{- with .Values.prometheus.metricServer.serviceMonitor.targetPort }}
targetPort: {{ . }}
{{- end }}
path: {{ .Values.prometheus.metricServer.serviceMonitor.path }}
{{- with .Values.prometheus.metricServer.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.prometheus.metricServer.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
{{- with .Values.prometheus.metricServer.serviceMonitor.relabellings }}
relabelings:
{{ toYaml . | indent 6 }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
app.kubernetes.io/name: {{ .Values.operator.name }}-metrics-apiserver
{{- end }}
26 changes: 26 additions & 0 deletions keda/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ prometheus:
port: 9022
portName: metrics
path: /metrics
serviceMonitor:
# Enables ServiceMonitor creation for the Prometheus Operator
enabled: false
jobLabel:
targetLabels: []
podTargetLabels: []
port: metrics
targetPort:
path: /metrics
interval:
scrapeTimeout:
relabellings: []
additionalLabels: {}
podMonitor:
# Enables PodMonitor creation for the Prometheus Operator
enabled: false
Expand All @@ -299,6 +312,19 @@ prometheus:
operator:
enabled: false
port: 8080
serviceMonitor:
# Enables ServiceMonitor creation for the Prometheus Operator
enabled: false
jobLabel:
targetLabels: []
podTargetLabels: []
port: metrics
targetPort:
path: /metrics
interval:
scrapeTimeout:
relabellings: []
additionalLabels: {}
podMonitor:
# Enables PodMonitor creation for the Prometheus Operator
enabled: false
Expand Down

0 comments on commit f1a850a

Please sign in to comment.