Skip to content

Commit

Permalink
Fix response on no metrics found
Browse files Browse the repository at this point in the history
Fixes the response from `GetMetricsBySelector` in case no metrics are
found. This issue caused a panic in kube-controller-manager:
kubernetes/kubernetes#80392

Fix #40

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
  • Loading branch information
mikkeloscar committed Jul 26, 2019
1 parent 9950851 commit 01aabe2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/provider/metric_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/metrics_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})
}
Expand Down

0 comments on commit 01aabe2

Please sign in to comment.