From 83c12bd0113215413c7c8c419ea592594785984e Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Mon, 9 Dec 2024 18:42:39 +0200 Subject: [PATCH] agent: golangci-lint fixes. Signed-off-by: Krisztian Litkey --- pkg/agent/agent.go | 6 +++--- pkg/agent/podresapi/client.go | 16 +--------------- pkg/agent/watch/file.go | 2 +- pkg/agent/watch/object.go | 3 +-- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 660e083f0..9f63cbae9 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -212,10 +212,10 @@ func (a *Agent) Start(notifyFn NotifyFn) error { break } if e.Type == watch.Added || e.Type == watch.Modified { - group, _ := e.Object.(*corev1.Node).Labels[a.groupLabel] + group := e.Object.(*corev1.Node).Labels[a.groupLabel] if group == "" { for _, l := range deprecatedGroupLabels { - group, _ = e.Object.(*corev1.Node).Labels[l] + group = e.Object.(*corev1.Node).Labels[l] if group != "" { log.Warnf("Using DEPRECATED config group label %q", l) log.Warnf("Please switch to using label %q instead", a.groupLabel) @@ -259,7 +259,7 @@ func (a *Agent) Stop() { if a.stopC != nil { close(a.stopC) - _ = <-a.doneC + <-a.doneC a.stopC = nil } } diff --git a/pkg/agent/podresapi/client.go b/pkg/agent/podresapi/client.go index e9a2e4909..fc946cbba 100644 --- a/pkg/agent/podresapi/client.go +++ b/pkg/agent/podresapi/client.go @@ -17,9 +17,7 @@ package podresapi import ( "context" "fmt" - "net" "strings" - "time" logger "github.com/containers/nri-plugins/pkg/log" "google.golang.org/grpc" @@ -43,7 +41,6 @@ const ( // these constants were obtained from NFD sources, cross-checked against // https://github.com/kubernetes/kubernetes/blob/release-1.31/test/e2e_node/util.go#L83 defaultSocketPath = "/var/lib/kubelet/pod-resources/kubelet.sock" - timeout = 10 * time.Second maxSize = 1024 * 1024 * 16 ) @@ -77,20 +74,9 @@ func NewClient(options ...ClientOption) (*Client, error) { } if c.conn == nil { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - - dialer := func(ctx context.Context, addr string) (net.Conn, error) { - return (&net.Dialer{}).DialContext(ctx, "unix", addr) - } - - conn, err := grpc.DialContext( - ctx, - c.socketPath, + conn, err := grpc.NewClient("unix://"+c.socketPath, grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxSize)), - grpc.WithBlock(), ) if err != nil { diff --git a/pkg/agent/watch/file.go b/pkg/agent/watch/file.go index a6fcd10b1..c8cc610db 100644 --- a/pkg/agent/watch/file.go +++ b/pkg/agent/watch/file.go @@ -87,7 +87,7 @@ func (w *FileWatch) Stop() { if w.stopC != nil { close(w.stopC) - _ = <-w.doneC + <-w.doneC w.stopC = nil } } diff --git a/pkg/agent/watch/object.go b/pkg/agent/watch/object.go index 3e906abd7..e7eb9e4a2 100644 --- a/pkg/agent/watch/object.go +++ b/pkg/agent/watch/object.go @@ -38,7 +38,6 @@ type ObjectWatch struct { name string resultC chan Event wif watch.Interface - pending *Event reopenC <-chan time.Time failing bool @@ -73,7 +72,7 @@ func (w *ObjectWatch) Stop() { if w.stopC != nil { close(w.stopC) - _ = <-w.doneC + <-w.doneC w.stopC = nil } }