diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index b1408d3..4b105b6 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -64,6 +64,11 @@ jobs: - name: Setup k3s/k3d run: c2cciutils-k8s-install + - name: Install prometheus CRD + run: | + curl https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/jsonnet/prometheus-operator/podmonitors-crd.json --output /tmp/podmonitors-crd.json + kubectl apply -f /tmp/podmonitors-crd.json + - name: Apply run: kubectl apply -f tests/expected.yaml diff --git a/templates/podmonitor.yaml b/templates/podmonitor.yaml new file mode 100644 index 0000000..0fb9757 --- /dev/null +++ b/templates/podmonitor.yaml @@ -0,0 +1,24 @@ +{{- range $serviceName, $serviceDefinition := .Values.services }} +{{- if hasKey $serviceDefinition "podMonitor" }} +{{- if eq $serviceDefinition.podMonitor.enabled true }} +--- +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: +{{- if hasKey $serviceDefinition.service "name" }} + name: {{ $serviceDefinition.service.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) }} +{{- include "common.metadata" ( dict "root" $ "service" $svcDict "serviceName" $serviceName ) | nindent 2 }} +spec: + selector: {{- include "common.selectorLabels" ( dict "root" $ "service" $serviceDefinition "serviceName" $serviceName ) | nindent 4 }} + {{- with $serviceDefinition.podMonitor.endpoint }} + podMetricsEndpoints: + - {{ . | toYaml | nindent 6 }} + {{- end }} +{{- end }} +{{- end }} +{{- end }} diff --git a/tests/expected.yaml b/tests/expected.yaml index 04064bf..9c07e67 100644 --- a/tests/expected.yaml +++ b/tests/expected.yaml @@ -619,3 +619,30 @@ spec: name: hardcoded-service-name port: number: 8080 +--- +# Source: custom-pod/templates/podmonitor.yaml +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: custom-custom-pod-with-service-name + 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: with-service-name + one-custom-label: hello-world + annotations: + one-custom-annotation: abc + two-custom-annotations: xyz +spec: + selector: + app.kubernetes.io/name: custom-pod + app.kubernetes.io/instance: custom + app.kubernetes.io/component: with-service-name + podMetricsEndpoints: + - + honorLabels: true + interval: 10s + port: prometheus diff --git a/tests/values.yaml b/tests/values.yaml index 2fa4d82..44c3e3d 100644 --- a/tests/values.yaml +++ b/tests/values.yaml @@ -30,10 +30,16 @@ ingress: services: example1: + enabled: true ingress: enabled: true path: /one - enabled: true + podMonitor: + enabled: true + endpoint: + port: prometheus + interval: 10s + honorLabels: true replicaCount: 1 nodeSelector: {} affinity: {}