From b38bca95aec2008f9b984e401eeafaa04500e842 Mon Sep 17 00:00:00 2001 From: Catherine Fang Date: Wed, 24 Apr 2024 15:26:31 -0400 Subject: [PATCH] Update --- custom-metrics-stackdriver-adapter/adapter.go | 2 +- .../pkg/adapter/coreprovider/provider.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/custom-metrics-stackdriver-adapter/adapter.go b/custom-metrics-stackdriver-adapter/adapter.go index 80694153f..9356d7b46 100644 --- a/custom-metrics-stackdriver-adapter/adapter.go +++ b/custom-metrics-stackdriver-adapter/adapter.go @@ -153,7 +153,7 @@ func (sa *StackdriverAdapter) withCoreMetrics(translator *translator.Translator) nodes := informers.Core().V1().Nodes() if err := api.Install(provider, podInformer.Lister(), nodes.Lister(), server.GenericAPIServer, []labels.Requirement{}); err != nil { - return nil + return err } return nil diff --git a/custom-metrics-stackdriver-adapter/pkg/adapter/coreprovider/provider.go b/custom-metrics-stackdriver-adapter/pkg/adapter/coreprovider/provider.go index eb8c1e4e7..9d50dafaf 100644 --- a/custom-metrics-stackdriver-adapter/pkg/adapter/coreprovider/provider.go +++ b/custom-metrics-stackdriver-adapter/pkg/adapter/coreprovider/provider.go @@ -50,6 +50,7 @@ type coreClientInterface interface { getNodeRAM(nodesNames []string) (map[string]resource.Quantity, map[string]api.TimeInfo, error) } +// GetPodMetrics implements the api.MetricsProvider interface. It translate data from getPodMetrics to the new api. func (p *CoreProvider) GetPodMetrics(pods ...*metav1.PartialObjectMetadata) ([]metrics.PodMetrics, error) { resMetrics := make([]metrics.PodMetrics, 0, len(pods)) @@ -90,6 +91,7 @@ func (p *CoreProvider) GetPodMetrics(pods ...*metav1.PartialObjectMetadata) ([]m return resMetrics, nil } +// GetNodeMetrics implements the api.MetricsProvider interface. It translate data from getNodeMetrics to the new api. func (p *CoreProvider) GetNodeMetrics(nodes ...*corev1.Node) ([]metrics.NodeMetrics, error) { resMetrics := make([]metrics.NodeMetrics, 0, len(nodes)) if len(nodes) == 0 { @@ -124,7 +126,6 @@ func (p *CoreProvider) GetNodeMetrics(nodes ...*corev1.Node) ([]metrics.NodeMetr return resMetrics, nil } -// GetPodMetrics implements the api.MetricsProvider interface. // If metrics from i-th pod are not present, ContainerMetrics[i] will be nil and TimeInfo[i] will be default TimeInfo value. func (p *CoreProvider) getPodMetrics(pods ...apitypes.NamespacedName) ([]api.TimeInfo, [][]metrics.ContainerMetrics, error) { timeInfo := make([]api.TimeInfo, len(pods)) @@ -182,7 +183,6 @@ func (p *CoreProvider) getPodMetrics(pods ...apitypes.NamespacedName) ([]api.Tim return timeInfo, coreMetrics, nil } -// GetNodeMetrics implements the api.MetricsProvider interface. // If metrics from i-th node are not present, ResourceList[i] will be nil and TimeInfo[i] will be default TimeInfo value. func (p *CoreProvider) getNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1.ResourceList, error) { timeInfo := make([]api.TimeInfo, len(nodes)) @@ -225,10 +225,12 @@ func (p *CoreProvider) getNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1 return timeInfo, coreMetrics, nil } +// TestGetPodMetrics is only for testing purpose. func (p *CoreProvider) TestGetPodMetrics(pods ...apitypes.NamespacedName) ([]api.TimeInfo, [][]metrics.ContainerMetrics, error) { return p.getPodMetrics(pods...) } +// TestGetNodeMetrics is only for testing purpose. func (p *CoreProvider) TestGetNodeMetrics(nodes ...string) ([]api.TimeInfo, []corev1.ResourceList, error) { return p.getNodeMetrics(nodes...) }