Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chart] Policy Reporter ServiceMonitor Missing Namespace Selector #283

Closed
aballman opened this issue Mar 29, 2023 · 4 comments · Fixed by #286
Closed

[Chart] Policy Reporter ServiceMonitor Missing Namespace Selector #283

aballman opened this issue Mar 29, 2023 · 4 comments · Fixed by #286

Comments

@aballman
Copy link

The template here allows you to specify a different namespace for the service monitor.

namespace: {{ include "monitoring.smNamespace" . }}

The monitoring.smNamespace helper allows you to specify a namespace other than the .Release.Namespace or .Values.global.namespace

{{/* Get the namespace name. */}}
{{- define "monitoring.smNamespace" -}}
{{- if .Values.serviceMonitor.namespace -}}
{{- .Values.serviceMonitor.namespace -}}
{{- else if .Values.global.namespace -}}
{{- .Values.global.namespace -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end }}

The problem being that if you do specify a different namespace than the release namespace, the service monitor will be missing anamespaceSelector in the spec that's a requirement if the serviceMonitor isn't in the same namespace as the service/endpoint

spec:
selector:
matchLabels:
{{- include "policyreporter.selectorLabels" . | nindent 8 }}
endpoints:
- port: http
honorLabels: {{ .Values.serviceMonitor.honorLabels }}
relabelings:
- action: labeldrop
regex: pod|service|container
- targetLabel: instance
replacement: policy-reporter
action: replace
{{- with .Values.serviceMonitor.relabelings }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.serviceMonitor.metricRelabelings }}
metricRelabelings:
{{- toYaml . | nindent 4 }}
{{- end }}

This issue prevents prometheus from scraping the metrics endpoint

@fjogeleit
Copy link
Member

Hey, thanks for reporting. I will have a look on it

@fjogeleit fjogeleit linked a pull request Mar 31, 2023 that will close this issue
@L1ghtman2k
Copy link

@fjogeleit How would one apply this to kyverno plugin's service monitor?

@fjogeleit
Copy link
Member

@L1ghtman2k there is a dedicated value for the plugin service monitor within the monitoring subchart

https://github.com/kyverno/policy-reporter/blob/main/charts/policy-reporter/charts/monitoring/values.yaml#L33

@L1ghtman2k
Copy link

@L1ghtman2k there is a dedicated value for the plugin service monitor within the monitoring subchart

https://github.com/kyverno/policy-reporter/blob/main/charts/policy-reporter/charts/monitoring/values.yaml#L33

Oh, i see, I was looking for something in the values.yaml that contains "plugin". Makes sense now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants