Skip to content

Commit

Permalink
Fix redundant error check
Browse files Browse the repository at this point in the history
This PR fixes
* Removes redundant error check
* use `glog.Errorf` to log in case of an error.

Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
  • Loading branch information
Madhu-1 committed Dec 21, 2018
1 parent 39e6a03 commit d785d90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
15 changes: 5 additions & 10 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ func runProbe(ctx context.Context, csiConn connection.CSIConnection) error {
glog.Infof("CSI driver name: %q", csiDriverName)
// Sending Probe request
glog.Infof("Sending probe request to CSI driver.")
if err := csiConn.LivenessProbe(ctx); err != nil {
return err
}
return nil
err = csiConn.LivenessProbe(ctx)
return err
}

func getCSIConnection() (connection.CSIConnection, error) {
// Connect to CSI.
glog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
if err != nil {
return nil, err
}
return csiConn, nil
return csiConn, err
}

func checkHealth(w http.ResponseWriter, req *http.Request) {
Expand All @@ -73,7 +68,7 @@ func checkHealth(w http.ResponseWriter, req *http.Request) {
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
glog.Infof("Failed to get connection to CSI with error: %v.", err)
glog.Errorf("Failed to get connection to CSI with error: %v.", err)
return
}
defer csiConn.Close()
Expand All @@ -82,7 +77,7 @@ func checkHealth(w http.ResponseWriter, req *http.Request) {
if err := runProbe(ctx, csiConn); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
glog.Infof("Health check failed with: %v.", err)
glog.Errorf("Health check failed with: %v.", err)
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`ok`))
Expand Down
5 changes: 1 addition & 4 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ func (c *csiConnection) LivenessProbe(ctx context.Context) error {
req := csi.ProbeRequest{}

_, err := client.Probe(ctx, &req)
if err != nil {
return err
}
return nil
return err
}

func (c *csiConnection) Close() error {
Expand Down

0 comments on commit d785d90

Please sign in to comment.