Skip to content

Commit

Permalink
Merge pull request #41 from eminaktas/fix/helm-metric
Browse files Browse the repository at this point in the history
fix(helm): fixes metric endpoint
  • Loading branch information
eminaktas authored Oct 31, 2024
2 parents 4cf0d3f + 746afb7 commit 886c38c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
1 change: 1 addition & 0 deletions chart/kubedns-shepherd/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ include "prometheus.enabledCheck" . }}
11 changes: 10 additions & 1 deletion chart/kubedns-shepherd/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Create the name of the service account to use
{{/*
Leader Election
*/}}
{{- define "kubedns-shepherd.leaderElection"}}
{{- define "kubedns-shepherd.leaderElection" -}}
{{- if .Values.leaderElection -}}
- --leader-elect={{ .Values.leaderElection.enabled }}
{{- if .Values.leaderElection.leaseDuration }}
Expand All @@ -85,3 +85,12 @@ Leader Election
- --leader-elect-resource-namespace={{ .Release.Namespace }}
{{- end }}
{{- end }}

{{/*
Prometheus
*/}}
{{- define "prometheus.enabledCheck" -}}
{{- if and (not .Values.prometheus.enabled) .Values.prometheus.serviceMonitor.enabled -}}
{{- printf "Warning: To enable metric scraping, please set prometheus.enabled to true, as serviceMonitor.enabled is currently set to true." }}
{{- end -}}
{{- end -}}
13 changes: 10 additions & 3 deletions chart/kubedns-shepherd/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ spec:
{{- include "chart.selectorLabels" . | nindent 8 }}
annotations:
kubectl.kubernetes.io/default-container: controller
{{- if and .Values.prometheus.enabled (not .Values.prometheus.serviceMonitor.enabled) }}
prometheus.io/port: {{ .Values.prometheus.port | quote }}
prometheus.io/scrape: "true"
{{- end }}
spec:
containers:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
{{- if .Values.prometheus.enabled }}
- --metrics-bind-address=:{{ .Values.prometheus.port }}
{{- end }}
{{- include "kubedns-shepherd.leaderElection" . | nindent 8 }}
{{- with .Values.extraArgs }}
{{- toYaml . | nindent 8 }}
Expand All @@ -44,9 +49,11 @@ spec:
- containerPort: 9443
name: webhook
protocol: TCP
- containerPort: 8080
{{- if .Values.prometheus.enabled }}
- containerPort: {{ .Values.prometheus.port }}
name: metrics
protocol: TCP
{{- end }}
- containerPort: 8081
name: probe
protocol: TCP
Expand Down
5 changes: 4 additions & 1 deletion chart/kubedns-shepherd/templates/metrics-service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if and .Values.prometheus.enabled .Values.prometheus.serviceMonitor.enabled }}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -6,6 +7,7 @@ metadata:
labels:
app.kubernetes.io/component: metrics
app.kubernetes.io/part-of: kubedns-shepherd
service: metrics-service
{{- include "chart.labels" . | nindent 4 }}
spec:
clusterIP: None
Expand All @@ -15,6 +17,7 @@ spec:
{{- include "chart.selectorLabels" . | nindent 4 }}
ports:
- name: metrics
port: 8080
port: {{ .Values.prometheus.port }}
protocol: TCP
targetPort: metrics
{{- end }}
33 changes: 25 additions & 8 deletions chart/kubedns-shepherd/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
{{- if .Values.serviceMonitor.enabled }}
{{- if and .Values.prometheus.enabled .Values.prometheus.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "chart.fullname" . }}-metrics-monitor
namespace: {{ .Release.Namespace }}
namespace: {{ .Values.prometheus.serviceMonitor.namespace | default .Release.Namespace }}
labels:
app.kubernetes.io/component: metrics
app.kubernetes.io/part-of: kubedns-shepherd
control-plane: controller-manager
{{- with .Values.prometheus.serviceMonitor.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "chart.labels" . | nindent 4 }}
{{- if .Values.prometheus.serviceMonitor.annotations }}
annotations:
{{- with .Values.prometheus.serviceMonitor.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
endpoints:
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
- scheme: http
path: /metrics
port: metrics
scheme: https
tlsConfig:
insecureSkipVerify: true
interval: {{ .Values.prometheus.serviceMonitor.interval | quote }}
{{- with .Values.prometheus.serviceMonitor.relabelings }}
relabelings:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.prometheus.serviceMonitor.metricRelabelings }}
metricRelabelings:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
control-plane: controller-manager
service: metrics-service
{{- include "chart.selectorLabels" . | nindent 6 }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- end }}
10 changes: 9 additions & 1 deletion chart/kubedns-shepherd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ image:

imagePullPolicy: IfNotPresent

serviceMonitor:
prometheus:
enabled: false
port: 8080
serviceMonitor:
enabled: false
labels: {}
annotations: {}
interval: "10s"
relabelings: ~
metricRelabelings: ~

containerSecurityContext:
allowPrivilegeEscalation: false
Expand Down

0 comments on commit 886c38c

Please sign in to comment.