Skip to content

Commit 75b1fbb

Browse files
[cinder-csi-plugin] ephemeral volume removal (#2602)
Disable creating new deprecated ephemeral volumes Signed-off-by: Serge Logvinov <[email protected]>
1 parent 515b4c9 commit 75b1fbb

File tree

2 files changed

+7
-146
lines changed

2 files changed

+7
-146
lines changed

pkg/csi/cinder/nodeserver.go

Lines changed: 3 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24-
"strconv"
2524
"strings"
2625

2726
"github.com/container-storage-interface/spec/lib/go/csi"
@@ -68,22 +67,14 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
6867

6968
ephemeralVolume := req.GetVolumeContext()["csi.storage.k8s.io/ephemeral"] == "true"
7069
if ephemeralVolume {
71-
// See https://github.com/kubernetes/cloud-provider-openstack/issues/1493
72-
klog.Warningf("CSI inline ephemeral volumes support is deprecated in 1.24 release.")
73-
return nodePublishEphemeral(req, ns)
70+
// See https://github.com/kubernetes/cloud-provider-openstack/issues/2599
71+
return nil, status.Error(codes.Unimplemented, "CSI inline ephemeral volumes support is removed in 1.31 release.")
7472
}
7573

7674
// In case of ephemeral volume staging path not provided
7775
if len(source) == 0 {
7876
return nil, status.Error(codes.InvalidArgument, "NodePublishVolume Staging Target Path must be provided")
7977
}
80-
_, err := ns.Cloud.GetVolume(volumeID)
81-
if err != nil {
82-
if cpoerrors.IsNotFound(err) {
83-
return nil, status.Error(codes.NotFound, "Volume not found")
84-
}
85-
return nil, status.Errorf(codes.Internal, "GetVolume failed with error %v", err)
86-
}
8778

8879
mountOptions := []string{"bind"}
8980
if req.GetReadonly() {
@@ -121,105 +112,6 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
121112
return &csi.NodePublishVolumeResponse{}, nil
122113
}
123114

124-
func nodePublishEphemeral(req *csi.NodePublishVolumeRequest, ns *nodeServer) (*csi.NodePublishVolumeResponse, error) {
125-
126-
var size int
127-
var err error
128-
129-
volID := req.GetVolumeId()
130-
volName := fmt.Sprintf("ephemeral-%s", volID)
131-
properties := map[string]string{"cinder.csi.openstack.org/cluster": ns.Driver.cluster}
132-
capacity, ok := req.GetVolumeContext()["capacity"]
133-
134-
volAvailability, err := ns.Metadata.GetAvailabilityZone()
135-
if err != nil {
136-
return nil, status.Errorf(codes.Internal, "retrieving availability zone from MetaData service failed with error %v", err)
137-
}
138-
139-
size = 1 // default size is 1GB
140-
if ok && strings.HasSuffix(capacity, "Gi") {
141-
size, err = strconv.Atoi(strings.TrimSuffix(capacity, "Gi"))
142-
if err != nil {
143-
klog.V(3).Infof("Unable to parse capacity: %v", err)
144-
return nil, status.Errorf(codes.Internal, "Unable to parse capacity %v", err)
145-
}
146-
}
147-
148-
// Check type in given param, if not, use ""
149-
volumeType, ok := req.GetVolumeContext()["type"]
150-
if !ok {
151-
volumeType = ""
152-
}
153-
154-
evol, err := ns.Cloud.CreateVolume(volName, size, volumeType, volAvailability, "", "", "", properties)
155-
156-
if err != nil {
157-
klog.V(3).Infof("Failed to Create Ephemeral Volume: %v", err)
158-
return nil, status.Errorf(codes.Internal, "Failed to create Ephemeral Volume %v", err)
159-
}
160-
161-
// Wait for volume status to be Available, before attaching
162-
if evol.Status != openstack.VolumeAvailableStatus {
163-
targetStatus := []string{openstack.VolumeAvailableStatus}
164-
err := ns.Cloud.WaitVolumeTargetStatus(evol.ID, targetStatus)
165-
if err != nil {
166-
return nil, status.Error(codes.Internal, err.Error())
167-
}
168-
}
169-
170-
klog.V(4).Infof("Ephemeral Volume %s is created", evol.ID)
171-
172-
// attach volume
173-
// for attach volume we need to have information about node.
174-
nodeID, err := ns.Metadata.GetInstanceID()
175-
if err != nil {
176-
msg := "nodePublishEphemeral: Failed to get Instance ID: %v"
177-
klog.V(3).Infof(msg, err)
178-
return nil, status.Errorf(codes.Internal, msg, err)
179-
}
180-
181-
_, err = ns.Cloud.AttachVolume(nodeID, evol.ID)
182-
if err != nil {
183-
msg := "nodePublishEphemeral: attach volume %s failed with error: %v"
184-
klog.V(3).Infof(msg, evol.ID, err)
185-
return nil, status.Errorf(codes.Internal, msg, evol.ID, err)
186-
}
187-
188-
err = ns.Cloud.WaitDiskAttached(nodeID, evol.ID)
189-
if err != nil {
190-
return nil, status.Error(codes.Internal, err.Error())
191-
}
192-
193-
m := ns.Mount
194-
195-
devicePath, err := getDevicePath(evol.ID, m)
196-
if err != nil {
197-
return nil, status.Errorf(codes.Internal, "Unable to find Device path for volume: %v", err)
198-
}
199-
200-
targetPath := req.GetTargetPath()
201-
202-
// Verify whether mounted
203-
notMnt, err := m.IsLikelyNotMountPointAttach(targetPath)
204-
if err != nil {
205-
return nil, status.Error(codes.Internal, err.Error())
206-
}
207-
208-
// Volume Mount
209-
if notMnt {
210-
// set default fstype is ext4
211-
fsType := "ext4"
212-
// Mount
213-
err = m.Mounter().FormatAndMount(devicePath, targetPath, fsType, nil)
214-
if err != nil {
215-
return nil, status.Error(codes.Internal, err.Error())
216-
}
217-
}
218-
219-
return &csi.NodePublishVolumeResponse{}, nil
220-
221-
}
222-
223115
func nodePublishVolumeForBlock(req *csi.NodePublishVolumeRequest, ns *nodeServer, mountOptions []string) (*csi.NodePublishVolumeResponse, error) {
224116
klog.V(4).Infof("NodePublishVolumeBlock: called with args %+v", protosanitizer.StripSecrets(*req))
225117

@@ -274,7 +166,6 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
274166
ephemeralVolume := false
275167

276168
vol, err := ns.Cloud.GetVolume(volumeID)
277-
278169
if err != nil {
279170

280171
if !cpoerrors.IsNotFound(err) {
@@ -459,16 +350,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
459350
return nil, status.Error(codes.InvalidArgument, "NodeUnstageVolume Staging Target Path must be provided")
460351
}
461352

462-
_, err := ns.Cloud.GetVolume(volumeID)
463-
if err != nil {
464-
if cpoerrors.IsNotFound(err) {
465-
klog.V(4).Infof("NodeUnstageVolume: Unable to find volume: %v", err)
466-
return nil, status.Error(codes.NotFound, "Volume not found")
467-
}
468-
return nil, status.Errorf(codes.Internal, "GetVolume failed with error %v", err)
469-
}
470-
471-
err = ns.Mount.UnmountPath(stagingTargetPath)
353+
err := ns.Mount.UnmountPath(stagingTargetPath)
472354
if err != nil {
473355
return nil, status.Errorf(codes.Internal, "Unmount of targetPath %s failed with error %v", stagingTargetPath, err)
474356
}

pkg/csi/cinder/nodeserver_test.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424

2525
"github.com/container-storage-interface/spec/lib/go/csi"
2626
"github.com/stretchr/testify/assert"
27+
"google.golang.org/grpc/codes"
28+
"google.golang.org/grpc/status"
2729
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
2830
"k8s.io/cloud-provider-openstack/pkg/util/metadata"
2931
"k8s.io/cloud-provider-openstack/pkg/util/mount"
@@ -129,31 +131,13 @@ func TestNodePublishVolumeEphermeral(t *testing.T) {
129131

130132
properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}
131133
fvolName := fmt.Sprintf("ephemeral-%s", FakeVolID)
132-
tState := []string{"available"}
133134

134135
omock.On("CreateVolume", fvolName, 2, "test", "nova", "", "", "", properties).Return(&FakeVol, nil)
135136

136-
omock.On("AttachVolume", FakeNodeID, FakeVolID).Return(FakeVolID, nil)
137-
omock.On("WaitDiskAttached", FakeNodeID, FakeVolID).Return(nil)
138-
omock.On("WaitVolumeTargetStatus", FakeVolID, tState).Return(nil)
139-
mmock.On("GetDevicePath", FakeVolID).Return(FakeDevicePath, nil)
140-
mmock.On("IsLikelyNotMountPointAttach", FakeTargetPath).Return(true, nil)
141-
metamock.On("GetAvailabilityZone").Return(FakeAvailability, nil)
142-
143-
mount.MInstance = mmock
144-
metadata.MetadataService = metamock
145-
openstack.OsInstances = map[string]openstack.IOpenStack{
146-
"": omock,
147-
}
148-
149-
d := NewDriver(&DriverOpts{Endpoint: FakeEndpoint, ClusterID: FakeCluster})
150-
fakeNse := NewNodeServer(d, mount.MInstance, metadata.MetadataService, openstack.OsInstances[""], map[string]string{})
151-
152137
// Init assert
153138
assert := assert.New(t)
154139

155140
// Expected Result
156-
expectedRes := &csi.NodePublishVolumeResponse{}
157141
stdVolCap := &csi.VolumeCapability{
158142
AccessType: &csi.VolumeCapability_Mount{
159143
Mount: &csi.VolumeCapability_MountVolume{},
@@ -174,13 +158,8 @@ func TestNodePublishVolumeEphermeral(t *testing.T) {
174158
}
175159

176160
// Invoke NodePublishVolume
177-
actualRes, err := fakeNse.NodePublishVolume(FakeCtx, fakeReq)
178-
if err != nil {
179-
t.Errorf("failed to NodePublishVolume: %v", err)
180-
}
181-
182-
// Assert
183-
assert.Equal(expectedRes, actualRes)
161+
_, err := fakeNs.NodePublishVolume(FakeCtx, fakeReq)
162+
assert.Equal(status.Error(codes.Unimplemented, "CSI inline ephemeral volumes support is removed in 1.31 release."), err)
184163
}
185164

186165
// Test NodeStageVolume

0 commit comments

Comments
 (0)