From 1f48d632f182d2f8aff534362b0ca79ef366e0cb Mon Sep 17 00:00:00 2001 From: Mitali Salvi Date: Thu, 30 May 2024 16:11:45 -0400 Subject: [PATCH] fixing linting issues --- .../stores/kubeletutil/kubeletclient.go | 15 ++++++--------- .../internal/stores/localnode_test.go | 17 ++++++++++++----- .../internal/stores/podstore.go | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go b/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go index c28c6b771a5f..1873d2480911 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/kubeletutil/kubeletclient.go @@ -6,7 +6,6 @@ package kubeletutil // import "github.com/open-telemetry/opentelemetry-collector import ( "encoding/json" "fmt" - "os" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -37,7 +36,12 @@ func NewKubeletClient(kubeIP string, port string, kubeConfigPath string, logger } endpoint = endpoint + ":" + port - clientConfig := &kubelet.ClientConfig{} + // use service account for authentication by default + clientConfig := &kubelet.ClientConfig{ + APIConfig: k8sconfig.APIConfig{ + AuthType: k8sconfig.AuthTypeServiceAccount, + }, + } if kubeConfigPath != "" { // use kube-config for authentication clientConfig = &kubelet.ClientConfig{ @@ -46,13 +50,6 @@ func NewKubeletClient(kubeIP string, port string, kubeConfigPath string, logger KubeConfigPath: kubeConfigPath, }, } - } else { - // use service account for authentication - clientConfig = &kubelet.ClientConfig{ - APIConfig: k8sconfig.APIConfig{ - AuthType: k8sconfig.AuthTypeServiceAccount, - }, - } } clientProvider, err := kubeletNewClientProvider(endpoint, clientConfig, logger) diff --git a/receiver/awscontainerinsightreceiver/internal/stores/localnode_test.go b/receiver/awscontainerinsightreceiver/internal/stores/localnode_test.go index b7de79de5188..50ae5d43b53b 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/localnode_test.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/localnode_test.go @@ -20,25 +20,32 @@ var logger = zap.NewNop() func TestNewLocalNodeDecorator(t *testing.T) { // don't set HostName environment variable, expect error in eks - d, err := NewLocalNodeDecorator(logger, "eks", nil) + d, err := NewLocalNodeDecorator(logger, "eks", nil, "") assert.Nil(t, d) assert.Error(t, err) // don't expect error in ecs - d, err = NewLocalNodeDecorator(logger, "ecs", nil) + d, err = NewLocalNodeDecorator(logger, "ecs", nil, "") assert.NotNil(t, d) assert.NoError(t, err) + assert.Empty(t, d.nodeName) + + d, err = NewLocalNodeDecorator(logger, "eks", nil, "test-hostname") + assert.NotNil(t, d) + assert.NoError(t, err) + assert.Equal(t, d.nodeName, "test-hostname") t.Setenv(ci.HostName, "host") - d, err = NewLocalNodeDecorator(logger, "eks", nil) + d, err = NewLocalNodeDecorator(logger, "eks", nil, "") assert.NotNil(t, d) assert.NoError(t, err) + assert.Equal(t, d.nodeName, "host") } func TestEbsVolumeInfo(t *testing.T) { t.Setenv(ci.HostName, "host") hostInfo := testutils.MockHostInfo{} - d, err := NewLocalNodeDecorator(logger, "eks", hostInfo) + d, err := NewLocalNodeDecorator(logger, "eks", hostInfo, "") assert.NotNil(t, d) assert.NoError(t, err) @@ -129,7 +136,7 @@ func TestExpectedTags(t *testing.T) { for name, testCase := range testCases { t.Run(name, func(t *testing.T) { - d, err := NewLocalNodeDecorator(logger, testCase.containerOrchestrator, hostInfo, WithK8sDecorator(k8sDecorator), WithECSInfo(&ecsInfo)) + d, err := NewLocalNodeDecorator(logger, testCase.containerOrchestrator, hostInfo, "", WithK8sDecorator(k8sDecorator), WithECSInfo(&ecsInfo)) assert.NotNil(t, d) assert.NoError(t, err) diff --git a/receiver/awscontainerinsightreceiver/internal/stores/podstore.go b/receiver/awscontainerinsightreceiver/internal/stores/podstore.go index 18af28cdfcf5..f18427d22104 100644 --- a/receiver/awscontainerinsightreceiver/internal/stores/podstore.go +++ b/receiver/awscontainerinsightreceiver/internal/stores/podstore.go @@ -148,7 +148,7 @@ func NewPodStore(hostIP string, prefFullPodName bool, addFullPodNameMetricLabel logger: logger, } if os.Getenv("RUN_ON_SYSTEMD") != "true" { - k8sClient := k8sclient.Get(logger, + k8sClient = k8sclient.Get(logger, k8sclient.NodeSelector(fields.OneTermEqualSelector("metadata.name", nodeName)), k8sclient.CaptureNodeLevelInfo(true), )