Skip to content

Commit

Permalink
Merge pull request #218 from camptocamp/fix-podmonitor-noservice
Browse files Browse the repository at this point in the history
Fix podMonitor without any service
  • Loading branch information
sbrunner authored Sep 4, 2024
2 parents 103987d + 3833606 commit 1ac3320
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
6 changes: 3 additions & 3 deletions templates/podmonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
{{- if hasKey $serviceDefinition.service "name" }}
name: {{ $serviceDefinition.service.name }}
{{- if hasKey $serviceDefinition.podMonitor "name" }}
name: {{ $serviceDefinition.podMonitor.name }}
{{- else }}
name: {{ include "common.fullname" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) }}
{{- end }}
{{- $svcDict := deepCopy $serviceDefinition }}
{{- $svcDict := merge $svcDict (dict "annotations" $serviceDefinition.service.annotations "labels" $serviceDefinition.service.labels) }}
{{- $svcDict := merge $svcDict (dict "annotations" $serviceDefinition.podMonitor.annotations "labels" $serviceDefinition.podMonitor.labels) }}
{{- include "common.metadata" ( dict "root" $ "service" $svcDict "serviceName" $serviceName ) | nindent 2 }}
spec:
selector:
Expand Down
23 changes: 23 additions & 0 deletions tests/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1550,3 +1550,26 @@ spec:
- port: prometheus
honorLabels: true
interval: 10s
---
# Source: custom-pod/templates/podmonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: custom-custom-pod-example4
labels:
helm.sh/chart: custom-pod
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: example4
spec:
selector:
matchLabels:
app.kubernetes.io/name: custom-pod
app.kubernetes.io/instance: custom
app.kubernetes.io/component: example4
podMetricsEndpoints:
- port: prometheus
honorLabels: true
interval: 10s
10 changes: 8 additions & 2 deletions tests/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ services:
interval: 10s
honorLabels: true
replicaCount: 1
nodeSelector: {}
affinity:
podAntiAffinity:
topologyKey: kubernetes.io/hostname
Expand Down Expand Up @@ -368,7 +367,7 @@ services:
<<: *servicedefinition
name: hardcoded-service-name

# Eyample with labelSelector in affinity
# Example with labelSelector in affinity
example4:
enabled: true
affinity:
Expand All @@ -382,6 +381,13 @@ services:
repository: camptocamp/image
tag: latest

podMonitor:
enabled: true
podMetricsEndpoints:
prometheus:
interval: 10s
honorLabels: true

# Minimal configuration of a deployment
deployment-min:
enabled: true
Expand Down
5 changes: 4 additions & 1 deletion values.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@
- **`annotations`**: Refer to _[#/definitions/annotations](#definitions/annotations)_.
- **`ports`** _(array)_
- **`podMonitor`** _(object)_: The Prometheus Pod monitor configuration. Cannot contain additional properties.
- **`enabled`** _(boolean)_: Enable the Pod monitor for this service.
- **`enabled`** _(boolean)_: Enable the Pod monitor for this service (Pod).
- **`name`** _(string)_: The name of the Pod monitor.
- **`labels`**: Refer to _[#/definitions/labels](#definitions/labels)_.
- **`annotations`**: Refer to _[#/definitions/annotations](#definitions/annotations)_.
- **`podMetricsEndpoints`** _(object)_: The endpoints of the Pod monitor by port. Can contain additional properties.
- **Additional properties** _(object)_: The endpoint of the Pod monitor.

Expand Down
12 changes: 11 additions & 1 deletion values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,17 @@
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable the Pod monitor for this service"
"description": "Enable the Pod monitor for this service (Pod)"
},
"name": {
"type": "string",
"description": "The name of the Pod monitor"
},
"labels": {
"$ref": "#/definitions/labels"
},
"annotations": {
"$ref": "#/definitions/annotations"
},
"podMetricsEndpoints": {
"type": "object",
Expand Down

0 comments on commit 1ac3320

Please sign in to comment.