From 3e34bb5d4d4fad9c2fa597a7e6c7a29e91872e35 Mon Sep 17 00:00:00 2001 From: Mitali Salvi Date: Thu, 30 May 2024 13:23:18 -0400 Subject: [PATCH] addressing pr comments --- internal/aws/k8s/k8sclient/clientset.go | 2 -- .../internal/host/nodeCapacity.go | 14 ++++++-------- .../internal/stores/kubeletutil/kubeletclient.go | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/internal/aws/k8s/k8sclient/clientset.go b/internal/aws/k8s/k8sclient/clientset.go index 1296e455f7bc..0db4ec06c610 100644 --- a/internal/aws/k8s/k8sclient/clientset.go +++ b/internal/aws/k8s/k8sclient/clientset.go @@ -160,8 +160,6 @@ func Get(logger *zap.Logger, options ...Option) *K8sClient { err := k8sClient.init(logger, options...) if err == nil { optionsToK8sClient[strOptions] = k8sClient - } else { - optionsToK8sClient[strOptions] = nil } } mu.Unlock() diff --git a/receiver/awscontainerinsightreceiver/internal/host/nodeCapacity.go b/receiver/awscontainerinsightreceiver/internal/host/nodeCapacity.go index 1d2c110a8fb5..ecd1133d4482 100644 --- a/receiver/awscontainerinsightreceiver/internal/host/nodeCapacity.go +++ b/receiver/awscontainerinsightreceiver/internal/host/nodeCapacity.go @@ -48,16 +48,14 @@ func newNodeCapacity(logger *zap.Logger, options ...nodeCapacityOption) (nodeCap ctx := context.Background() if runtime.GOOS != ci.OperatingSystemWindows { + procPath := hostProc if os.Getenv("RUN_ON_SYSTEMD") == "true" { - if _, err := nc.osLstat("/proc"); os.IsNotExist(err) { - return nil, err - } - } else { - if _, err := nc.osLstat(hostProc); os.IsNotExist(err) { - return nil, err - } + procPath = "/proc" } - envMap := common.EnvMap{common.HostProcEnvKey: hostProc} + if _, err := nc.osLstat(procPath); os.IsNotExist(err) { + return nil, err + } + envMap := common.EnvMap{common.HostProcEnvKey: procPath} ctx = context.WithValue(ctx, common.EnvKey, envMap) } diff --git a/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go b/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go index da66c34da9f8..c28c6b771a5f 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go @@ -38,7 +38,7 @@ func NewKubeletClient(kubeIP string, port string, kubeConfigPath string, logger endpoint = endpoint + ":" + port clientConfig := &kubelet.ClientConfig{} - if os.Getenv("RUN_ON_SYSTEMD") == "true" { + if kubeConfigPath != "" { // use kube-config for authentication clientConfig = &kubelet.ClientConfig{ APIConfig: k8sconfig.APIConfig{