Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Read http response body in case of volume creation failed (#54)
Browse files Browse the repository at this point in the history
This change required to get the actual error from maya-apiserver
in case of volume provisioning failed.

Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 authored and Amit Kumar Das committed Aug 10, 2018
1 parent a3f7e63 commit ad30190
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions openebs/pkg/volume/v1alpha1/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -117,16 +118,16 @@ func (v CASVolume) CreateVolume(vol v1alpha1.CASVolume) error {
}
defer resp.Body.Close()

code := resp.StatusCode
if code != http.StatusOK {
return errors.New(http.StatusText(code))
}

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
glog.Errorf("Unable to read response from maya-apiserver %v", err)
return err
}
code := resp.StatusCode
if code != http.StatusOK {
glog.Errorf("%s: failed to create volume '%s': response: %+v", http.StatusText(code), vol.Name, data)
return fmt.Errorf("%s: failed to create volume '%s': response: %+v", http.StatusText(code), vol.Name, data)
}

glog.Infof("volume Successfully Created:\n%#v", string(data))
return nil
Expand Down Expand Up @@ -201,7 +202,7 @@ func (v CASVolume) DeleteVolume(vname string, namespace string) error {

code := resp.StatusCode
if code != http.StatusOK {
return errors.New(http.StatusText(code))
return fmt.Errorf("failed to delete volume %s:%s", vname, http.StatusText(code))
}
glog.Info("volume Deleted Successfully initiated")
return nil
Expand Down

0 comments on commit ad30190

Please sign in to comment.