From 962b4e9be32311eb31779a44cae18f5895456c4a Mon Sep 17 00:00:00 2001 From: jw-maynard Date: Thu, 14 Jan 2021 01:46:05 -0800 Subject: [PATCH] [bitnami/kube-prometheus] Add internal chart management of additional scrape configs (#4975) * Add the ability to manage additional scrape configs inside the Helm chart * Fix values.yaml, additional documentation * Update version in Chart.yaml * Update after suggestions from Bitnami team * Fix indenting problem in values files --- bitnami/kube-prometheus/Chart.yaml | 2 +- bitnami/kube-prometheus/README.md | 51 ++++++++++++++++--- .../prometheus/additionalScrapeJobs.yaml | 10 ++++ .../templates/prometheus/prometheus.yaml | 10 +++- .../kube-prometheus/values-production.yaml | 14 +++++ bitnami/kube-prometheus/values.yaml | 14 +++++ 6 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 bitnami/kube-prometheus/templates/prometheus/additionalScrapeJobs.yaml diff --git a/bitnami/kube-prometheus/Chart.yaml b/bitnami/kube-prometheus/Chart.yaml index 9a9e3dc6f4..04a45f18e3 100644 --- a/bitnami/kube-prometheus/Chart.yaml +++ b/bitnami/kube-prometheus/Chart.yaml @@ -34,4 +34,4 @@ sources: - https://github.com/bitnami/bitnami-docker-prometheus - https://github.com/bitnami/bitnami-docker-alertmanager - https://github.com/prometheus-operator/kube-prometheus -version: 3.3.3 +version: 3.4.0 diff --git a/bitnami/kube-prometheus/README.md b/bitnami/kube-prometheus/README.md index d84c6a9bc6..29a89186f4 100644 --- a/bitnami/kube-prometheus/README.md +++ b/bitnami/kube-prometheus/README.md @@ -237,9 +237,14 @@ The following table lists the configurable parameters of the kube-prometheus cha | `prometheus.volumes` | Volumes allows configuration of additional volumes. Evaluated as a template | `[]` See [docs](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#prometheusspec) for details | | `prometheus.volumeMounts` | VolumeMounts allows configuration of additional VolumeMounts. Evaluated as a template | `[]` See [docs](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#prometheusspec) for details | | `prometheus.additionalPrometheusRules` | PrometheusRule defines recording and alerting rules for a Prometheus instance. | `[]` | -| `prometheus.additionalScrapeConfigsExternal.enabled` | Enable additional scrape configs that are managed externally to this chart | `false` See [docs](#additional-scrape-configurations) for details. | -| `prometheus.additionalScrapeConfigsExternal.name` | Name of the secret that Prometheus should use for the additional scrape configuration | `nil` | -| `prometheus.additionalScrapeConfigsExternal.key` | Name of the key inside the secret to be used for the additional scrape configuration | `nil` | +| `prometheus.additionalScrapeConfigs.enabled` | Enable additional scrape configs | `false` See [docs](#additional-scrape-configurations) for details. | +| `prometheus.additionalScrapeConfigs.type` | Indicates if the cart should use external additional scrape configs or internal configs | `external` See [docs](#additional-scrape-configurations) for details. | +| `prometheus.additionalScrapeConfigs.external.name` | Name of the secret that Prometheus should use for the additional external scrape configuration | `nil` | +| `prometheus.additionalScrapeConfigs.external.key` | Name of the key inside the secret to be used for the additional external scrape configuration | `nil` | +| `prometheus.additionalScrapeConfigs.internal.jobList` | A list of Prometheus scrape jobs | `[]` See [docs](#additional-scrape-configurations) for details. | +| `prometheus.additionalScrapeConfigsExternal.enabled` | (deprecated) Enable additional scrape configs that are managed externally to this chart | `false` See [docs](#additional-scrape-configurations) for details. | +| `prometheus.additionalScrapeConfigsExternal.name` | (deprecated) Name of the secret that Prometheus should use for the additional scrape configuration | `nil` | +| `prometheus.additionalScrapeConfigsExternal.key` | (deprecated) Name of the key inside the secret to be used for the additional scrape configuration | `nil` | | `prometheus.additionalAlertRelabelConfigsExternal.enabled` | Enable additional Prometheus alert relabel configs that are managed externally to this chart | `false` See [docs](#additional-alert-relabel-configurations) for details. | | `prometheus.additionalAlertRelabelConfigsExternal.name` | Name of the secret that Prometheus should use for the additional Prometheus alert relabel configuration | `nil` | | `prometheus.additionalAlertRelabelConfigsExternal.key` | Name of the key inside the secret to be used for the additional Prometheus alert relabel configuration | `nil` | @@ -476,12 +481,34 @@ This chart includes a `values-production.yaml` file where you can find some para ### Additional scrape configurations -It is possible to inject externally managed scrape configurations via a Secret by setting `prometheus.additionalScrapeConfigsExternal.enabled` to `true`. The secret must exist in the same namespace which the kube-prometheus will be deployed into. Set the secret name using the parameter `prometheus.additionalScrapeConfigsExternal.name`, and the key containing the additional scrape configuration using the `prometheus.additionalScrapeConfigsExternal.key`. For instance, if you created a secret named `kube-prometheus-prometheus-scrape-config` and it contains a file named `additional-scrape-configs.yaml`, use the parameters below: +The following values have been deprecated. See [Upgrading](#upgrading) below. ```console -prometheus.additionalScrapeConfigsExternal.enabled=true -prometheus.additionalScrapeConfigsExternal.name=kube-prometheus-prometheus-scrape-config -prometheus.additionalScrapeConfigsExternal.key=additional-scrape-configs.yaml +prometheus.additionalScrapeConfigsExternal.enabled +prometheus.additionalScrapeConfigsExternal.name +prometheus.additionalScrapeConfigsExternal.key +``` + +It is possible to inject externally managed scrape configurations via a Secret by setting `prometheus.additionalScrapeConfigs.enabled` to `true` and `prometheus.additionalScrapeConfigs.type` to `external`. The secret must exist in the same namespace which the kube-prometheus will be deployed into. Set the secret name using the parameter `prometheus.additionalScrapeConfigs.external.name`, and the key containing the additional scrape configuration using the `prometheus.additionalScrapeConfigs.external.key`. For instance, if you created a secret named `kube-prometheus-prometheus-scrape-config` and it contains a file named `additional-scrape-configs.yaml`, use the parameters below: + +```console +prometheus.additionalScrapeConfigs.enabled=true +prometheus.additionalScrapeConfigs.type=external +prometheus.additionalScrapeConfigs.external.name=kube-prometheus-prometheus-scrape-config +prometheus.additionalScrapeConfigs.external.key=additional-scrape-configs.yaml +``` + +It is also possible to define scrape configs to be managed by the Helm chart by setting `prometheus.additionalScrapeConfigs.enabled` to `true` and `prometheus.additionalScrapeConfigs.type` to `internal`. You can then use `prometheus.additionalScrapeConfigs.internal.jobList` to define a list of additional scrape jobs for Prometheus. + +```console +prometheus.additionalScrapeConfigs.enabled=true +prometheus.additionalScrapeConfigs.type=internal +prometheus.additionalScrapeConfigs.internal.jobList= + - job_name: 'opentelemetry-collector' + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + static_configs: + - targets: ['opentelemetry-collector:8889'] ``` For more information, see [Prometheus Operator - Additional scrape configuration documentation](https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/additional-scrape-config.md). @@ -512,6 +539,16 @@ Find more information about how to deal with common errors related to Bitnami’ $ helm upgrade my-release bitnami/kube-prometheus ``` +### To 3.4.0 + +Some parameters disappeared in favor of new ones: + +- `prometheus.additionalScrapeConfigsExternal.enabled` -> deprecated in favor of `prometheus.additionalScrapeConfigs.enabled` and `prometheus.additionalScrapeConfigs.type`. +- `prometheus.additionalScrapeConfigsExternal.name` -> deprecated in favor of `prometheus.additionalScrapeConfigs.external.name`. +- `prometheus.additionalScrapeConfigsExternal.key` -> deprecated in favor of `prometheus.additionalScrapeConfigs.external.key`. + +Adapt you parameters accordingly if you are external scrape configs. + ### To 3.1.0 Some parameters disappeared in favor of new ones: diff --git a/bitnami/kube-prometheus/templates/prometheus/additionalScrapeJobs.yaml b/bitnami/kube-prometheus/templates/prometheus/additionalScrapeJobs.yaml new file mode 100644 index 0000000000..9d36939167 --- /dev/null +++ b/bitnami/kube-prometheus/templates/prometheus/additionalScrapeJobs.yaml @@ -0,0 +1,10 @@ +{{- if (and .Values.prometheus.additionalScrapeConfigs.enabled (eq .Values.prometheus.additionalScrapeConfigs.type "internal") ) }} +apiVersion: v1 +kind: Secret +metadata: + name: additional-scrape-jobs-{{ template "kube-prometheus.prometheus.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: {{- include "kube-prometheus.prometheus.labels" . | nindent 4 }} +data: + scrape-jobs.yaml: {{- include "common.tplvalues.render" ( dict "value" .Values.prometheus.additionalScrapeConfigs.internal.jobList "context" $ ) | b64enc | quote }} +{{- end }} \ No newline at end of file diff --git a/bitnami/kube-prometheus/templates/prometheus/prometheus.yaml b/bitnami/kube-prometheus/templates/prometheus/prometheus.yaml index 9aee7e4b8a..75e16242ed 100644 --- a/bitnami/kube-prometheus/templates/prometheus/prometheus.yaml +++ b/bitnami/kube-prometheus/templates/prometheus/prometheus.yaml @@ -183,10 +183,18 @@ spec: {{- if .Values.prometheus.volumeMounts }} volumeMounts: {{- include "common.tplvalues.render" (dict "value" .Values.prometheus.volumeMounts "context" $) | nindent 4 }} {{- end }} - {{- if .Values.prometheus.additionalScrapeConfigsExternal.enabled }} + {{- if or .Values.prometheus.additionalScrapeConfigs.enabled .Values.prometheus.additionalScrapeConfigsExternal.enabled }} additionalScrapeConfigs: + {{- if and .Values.prometheus.additionalScrapeConfigs.enabled (eq .Values.prometheus.additionalScrapeConfigs.type "external") }} + name: {{ .Values.prometheus.additionalScrapeConfigs.external.name }} + key: {{ .Values.prometheus.additionalScrapeConfigs.external.key }} + {{- else if and .Values.prometheus.additionalScrapeConfigs.enabled (eq .Values.prometheus.additionalScrapeConfigs.type "internal") }} + name: additional-scrape-jobs-{{ template "kube-prometheus.prometheus.fullname" . }} + key: scrape-jobs.yaml + {{- else if and (not .Values.prometheus.additionalScrapeConfigs.enabled) .Values.prometheus.additionalScrapeConfigsExternal.enabled }} name: {{ .Values.prometheus.additionalScrapeConfigsExternal.name }} key: {{ .Values.prometheus.additionalScrapeConfigsExternal.key }} + {{- end }} {{- end }} {{- if .Values.prometheus.additionalAlertRelabelConfigsExternal.enabled }} additionalAlertRelabelConfigs: diff --git a/bitnami/kube-prometheus/values-production.yaml b/bitnami/kube-prometheus/values-production.yaml index bd1677bd2d..bc6b0ef200 100644 --- a/bitnami/kube-prometheus/values-production.yaml +++ b/bitnami/kube-prometheus/values-production.yaml @@ -729,6 +729,20 @@ prometheus: ## Enable additional scrape configs that are managed externally to this chart ## Note that the prometheus will fail to provision if the correct secret does not exist. ## + additionalScrapeConfigs: + enabled: false + type: external + external: + ## Name of the secret that Prometheus should use for the additional scrape configuration + ## + name: "" + ## Name of the key inside the secret to be used for the additional scrape configuration. + ## + key: "" + internal: + jobList: [] + + ## NOTE additionalScrapeConfigsExternal is deprecated. Please see README.md additionalScrapeConfigsExternal: enabled: false ## Name of the secret that Prometheus should use for the additional scrape configuration diff --git a/bitnami/kube-prometheus/values.yaml b/bitnami/kube-prometheus/values.yaml index 7a23d4a6b1..32ba9b78dc 100644 --- a/bitnami/kube-prometheus/values.yaml +++ b/bitnami/kube-prometheus/values.yaml @@ -727,6 +727,20 @@ prometheus: ## Enable additional scrape configs that are managed externally to this chart ## Note that the prometheus will fail to provision if the correct secret does not exist. ## + additionalScrapeConfigs: + enabled: false + type: external + external: + ## Name of the secret that Prometheus should use for the additional scrape configuration + ## + name: "" + ## Name of the key inside the secret to be used for the additional scrape configuration. + ## + key: "" + internal: + jobList: [] + + ## NOTE additionalScrapeConfigsExternal is deprecated. Please see README.md additionalScrapeConfigsExternal: enabled: false ## Name of the secret that Prometheus should use for the additional scrape configuration