Skip to content

Commit

Permalink
fixing linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mitali-salvi committed May 30, 2024
1 parent ef32d52 commit 1f48d63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down

0 comments on commit 1f48d63

Please sign in to comment.