From 87c90e6b1f6519f02f57c1df85d5ed579046f80d Mon Sep 17 00:00:00 2001 From: Jie Yu Date: Sat, 1 Jun 2019 19:04:13 -0700 Subject: [PATCH] [stable/prometheus-adapter] conditionally register external metrics API (#13716) (#14389) * [stable/prometheus-adapter] conditionally register external metrics API (#13716) The prometheus-adapter will NOT serve external metrics API if `externalRules` section is not specified. See this code: https://github.com/DirectXMan12/k8s-prometheus-adapter/blob/v0.5.0/cmd/adapter/adapter.go#L177 In that case, we cannot bindly register the external metrics API. Otherwise, we might see issues described in #13716. This patch fixed the issue by conditionally register the external metrics API. Fixes #13716 Signed-off-by: Jie Yu * [stable/prometheus-adapter] bump chart version to 1.0.3 Bump the chart version to 1.0.3 due to the fix of #13716. Signed-off-by: Jie Yu * [stable/prometheus-adapter] use 'and' to combine template directives To address the review comments. Signed-off-by: Jie Yu * [stable/prometheus-adapter] add ci test values To improve the test coverage. Signed-off-by: Jie Yu --- stable/prometheus-adapter/Chart.yaml | 2 +- stable/prometheus-adapter/ci/default-values.yaml | 0 stable/prometheus-adapter/ci/external-rules-values.yaml | 9 +++++++++ .../templates/external-metrics-apiservice.yaml | 2 ++ .../templates/external-metrics-cluster-role.yaml | 2 +- .../hpa-external-metrics-cluster-role-binding.yaml | 3 +-- 6 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 stable/prometheus-adapter/ci/default-values.yaml create mode 100644 stable/prometheus-adapter/ci/external-rules-values.yaml diff --git a/stable/prometheus-adapter/Chart.yaml b/stable/prometheus-adapter/Chart.yaml index 5c9a44701053..4cd240375237 100644 --- a/stable/prometheus-adapter/Chart.yaml +++ b/stable/prometheus-adapter/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: prometheus-adapter -version: 1.0.2 +version: 1.0.3 appVersion: v0.5.0 description: A Helm chart for k8s prometheus adapter home: https://github.com/DirectXMan12/k8s-prometheus-adapter diff --git a/stable/prometheus-adapter/ci/default-values.yaml b/stable/prometheus-adapter/ci/default-values.yaml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/stable/prometheus-adapter/ci/external-rules-values.yaml b/stable/prometheus-adapter/ci/external-rules-values.yaml new file mode 100644 index 000000000000..2dafb56211bf --- /dev/null +++ b/stable/prometheus-adapter/ci/external-rules-values.yaml @@ -0,0 +1,9 @@ +rules: + external: + - seriesQuery: '{__name__=~"^some_metric_count$"}' + resources: + template: <<.Resource>> + name: + matches: "" + as: "my_custom_metric" + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>) diff --git a/stable/prometheus-adapter/templates/external-metrics-apiservice.yaml b/stable/prometheus-adapter/templates/external-metrics-apiservice.yaml index 13de1c4bc60c..560b2ffcd806 100644 --- a/stable/prometheus-adapter/templates/external-metrics-apiservice.yaml +++ b/stable/prometheus-adapter/templates/external-metrics-apiservice.yaml @@ -1,3 +1,4 @@ +{{- if .Values.rules.external }} apiVersion: apiregistration.k8s.io/v1beta1 kind: APIService metadata: @@ -19,3 +20,4 @@ spec: insecureSkipTLSVerify: {{ if .Values.tls.enable }}false{{ else }}true{{ end }} groupPriorityMinimum: 100 versionPriority: 100 +{{- end -}} diff --git a/stable/prometheus-adapter/templates/external-metrics-cluster-role.yaml b/stable/prometheus-adapter/templates/external-metrics-cluster-role.yaml index daa1d03a05a3..4adbd653727d 100644 --- a/stable/prometheus-adapter/templates/external-metrics-cluster-role.yaml +++ b/stable/prometheus-adapter/templates/external-metrics-cluster-role.yaml @@ -1,4 +1,4 @@ -{{- if .Values.rbac.create -}} +{{- if and .Values.rbac.create .Values.rules.external -}} apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: diff --git a/stable/prometheus-adapter/templates/hpa-external-metrics-cluster-role-binding.yaml b/stable/prometheus-adapter/templates/hpa-external-metrics-cluster-role-binding.yaml index f1d54f8b84f8..0776029af275 100644 --- a/stable/prometheus-adapter/templates/hpa-external-metrics-cluster-role-binding.yaml +++ b/stable/prometheus-adapter/templates/hpa-external-metrics-cluster-role-binding.yaml @@ -1,5 +1,4 @@ - -{{- if .Values.rbac.create -}} +{{- if and .Values.rbac.create .Values.rules.external -}} apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: