diff --git a/pkg/csi-common/utils.go b/pkg/csi-common/utils.go index 3f02a0846f..7bcadefa91 100644 --- a/pkg/csi-common/utils.go +++ b/pkg/csi-common/utils.go @@ -42,14 +42,10 @@ func parseEndpoint(ep string) (string, string, error) { return "", "", fmt.Errorf("Invalid endpoint: %v", ep) } -var klogFatalf = func(format string, args ...interface{}) { - klog.Fatalf(format, args...) -} - func ListenEndpoint(endpoint string) (net.Listener, error) { proto, addr, err := parseEndpoint(endpoint) if err != nil { - klogFatalf("Invalid endpoint: %v", err) + klog.Errorf("%v", err) return nil, err } @@ -58,14 +54,14 @@ func ListenEndpoint(endpoint string) (net.Listener, error) { addr = "/" + addr } if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - klogFatalf("Failed to remove %s, error: %s", addr, err.Error()) + klog.Errorf("Failed to remove %s, error: %v", addr, err) return nil, err } } listener, err := net.Listen(proto, addr) if err != nil { - klogFatalf("Failed to listen: %v", err) + klog.Errorf("Failed to listen: %v", err) return nil, err } return listener, err diff --git a/pkg/csi-common/utils_test.go b/pkg/csi-common/utils_test.go index 5270740a47..f36de14cf2 100644 --- a/pkg/csi-common/utils_test.go +++ b/pkg/csi-common/utils_test.go @@ -310,10 +310,6 @@ func TestListenEndpoint(t *testing.T) { t.Skip("Skip test on Windows") } - originalKlogFatalf := klogFatalf - klogFatalf = func(_ string, _ ...interface{}) {} - defer func() { klogFatalf = originalKlogFatalf }() - tests := []struct { name string endpoint string @@ -344,14 +340,6 @@ func TestListenEndpoint(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - defer func() { - if r := recover(); r != nil { - if !tt.wantErr { - t.Errorf("ListenEndpoint() panicked unexpectedly: %v", r) - } - } - }() - got, err := ListenEndpoint(tt.endpoint) if (err != nil) != tt.wantErr { t.Errorf("Listen() error = %v, wantErr %v", err, tt.wantErr)