Make testing example more complex; improve handling for NodeUnpublishVolume/ControllerUnpublishVolume for volumes that were externally deleted
This commit is contained in:
parent
beee5a441d
commit
96956ba7ff
@ -2,7 +2,33 @@
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
metadata:
|
metadata:
|
||||||
name: example-pvc
|
name: example-pvc-1
|
||||||
|
namespace: p5x-system
|
||||||
|
spec:
|
||||||
|
storageClassName: p5x
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 5Gi
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: example-pvc-2
|
||||||
|
namespace: p5x-system
|
||||||
|
spec:
|
||||||
|
storageClassName: p5x
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 5Gi
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: example-pvc-3
|
||||||
namespace: p5x-system
|
namespace: p5x-system
|
||||||
spec:
|
spec:
|
||||||
storageClassName: p5x
|
storageClassName: p5x
|
||||||
@ -15,7 +41,7 @@ spec:
|
|||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
metadata:
|
||||||
name: example-pod
|
name: example-pod-1
|
||||||
namespace: p5x-system
|
namespace: p5x-system
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
@ -24,9 +50,33 @@ spec:
|
|||||||
command: ['/bin/bash', '-c', '--']
|
command: ['/bin/bash', '-c', '--']
|
||||||
args: ['while true; do sleep 30; done;']
|
args: ['while true; do sleep 30; done;']
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- mountPath: '/mnt/example-pvc'
|
- mountPath: '/mnt/example-pvc-1'
|
||||||
name: example-pvc
|
name: example-pvc-1
|
||||||
|
- mountPath: '/mnt/example-pvc-2'
|
||||||
|
name: example-pvc-2
|
||||||
volumes:
|
volumes:
|
||||||
- name: example-pvc
|
- name: example-pvc-1
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
claimName: example-pvc
|
claimName: example-pvc-1
|
||||||
|
- name: example-pvc-2
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: example-pvc-2
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: example-pod-2
|
||||||
|
namespace: p5x-system
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: example-ct
|
||||||
|
image: fedora:39
|
||||||
|
command: ['/bin/bash', '-c', '--']
|
||||||
|
args: ['while true; do sleep 30; done;']
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: '/mnt/example-pvc-3'
|
||||||
|
name: example-pvc-3
|
||||||
|
volumes:
|
||||||
|
- name: example-pvc-3
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: example-pvc-3
|
@ -18,6 +18,7 @@ package csi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"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())
|
vol, err := d.p5x.GetVolumeByName(request.GetVolumeId())
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package csi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"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())
|
vol, err := n.p5x.GetVolumeByName(request.GetVolumeId())
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,12 @@ package csi
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type p5xApi struct {
|
type p5xApi struct {
|
||||||
@ -45,6 +47,8 @@ func (p5x *p5xApi) CreateVolume(name string, sizeInBytes int64) (*p5xVolume, err
|
|||||||
return vol, nil
|
return vol, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrVolumeNotFound = errors.New("p5x volume not found")
|
||||||
|
|
||||||
func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) {
|
func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) {
|
||||||
klog.Infof("p5x.GetVolumeByName: %s", name)
|
klog.Infof("p5x.GetVolumeByName: %s", name)
|
||||||
route := fmt.Sprintf("volumes/%s", name)
|
route := fmt.Sprintf("volumes/%s", name)
|
||||||
@ -53,6 +57,10 @@ func (p5x *p5xApi) GetVolumeByName(name string) (*p5xVolume, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(string(resBody[:]), "Could not find volume with the name") {
|
||||||
|
return nil, ErrVolumeNotFound
|
||||||
|
}
|
||||||
|
|
||||||
vol := &p5xVolume{}
|
vol := &p5xVolume{}
|
||||||
err = json.Unmarshal(resBody, vol)
|
err = json.Unmarshal(resBody, vol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user