From 59572d16f337e9aaff1c8205ed79fdd099e0d68b Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Mon, 11 Mar 2019 06:35:25 +0200 Subject: [PATCH] add prometheus-operator servicemonitor support for helm-exporter (#12024) Signed-off-by: Alex Snast --- stable/helm-exporter/Chart.yaml | 2 +- stable/helm-exporter/README.md | 6 ++++ stable/helm-exporter/templates/service.yaml | 2 ++ .../templates/servicemonitor.yaml | 30 +++++++++++++++++++ stable/helm-exporter/values.yaml | 7 +++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 stable/helm-exporter/templates/servicemonitor.yaml diff --git a/stable/helm-exporter/Chart.yaml b/stable/helm-exporter/Chart.yaml index 289994d180..682bcee2ff 100644 --- a/stable/helm-exporter/Chart.yaml +++ b/stable/helm-exporter/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: "0.1.0" description: Exports helm release stats to prometheus name: helm-exporter -version: 0.1.0 +version: 0.2.0 home: https://github.com/sstarcher/helm-exporter sources: - https://github.com/sstarcher/helm-exporter diff --git a/stable/helm-exporter/README.md b/stable/helm-exporter/README.md index 5dd94b2d6a..b91b05910b 100644 --- a/stable/helm-exporter/README.md +++ b/stable/helm-exporter/README.md @@ -12,6 +12,8 @@ $ helm install stable/helm-exporter This chart bootstraps a [helm-exporter](https://github.com/sstarcher/helm-exporter) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. +The chart comes with a ServiceMonitor for use with the [Prometheus Operator](https://github.com/helm/charts/tree/master/stable/prometheus-operator). + ## Installing the Chart To install the chart with the release name `my-release`: @@ -45,6 +47,10 @@ Parameter | Description | Default `nodeSelector` | node labels for pod assignment | `{}` `resources` | pod resource requests & limits | `{}` `tolerations` | List of node taints to tolerate (requires Kubernetes 1.6+) | `[]` +`serviceMonitor.create` | Set to true if using the Prometheus Operator | `false` +`serviceMonitor.interval` | Interval at which metrics should be scraped | `` +`serviceMonitor.namespace` | The namespace where the Prometheus Operator is deployed | `` +`serviceMonitor.additionalLabels` | Additional labels to add to the ServiceMonitor | `{}` ```console $ helm install stable/helm-exporter --name my-release diff --git a/stable/helm-exporter/templates/service.yaml b/stable/helm-exporter/templates/service.yaml index 287c5d65bf..f2e76a6a04 100644 --- a/stable/helm-exporter/templates/service.yaml +++ b/stable/helm-exporter/templates/service.yaml @@ -7,8 +7,10 @@ metadata: helm.sh/chart: {{ include "helm-exporter.chart" . }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- if not .Values.serviceMonitor.create }} annotations: prometheus.io/scrape: "true" + {{- end }} spec: type: ClusterIP clusterIP: None diff --git a/stable/helm-exporter/templates/servicemonitor.yaml b/stable/helm-exporter/templates/servicemonitor.yaml new file mode 100644 index 0000000000..329340bd9a --- /dev/null +++ b/stable/helm-exporter/templates/servicemonitor.yaml @@ -0,0 +1,30 @@ +{{ if .Values.serviceMonitor.create }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "helm-exporter.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "helm-exporter.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: {{ include "helm-exporter.chart" . }} + {{- range $key, $value := .Values.serviceMonitor.additionalLabels }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- with .Values.serviceMonitor.namespace }} + namespace: {{ . }} + {{- end }} +spec: + endpoints: + - port: metrics + {{- with .Values.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "helm-exporter.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/stable/helm-exporter/values.yaml b/stable/helm-exporter/values.yaml index 3ff600d6fd..0e5aef8908 100644 --- a/stable/helm-exporter/values.yaml +++ b/stable/helm-exporter/values.yaml @@ -26,3 +26,10 @@ serviceAccount: # The name of the ServiceAccount to use. # If not set and create is true, a name is generated using the fullname template name: + +serviceMonitor: + # Specifies whether a ServiceMonitor should be created + create: false + interval: + namespace: + additionalLabels: {}