From e9ef0bb4d0e28c31ae81f3188b657ce63adf60ee Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Tue, 11 Dec 2018 10:21:21 -0800 Subject: [PATCH 1/2] Fix empty pod or node list resulting in an error --- pkg/resourceprovider/provider.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/resourceprovider/provider.go b/pkg/resourceprovider/provider.go index 7d47af6b1..7dda77937 100644 --- a/pkg/resourceprovider/provider.go +++ b/pkg/resourceprovider/provider.go @@ -120,7 +120,7 @@ type nsQueryResults struct { func (p *resourceProvider) GetContainerMetrics(pods ...apitypes.NamespacedName) ([]provider.TimeInfo, [][]metrics.ContainerMetrics, error) { if len(pods) == 0 { - return nil, nil, fmt.Errorf("no pods to fetch metrics for") + return nil, nil, nil } // TODO(directxman12): figure out how well this scales if we go to list 1000+ pods @@ -240,7 +240,7 @@ func (p *resourceProvider) assignForPod(pod apitypes.NamespacedName, resultsByNs func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]provider.TimeInfo, []corev1.ResourceList, error) { if len(nodes) == 0 { - return nil, nil, fmt.Errorf("no nodes to fetch metrics for") + return nil, nil, nil } now := pmodel.Now() From 76249528703ce650d7d5f596a9418d7a98a4ef86 Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Thu, 13 Dec 2018 15:50:02 -0800 Subject: [PATCH 2/2] resourceprovider: Add comments on possible nil results --- pkg/resourceprovider/provider.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/resourceprovider/provider.go b/pkg/resourceprovider/provider.go index 7dda77937..b1dc0151d 100644 --- a/pkg/resourceprovider/provider.go +++ b/pkg/resourceprovider/provider.go @@ -118,6 +118,7 @@ type nsQueryResults struct { err error } +// GetContainerMetrics implements the provider.MetricsProvider interface. It may return nil, nil, nil. func (p *resourceProvider) GetContainerMetrics(pods ...apitypes.NamespacedName) ([]provider.TimeInfo, [][]metrics.ContainerMetrics, error) { if len(pods) == 0 { return nil, nil, nil @@ -238,6 +239,7 @@ func (p *resourceProvider) assignForPod(pod apitypes.NamespacedName, resultsByNs *resMetrics = containerMetricsList } +// GetNodeMetrics implements the provider.MetricsProvider interface. It may return nil, nil, nil. func (p *resourceProvider) GetNodeMetrics(nodes ...string) ([]provider.TimeInfo, []corev1.ResourceList, error) { if len(nodes) == 0 { return nil, nil, nil