From fa5f8cd74292e66c1dcbb8ab0c9ddfa95f8f91ee Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Fri, 23 Apr 2021 11:27:38 -0600 Subject: [PATCH] Add requested fixes --- docs/externalmetrics.md | 4 ++-- docs/sample-config.yaml | 3 ++- pkg/naming/metrics_query.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/externalmetrics.md b/docs/externalmetrics.md index 080ecd13..461b8788 100644 --- a/docs/externalmetrics.md +++ b/docs/externalmetrics.md @@ -1,7 +1,7 @@ External Metrics =========== -It's possible to configure [Autoscaling on metrics not related to Kubernetes objects](Autoscaling on metrics not related to Kubernetes objects) in Kubernetes. This is done with a special `External Metrics` system. Using external metrics in Kubernetes with the adapter requires you to configure special `external` rules in the configuration. +It's possible to configure [Autoscaling on metrics not related to Kubernetes objects](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects) in Kubernetes. This is done with a special `External Metrics` system. Using external metrics in Kubernetes with the adapter requires you to configure special `external` rules in the configuration. The configuration for `external` metrics rules is almost identical to the normal `rules`: @@ -33,7 +33,7 @@ possible with `external` rules because the `namespace` label is set to match tha However, you can explicitly disable the automatic add of the HPA namepace to the query, and instead opt to not set a namespace at all, or to target a different namespace. -This is done by setting `namespaced: false` the `resources` section of the `external` rule: +This is done by setting `namespaced: false` in the `resources` section of the `external` rule: ```yaml # rules: ... diff --git a/docs/sample-config.yaml b/docs/sample-config.yaml index 9d926a33..e36cefe5 100644 --- a/docs/sample-config.yaml +++ b/docs/sample-config.yaml @@ -76,7 +76,8 @@ external: # but you can explicitly disable namespaces if needed with "namespaced: false" # this is useful if you have an HPA with an external metric in namespace A # but want to query for metrics from namespace B - namespaced: false + resources: + namespaced: false # TODO: should we be able to map to a constant instance of a resource # (e.g. `resources: {constant: [{resource: "namespace", name: "kube-system"}}]`)? diff --git a/pkg/naming/metrics_query.go b/pkg/naming/metrics_query.go index b6666228..c7f5c156 100644 --- a/pkg/naming/metrics_query.go +++ b/pkg/naming/metrics_query.go @@ -90,7 +90,7 @@ type queryPart struct { func (q *metricsQuery) Build(series string, resource schema.GroupResource, namespace string, extraGroupBy []string, metricSelector labels.Selector, names ...string) (prom.Selector, error) { queryParts := q.createQueryPartsFromSelector(metricSelector) - if q.namespaced && namespace != "" { + if namespace != "" { namespaceLbl, err := q.resConverter.LabelForResource(NsGroupResource) if err != nil { return "", err