Skip to content

Commit 8183d3a

Browse files
committed
Add support for legacy storage operations
Signed-off-by: Niclas Schad <niclas.schad@stackit.cloud>
1 parent 2909798 commit 8183d3a

4 files changed

Lines changed: 48 additions & 16 deletions

File tree

cmd/stackit-csi-plugin/main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var (
2424
httpEndpoint string
2525
provideControllerService bool
2626
provideNodeService bool
27+
legacyStorageMode bool
2728
)
2829

2930
func main() {
@@ -72,6 +73,8 @@ func main() {
7273
"If set to true then the CSI driver does provide the controller service (default: true)")
7374
cmd.PersistentFlags().BoolVar(&provideNodeService, "provide-node-service", true,
7475
"If set to true then the CSI driver does provide the node service (default: true)")
76+
cmd.PersistentFlags().BoolVar(&legacyStorageMode, "legacy-storage-mode", false,
77+
"Configures the CSI to listen to the legacy storage driverName cinder.csi.openstack.org instead")
7578

7679
stackit.AddExtraFlags(pflag.CommandLine)
7780

@@ -81,11 +84,17 @@ func main() {
8184

8285
func handle() {
8386
// Initialize cloud
84-
d := blockstorage.NewDriver(&blockstorage.DriverOpts{
87+
driverOpts := &blockstorage.DriverOpts{
8588
Endpoint: endpoint,
8689
ClusterID: cluster,
8790
PVCLister: csi.GetPVCLister(),
88-
})
91+
}
92+
93+
if legacyStorageMode {
94+
driverOpts.LegacyDriverName = true
95+
}
96+
97+
d := blockstorage.NewDriver(driverOpts)
8998

9099
if provideControllerService {
91100
var err error

pkg/csi/blockstorage/controllerserver.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
112112
accessibleTopologyReq := req.GetAccessibilityRequirements()
113113
// Check from topology
114114
if accessibleTopologyReq != nil {
115-
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
115+
if cs.Driver.legacyDriver {
116+
volAvailability = sharedcsi.GetAZFromTopology(legacyTopologyKey, accessibleTopologyReq)
117+
} else {
118+
volAvailability = sharedcsi.GetAZFromTopology(topologyKey, accessibleTopologyReq)
119+
}
116120
}
117121
}
118122

@@ -131,7 +135,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
131135
return nil, status.Error(codes.Internal, fmt.Sprintf("Volume %s is not in available state", *vols[0].Id))
132136
}
133137
klog.V(4).Infof("Volume %s already exists in Availability Zone: %s of size %d GiB", *vols[0].Id, *vols[0].AvailabilityZone, *vols[0].Size)
134-
return getCreateVolumeResponse(&vols[0]), nil
138+
return cs.getCreateVolumeResponse(&vols[0]), nil
135139
} else if len(vols) > 1 {
136140
klog.V(3).Infof("found multiple existing volumes with selected name (%s) during create", volName)
137141
return nil, status.Error(codes.Internal, "Multiple volumes reported by Cinder with same name")
@@ -274,7 +278,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
274278

275279
klog.V(4).Infof("CreateVolume: Successfully created volume %s in Availability Zone: %s of size %d GiB", *vol.Id, *vol.AvailabilityZone, *vol.Size)
276280

277-
return getCreateVolumeResponse(vol), nil
281+
return cs.getCreateVolumeResponse(vol), nil
278282
}
279283

280284
func setVolumeEncryptionParameters(opts *iaas.CreateVolumePayload, volParams *stackitParameterConfig) error {
@@ -957,7 +961,7 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
957961
}, nil
958962
}
959963

960-
func getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {
964+
func (cs *controllerServer) getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {
961965
var volsrc *csi.VolumeContentSource
962966
var volumeSourceType stackit.VolumeSourceTypes
963967
volCnx := map[string]string{}
@@ -998,9 +1002,14 @@ func getCreateVolumeResponse(vol *iaas.Volume) *csi.CreateVolumeResponse {
9981002
}
9991003
}
10001004

1005+
topoKey := topologyKey
1006+
if cs.Driver.legacyDriver {
1007+
topoKey = legacyTopologyKey
1008+
}
1009+
10011010
accessibleTopology := []*csi.Topology{
10021011
{
1003-
Segments: map[string]string{topologyKey: ptr.Deref(vol.AvailabilityZone, "")},
1012+
Segments: map[string]string{topoKey: ptr.Deref(vol.AvailabilityZone, "")},
10041013
},
10051014
}
10061015

pkg/csi/blockstorage/driver.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
)
1515

1616
const (
17-
driverName = "block-storage.csi.stackit.cloud"
18-
topologyKey = "topology." + driverName + "/zone"
17+
driverName = "block-storage.csi.stackit.cloud"
18+
legacyDriverName = "cinder.csi.openstack.org"
19+
topologyKey = "topology." + driverName + "/zone"
20+
legacyTopologyKey = "topology." + legacyDriverName + "/zone"
1921

2022
// ResizeRequired parameter, if set to true, will trigger a resize on mount operation
2123
ResizeRequired = driverName + "/resizeRequired"
@@ -28,10 +30,11 @@ var (
2830
)
2931

3032
type Driver struct {
31-
name string
32-
fqVersion string // Fully qualified version in format {Version}@{CPO version}
33-
endpoint string
34-
clusterID string
33+
name string
34+
fqVersion string // Fully qualified version in format {Version}@{CPO version}
35+
endpoint string
36+
clusterID string
37+
legacyDriver bool
3538

3639
ids *identityServer
3740
cs *controllerServer
@@ -46,8 +49,9 @@ type Driver struct {
4649
}
4750

4851
type DriverOpts struct {
49-
ClusterID string
50-
Endpoint string
52+
ClusterID string
53+
Endpoint string
54+
LegacyDriverName bool
5155

5256
PVCLister corev1.PersistentVolumeClaimLister
5357
}
@@ -61,6 +65,11 @@ func NewDriver(o *DriverOpts) *Driver {
6165
pvcLister: o.PVCLister,
6266
}
6367

68+
if o.LegacyDriverName {
69+
d.name = legacyDriverName
70+
d.legacyDriver = true
71+
}
72+
6473
klog.Info("Driver: ", d.name)
6574
klog.Info("Driver version: ", d.fqVersion)
6675
klog.Info("CSI Spec version: ", specVersion)

pkg/csi/blockstorage/nodeserver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,14 @@ func (ns *nodeServer) NodeGetInfo(ctx context.Context, _ *csi.NodeGetInfoRequest
322322
return nil, status.Errorf(codes.Internal, "[NodeGetInfo] Unable to retrieve availability zone of node %v", err)
323323
}
324324

325+
topoKey := topologyKey
326+
if ns.Driver.legacyDriver {
327+
topoKey = legacyTopologyKey
328+
}
329+
325330
//TODO: support well-known topology key "topology.kubernetes.io/zone"
326331
segments := map[string]string{
327-
topologyKey: zone,
332+
topoKey: zone,
328333
}
329334

330335
nodeInfo.AccessibleTopology = &csi.Topology{Segments: segments}

0 commit comments

Comments
 (0)