Skip to content

Commit d785d90

Browse files
committed
Fix redundant error check
This PR fixes * Removes redundant error check * use `glog.Errorf` to log in case of an error. Signed-off-by: Madhu Rajanna <[email protected]>
1 parent 39e6a03 commit d785d90

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

cmd/main.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,15 @@ func runProbe(ctx context.Context, csiConn connection.CSIConnection) error {
5151
glog.Infof("CSI driver name: %q", csiDriverName)
5252
// Sending Probe request
5353
glog.Infof("Sending probe request to CSI driver.")
54-
if err := csiConn.LivenessProbe(ctx); err != nil {
55-
return err
56-
}
57-
return nil
54+
err = csiConn.LivenessProbe(ctx)
55+
return err
5856
}
5957

6058
func getCSIConnection() (connection.CSIConnection, error) {
6159
// Connect to CSI.
6260
glog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
6361
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
64-
if err != nil {
65-
return nil, err
66-
}
67-
return csiConn, nil
62+
return csiConn, err
6863
}
6964

7065
func checkHealth(w http.ResponseWriter, req *http.Request) {
@@ -73,7 +68,7 @@ func checkHealth(w http.ResponseWriter, req *http.Request) {
7368
if err != nil {
7469
w.WriteHeader(http.StatusInternalServerError)
7570
w.Write([]byte(err.Error()))
76-
glog.Infof("Failed to get connection to CSI with error: %v.", err)
71+
glog.Errorf("Failed to get connection to CSI with error: %v.", err)
7772
return
7873
}
7974
defer csiConn.Close()
@@ -82,7 +77,7 @@ func checkHealth(w http.ResponseWriter, req *http.Request) {
8277
if err := runProbe(ctx, csiConn); err != nil {
8378
w.WriteHeader(http.StatusInternalServerError)
8479
w.Write([]byte(err.Error()))
85-
glog.Infof("Health check failed with: %v.", err)
80+
glog.Errorf("Health check failed with: %v.", err)
8681
} else {
8782
w.WriteHeader(http.StatusOK)
8883
w.Write([]byte(`ok`))

pkg/connection/connection.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ func (c *csiConnection) LivenessProbe(ctx context.Context) error {
118118
req := csi.ProbeRequest{}
119119

120120
_, err := client.Probe(ctx, &req)
121-
if err != nil {
122-
return err
123-
}
124-
return nil
121+
return err
125122
}
126123

127124
func (c *csiConnection) Close() error {

0 commit comments

Comments
 (0)