Fix response on no metrics found (#67)

Fixes the response from `GetMetricsBySelector` in case no metrics are
found. This issue caused a panic in kube-controller-manager:
https://github.com/kubernetes/kubernetes/pull/80392

Fix #40

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
This commit is contained in:
Mikkel Oscar Lyderik Larsen
2019-07-26 20:35:17 +02:00
committed by Sandor Szücs
parent 9950851cad
commit 461869c69b
2 changed files with 3 additions and 3 deletions

View File

@ -155,12 +155,12 @@ func (s *MetricStore) GetMetricsBySelector(namespace string, selector labels.Sel
metrics, ok := s.customMetricsStore[info.Metric]
if !ok {
return nil
return &custom_metrics.MetricValueList{}
}
group, ok := metrics[info.GroupResource]
if !ok {
return nil
return &custom_metrics.MetricValueList{}
}
if !info.Namespaced {

View File

@ -568,7 +568,7 @@ func TestCustomMetricsStorageErrors(t *testing.T) {
require.Nil(t, metric)
metrics := metricsStore.GetMetricsBySelector(tc.byLabel.namespace, tc.byLabel.selector, tc.byLabel.info)
require.Nil(t, metrics)
require.Equal(t, &custom_metrics.MetricValueList{}, metrics)
})
}