Skip to content

Commit

Permalink
Merge pull request #1009 from akutz/bugfix/idempotent-error-handling
Browse files Browse the repository at this point in the history
Idempotent Errors
  • Loading branch information
akutz committed Sep 8, 2017
2 parents 2fc283c + 406fd54 commit 97dbe46
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 62 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions agent/csi/libstorage/csi_service_libstorage.go
Expand Up @@ -33,16 +33,17 @@ const (
WFDTimeout = 10
)

var (
// ctxConfigKey is an interface-wrapped key used to access a possible
// config object in the context given to the provider's Serve function
ctxConfigKey = interface{}("csi.config")
ctxExactMountKey = interface{}("exactmount")
)

func init() {
goioc.Register("libstorage", func() interface{} { return &driver{} })
}

// ctxConfigKey is an interface-wrapped key used to access a possible
// config object in the context given to the provider's Serve function
var ctxConfigKey = interface{}("csi.config")

var ctxExactMountKey = interface{}("exactmount")

type driver struct {
ctx apitypes.Context
client apitypes.Client
Expand Down Expand Up @@ -94,9 +95,12 @@ func (d *driver) Serve(ctx context.Context, lis net.Listener) error {
// Cache the node ID.
d.nodeID = toNodeID(d.iid)

szTimeout := d.config.GetString("csi.libstorage.timeout")
timeout, _ := time.ParseDuration(szTimeout)

// Create a gRPC server with an idempotent interceptor.
d.server = grpc.NewServer(
grpc.UnaryInterceptor(gocsi.NewIdempotentInterceptor(d)))
grpc.UnaryInterceptor(gocsi.NewIdempotentInterceptor(d, timeout)))

csi.RegisterControllerServer(d.server, d)
csi.RegisterIdentityServer(d.server, d)
Expand Down
21 changes: 16 additions & 5 deletions agent/csi/libstorage/csi_service_libstorage_idemp.go
Expand Up @@ -7,14 +7,17 @@ import (

"github.com/codedellemc/gocsi/csi"
"github.com/codedellemc/gocsi/mount"
xctx "golang.org/x/net/context"

apitypes "github.com/codedellemc/rexray/libstorage/api/types"
apiutils "github.com/codedellemc/rexray/libstorage/api/utils"
)

var errMissingIDKeyPath = errors.New("missing id key path")
var errMissingTokenKey = errors.New("missing token key")
var errUnableToGetLocDevs = errors.New("unable to get local devices")
var (
errMissingIDKeyPath = errors.New("missing id key path")
errMissingTokenKey = errors.New("missing token key")
errUnableToGetLocDevs = errors.New("unable to get local devices")
)

const resNotFound = "resource not found"

Expand All @@ -25,7 +28,10 @@ func isNotFoundErr(err error) bool {
// GetVolumeName should return the name of the volume specified
// by the provided volume ID. If the volume does not exist then
// an empty string should be returned.
func (d *driver) GetVolumeName(id *csi.VolumeID) (string, error) {
func (d *driver) GetVolumeName(
ctx xctx.Context,
id *csi.VolumeID) (string, error) {

idVal, ok := id.Values["id"]
if !ok {
return "", errMissingIDKeyPath
Expand Down Expand Up @@ -53,7 +59,10 @@ func (d *driver) GetVolumeName(id *csi.VolumeID) (string, error) {
// GetVolumeInfo should return information about the volume
// specified by the provided volume name. If the volume does not
// exist then a nil value should be returned.
func (d *driver) GetVolumeInfo(name string) (*csi.VolumeInfo, error) {
func (d *driver) GetVolumeInfo(
ctx xctx.Context,
name string) (*csi.VolumeInfo, error) {

td, ok := d.client.Storage().(apitypes.StorageDriverVolInspectByName)
if !ok {
return nil, fmt.Errorf(
Expand Down Expand Up @@ -82,6 +91,7 @@ func (d *driver) GetVolumeInfo(name string) (*csi.VolumeInfo, error) {
// IsControllerPublished should return publication info about
// the volume specified by the provided volume name or ID.
func (d *driver) IsControllerPublished(
ctx xctx.Context,
id *csi.VolumeID) (*csi.PublishVolumeInfo, error) {

idVal, ok := id.Values["id"]
Expand Down Expand Up @@ -121,6 +131,7 @@ func (d *driver) IsControllerPublished(
// IsNodePublished should return a flag indicating whether or
// not the volume exists and is published on the current host.
func (d *driver) IsNodePublished(
ctx xctx.Context,
id *csi.VolumeID,
pubInfo *csi.PublishVolumeInfo,
targetPath string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/codedellemc/csi-vfs/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 27 additions & 11 deletions vendor/github.com/codedellemc/csi-vfs/provider/provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions vendor/github.com/codedellemc/gocsi/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 97dbe46

Please sign in to comment.