From 81c07f5ea35dcdfc269654f9b29b40e6011ffcb7 Mon Sep 17 00:00:00 2001 From: amaslennikov Date: Mon, 29 Jan 2024 11:29:54 +0300 Subject: [PATCH] Fix lint issues Signed-off-by: amaslennikov --- pkg/resources/server.go | 7 ++++--- pkg/resources/testing.go | 4 ++-- pkg/utils/utils.go | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/resources/server.go b/pkg/resources/server.go index bb4fb0135..6080953a4 100644 --- a/pkg/resources/server.go +++ b/pkg/resources/server.go @@ -51,6 +51,7 @@ type resourceServer struct { const ( rsWatchInterval = 5 * time.Second serverStartTimeout = 5 * time.Second + unix = "unix" ) // NewResourceServer returns an instance of ResourceServer @@ -77,7 +78,7 @@ func NewResourceServer(prefix, suffix string, pluginWatch, useCdi bool, rp types } func (rs *resourceServer) register() error { - kubeletEndpoint := "unix:" + filepath.Join(types.DeprecatedSockDir, types.KubeEndPoint) + kubeletEndpoint := unix + ":" + filepath.Join(types.DeprecatedSockDir, types.KubeEndPoint) conn, err := grpc.Dial(kubeletEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { glog.Errorf("%s device plugin unable connect to Kubelet : %v", rs.resourcePool.GetResourceName(), err) @@ -252,7 +253,7 @@ func (rs *resourceServer) Start() error { } glog.Infof("starting %s device plugin endpoint at: %s\n", resourceName, rs.endPoint) - lis, err := net.Listen("unix", rs.sockPath) + lis, err := net.Listen(unix, rs.sockPath) if err != nil { glog.Errorf("error starting %s device plugin endpoint: %v", resourceName, err) return err @@ -273,7 +274,7 @@ func (rs *resourceServer) Start() error { // Wait for server to start by launching a blocking connection ctx, _ := context.WithTimeout(context.TODO(), serverStartTimeout) conn, err := grpc.DialContext( - ctx, "unix:"+rs.sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + ctx, unix+":"+rs.sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) if err != nil { glog.Errorf("error. unable to establish test connection with %s gRPC server: %v", resourceName, err) diff --git a/pkg/resources/testing.go b/pkg/resources/testing.go index 60e51d06d..74427fdec 100644 --- a/pkg/resources/testing.go +++ b/pkg/resources/testing.go @@ -127,7 +127,7 @@ func (s *fakeRegistrationServer) Register( } func (s *fakeRegistrationServer) start() { - l, err := net.Listen("unix", path.Join(s.sockDir, types.KubeEndPoint)) + l, err := net.Listen(unix, path.Join(s.sockDir, types.KubeEndPoint)) if err != nil { panic(err) } @@ -145,7 +145,7 @@ func (s *fakeRegistrationServer) waitForServer(timeout time.Duration) error { if time.Now().After(maxWaitTime) { return fmt.Errorf("waiting for the fake registration server timed out") } - c, err := net.DialTimeout("unix", path.Join(s.sockDir, types.KubeEndPoint), time.Second) + c, err := net.DialTimeout(unix, path.Join(s.sockDir, types.KubeEndPoint), time.Second) if err == nil { return c.Close() } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 2afb2d92e..1377a5e73 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -42,6 +42,7 @@ const ( classIDBitSize = 64 maxVendorName = 20 maxProductName = 40 + ellipsis = "..." ) // DetectPluginWatchMode returns true if plugins registry directory exist @@ -504,7 +505,7 @@ func HasDefaultRoute(pciAddr string) (bool, error) { func NormalizeVendorName(vendor string) string { vendorName := vendor if len(vendor) > maxVendorName { - vendorName = string([]byte(vendorName)[0:17]) + "..." + vendorName = string([]byte(vendorName)[0:17]) + ellipsis } return vendorName } @@ -513,7 +514,7 @@ func NormalizeVendorName(vendor string) string { func NormalizeProductName(product string) string { productName := product if len(product) > maxProductName { - productName = string([]byte(productName)[0:37]) + "..." + productName = string([]byte(productName)[0:37]) + ellipsis } return productName }