From 46ca5036c49f4e03333a24f63f34e35160ddcffd Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Mon, 13 Feb 2023 17:16:53 +0100 Subject: [PATCH] fix: add check to skip controlplaneinfo in case of cloud providers Signed-off-by: Alessio Greggi --- .../hostsensorutils/hostsensorgetfrompod.go | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/pkg/hostsensorutils/hostsensorgetfrompod.go b/core/pkg/hostsensorutils/hostsensorgetfrompod.go index 874d7db3..b96f9c22 100644 --- a/core/pkg/hostsensorutils/hostsensorgetfrompod.go +++ b/core/pkg/hostsensorutils/hostsensorgetfrompod.go @@ -323,18 +323,9 @@ func (hsh *HostSensorHandler) CollectResources(ctx context.Context) ([]hostsenso res = append(res, kcData...) } - // GetControlPlaneInfo - kcData, err = hsh.GetControlPlaneInfo(ctx) - if err != nil { - addInfoToMap(ControlPlaneInfo, infoMap, err) - logger.L().Ctx(ctx).Warning(err.Error()) - } - if len(kcData) > 0 { - res = append(res, kcData...) - } - // GetCloudProviderInfo kcData, err = hsh.GetCloudProviderInfo(ctx) + isCloudProvider := (kcData != nil) if err != nil { addInfoToMap(CloudProviderInfo, infoMap, err) logger.L().Ctx(ctx).Warning(err.Error()) @@ -343,6 +334,18 @@ func (hsh *HostSensorHandler) CollectResources(ctx context.Context) ([]hostsenso res = append(res, kcData...) } + // GetControlPlaneInfo + if !isCloudProvider { // we retrieve control plane info only if we are not using a cloud provider + kcData, err = hsh.GetControlPlaneInfo(ctx) + if err != nil { + addInfoToMap(ControlPlaneInfo, infoMap, err) + logger.L().Ctx(ctx).Warning(err.Error()) + } + if len(kcData) > 0 { + res = append(res, kcData...) + } + } + // GetCNIInfo kcData, err = hsh.GetCNIInfo(ctx) if err != nil {