Make testing example more complex; improve handling for NodeUnpublishVolume/ControllerUnpublishVolume for volumes that were externally deleted

This commit is contained in:
2024-10-02 00:05:26 -04:00
parent beee5a441d
commit 96956ba7ff
4 changed files with 76 additions and 6 deletions

View File

@@ -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 {