Make testing example more complex; improve handling for NodeUnpublishVolume/ControllerUnpublishVolume for volumes that were externally deleted
This commit is contained in:
@@ -18,6 +18,7 @@ package csi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"k8s.io/klog"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
@@ -90,6 +91,11 @@ func (d *controllerService) DeleteVolume(ctx context.Context, request *csi.Delet
|
||||
|
||||
vol, err := d.p5x.GetVolumeByName(request.GetVolumeId())
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrVolumeNotFound) {
|
||||
klog.Infof("controller.DeleteVolume: Could not find volume %s -- assuming it has already been deleted", request.GetVolumeId())
|
||||
return &csi.DeleteVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package csi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"k8s.io/klog"
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
@@ -131,6 +132,11 @@ func (n *nodeService) NodeUnpublishVolume(ctx context.Context, request *csi.Node
|
||||
|
||||
vol, err := n.p5x.GetVolumeByName(request.GetVolumeId())
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrVolumeNotFound) {
|
||||
klog.Infof("node.NodeUnpublishVolume: Could not find volume %s - assuming it has already been deleted", request.GetVolumeId())
|
||||
return &csi.NodeUnpublishVolumeResponse{}, nil
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@ package csi
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"k8s.io/klog"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type p5xApi struct {
|
||||
@@ -45,6 +47,8 @@ func (p5x *p5xApi) CreateVolume(name string, sizeInBytes int64) (*p5xVolume, err
|
||||
return vol, nil
|
||||
}
|
||||
|
||||
var ErrVolumeNotFound = errors.New("p5x volume not found")
|
||||
|
||||
func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) {
|
||||
klog.Infof("p5x.GetVolumeByName: %s", name)
|
||||
route := fmt.Sprintf("volumes/%s", name)
|
||||
@@ -53,6 +57,10 @@ func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if strings.Contains(string(resBody[:]), "Could not find volume with the name") {
|
||||
return nil, ErrVolumeNotFound
|
||||
}
|
||||
|
||||
vol := &p5xVolume{}
|
||||
err = json.Unmarshal(resBody, vol)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user