-
Notifications
You must be signed in to change notification settings - Fork 75
feat(chart): add prometheus servicemonitor support #456
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
Open
Ayush4958
wants to merge
2
commits into
kubernetes-sigs:main
Choose a base branch
from
Ayush4958:feat/add-prometheus-service-monitor-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| Thanks for installing the {{ template "node-readiness-controller.fullname" . }} chart! | ||
|
|
||
| To verify that the controller pods are running, execute: | ||
| kubectl get pods -n {{ .Release.Namespace }} -l app.kubernetes.io/name={{ include "node-readiness-controller.name" . }} | ||
|
|
||
| {{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }} | ||
| {{- if not (.Capabilities.APIVersions.Has "monitoring.coreos.com/v1") }} | ||
|
|
||
| =================================================================================== | ||
| WARNING: Prometheus ServiceMonitor requested but CRD is missing! | ||
| =================================================================================== | ||
| You have enabled `metrics.serviceMonitor.enabled: true`, but the Kubernetes | ||
| API server does not report the `monitoring.coreos.com/v1` API as available. | ||
|
|
||
| The ServiceMonitor resource was NOT created. | ||
|
|
||
| If you are using offline rendering (e.g., `helm template`), this warning is | ||
| expected because Helm cannot detect cluster capabilities offline. You can | ||
| bypass this warning and force rendering by passing: | ||
| --api-versions "monitoring.coreos.com/v1" | ||
| =================================================================================== | ||
|
|
||
| {{- end }} | ||
| {{- end }} |
45 changes: 45 additions & 0 deletions
45
charts/node-readiness-controller/templates/servicemonitor.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| {{- if .Values.metrics.serviceMonitor.enabled }} | ||
| {{- if not .Values.metrics.enabled }} | ||
| {{- fail "You enabled metrics.serviceMonitor.enabled, but metrics.enabled is false. Please enable metrics to use the ServiceMonitor." }} | ||
| {{- end }} | ||
| {{- if .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" }} | ||
| apiVersion: monitoring.coreos.com/v1 | ||
| kind: ServiceMonitor | ||
| metadata: | ||
| name: {{ include "node-readiness-controller.fullname" . }} | ||
| namespace: {{ include "node-readiness-controller.namespace" . }} | ||
| labels: | ||
| {{- include "node-readiness-controller.labels" . | nindent 4 }} | ||
| {{- with .Values.metrics.serviceMonitor.labels }} | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| {{- include "node-readiness-controller.selectorLabels" . | nindent 6 }} | ||
| endpoints: | ||
| - port: {{ ternary "https" "http" .Values.metrics.secure }} | ||
| interval: {{ .Values.metrics.serviceMonitor.interval }} | ||
| scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }} | ||
| {{- if .Values.metrics.secure }} | ||
| scheme: https | ||
| {{- if .Values.metrics.serviceMonitor.bearerTokenFile }} | ||
| bearerTokenFile: {{ .Values.metrics.serviceMonitor.bearerTokenFile }} | ||
| {{- else }} | ||
| bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
| {{- end }} | ||
| {{- with .Values.metrics.serviceMonitor.tlsConfig }} | ||
| tlsConfig: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- with .Values.metrics.serviceMonitor.metricRelabelings }} | ||
| metricRelabelings: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- with .Values.metrics.serviceMonitor.relabelings }} | ||
| relabelings: | ||
| {{- toYaml . | nindent 8 }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
121 changes: 121 additions & 0 deletions
121
charts/node-readiness-controller/tests/servicemonitor_test.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| suite: Test ServiceMonitor Template | ||
| templates: | ||
| - servicemonitor.yaml | ||
|
|
||
| tests: | ||
| - it: does not render when metrics.enabled is false | ||
| set: | ||
| metrics: | ||
| enabled: false | ||
| serviceMonitor: | ||
| enabled: true | ||
| asserts: | ||
| - failedTemplate: | ||
| errorMessage: You enabled metrics.serviceMonitor.enabled, but metrics.enabled is false. Please enable metrics to use the ServiceMonitor. | ||
|
|
||
| - it: does not render when metrics.serviceMonitor.enabled is false | ||
| set: | ||
| metrics: | ||
| enabled: true | ||
| serviceMonitor: | ||
| enabled: false | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: does not render when monitoring.coreos.com/v1 capability is missing | ||
| set: | ||
| metrics: | ||
| enabled: true | ||
| serviceMonitor: | ||
| enabled: true | ||
| asserts: | ||
| - hasDocuments: | ||
| count: 0 | ||
|
|
||
| - it: renders correctly when both flags are true (assumes monitoring.coreos.com/v1 exists) | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| metrics: | ||
| enabled: true | ||
| serviceMonitor: | ||
| enabled: true | ||
| asserts: | ||
| - isKind: | ||
| of: ServiceMonitor | ||
| - equal: | ||
| path: apiVersion | ||
| value: monitoring.coreos.com/v1 | ||
| - equal: | ||
| path: spec.endpoints[0].port | ||
| value: http | ||
| - equal: | ||
| path: spec.endpoints[0].interval | ||
| value: 30s | ||
| - equal: | ||
| path: spec.endpoints[0].scrapeTimeout | ||
| value: 10s | ||
|
|
||
| - it: uses https scheme, bearer token, and injects custom tlsConfig when secure is true | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| metrics: | ||
| enabled: true | ||
| secure: true | ||
| serviceMonitor: | ||
| enabled: true | ||
| bearerTokenFile: /custom/path/to/token | ||
| tlsConfig: | ||
| insecureSkipVerify: true | ||
| asserts: | ||
| - equal: | ||
| path: spec.endpoints[0].port | ||
| value: https | ||
| - equal: | ||
| path: spec.endpoints[0].scheme | ||
| value: https | ||
| - equal: | ||
| path: spec.endpoints[0].bearerTokenFile | ||
| value: /custom/path/to/token | ||
| - equal: | ||
| path: spec.endpoints[0].tlsConfig.insecureSkipVerify | ||
| value: true | ||
|
|
||
| - it: merges custom labels | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| metrics: | ||
| enabled: true | ||
| serviceMonitor: | ||
| enabled: true | ||
| labels: | ||
| release: prometheus | ||
| asserts: | ||
| - equal: | ||
| path: metadata.labels.release | ||
| value: prometheus | ||
|
|
||
| - it: applies custom interval and timeout | ||
| capabilities: | ||
| apiVersions: | ||
| - monitoring.coreos.com/v1 | ||
| set: | ||
| metrics: | ||
| enabled: true | ||
| serviceMonitor: | ||
| enabled: true | ||
| interval: 1m | ||
| scrapeTimeout: 30s | ||
| asserts: | ||
| - equal: | ||
| path: spec.endpoints[0].interval | ||
| value: 1m | ||
| - equal: | ||
| path: spec.endpoints[0].scrapeTimeout | ||
| value: 30s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
serviceMonitor.enabled=truebut the CRD isn't installed, this just renders nothing. do we want to warn here, or is the current behavior intentional?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was intentional but I can see its a bad UX so I will add a warning to the chart's NOTES.txt
about crd not being installed