From bdc8b487ba8f6897c8a011e4b1ab15ede6419fe1 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Tue, 27 Oct 2020 19:39:13 -0600 Subject: [PATCH] Populate both CPU and Memory resource container metrics if one is specified --- pkg/resourceprovider/provider.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/resourceprovider/provider.go b/pkg/resourceprovider/provider.go index da0bc70b..5da1a693 100644 --- a/pkg/resourceprovider/provider.go +++ b/pkg/resourceprovider/provider.go @@ -226,6 +226,17 @@ func (p *resourceProvider) assignForPod(pod apitypes.NamespacedName, resultsByNs } } + // check for any containers that have either memory usage or CPU usage, but not both + for _, containerMetric := range containerMetrics { + _, hasMemory := containerMetric.Usage[corev1.ResourceMemory] + _, hasCPU := containerMetric.Usage[corev1.ResourceCPU] + if hasMemory && !hasCPU { + containerMetric.Usage[corev1.ResourceCPU] = *resource.NewMilliQuantity(int64(0), resource.BinarySI) + } else if hasCPU && !hasMemory { + containerMetric.Usage[corev1.ResourceMemory] = *resource.NewMilliQuantity(int64(0), resource.BinarySI) + } + } + // store the time in the final format *resTime = api.TimeInfo{ Timestamp: earliestTs.Time(),