Skip to content

Commit 7efefcc

Browse files
committed
add flag to block volume creation
Signed-off-by: Niclas Schad <niclas.schad@stackit.cloud>
1 parent 3a6610a commit 7efefcc

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

cmd/stackit-csi-plugin/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
provideControllerService bool
2626
provideNodeService bool
2727
legacyStorageMode bool
28+
blockVolumeCreation bool
2829
)
2930

3031
func main() {
@@ -75,6 +76,7 @@ func main() {
7576
"If set to true then the CSI driver does provide the node service (default: true)")
7677
cmd.PersistentFlags().BoolVar(&legacyStorageMode, "legacy-storage-mode", false,
7778
"Configures the CSI to listen to the legacy storage driverName cinder.csi.openstack.org instead")
79+
cmd.PersistentFlags().BoolVar(&blockVolumeCreation, "block-volume-creation", false, "Block volume creation")
7880

7981
stackit.AddExtraFlags(pflag.CommandLine)
8082

@@ -94,6 +96,10 @@ func handle() {
9496
driverOpts.LegacyDriverName = true
9597
}
9698

99+
if blockVolumeCreation {
100+
driverOpts.BlockVolumeCreation = true
101+
}
102+
97103
d := blockstorage.NewDriver(driverOpts)
98104

99105
if provideControllerService {

pkg/csi/blockstorage/controllerserver.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
7777

7878
cloud := cs.Instance
7979

80+
if cs.Driver.blockVolumeCreation {
81+
return nil, status.Error(codes.FailedPrecondition, "CSI driver is in read/update-only mode")
82+
}
83+
8084
// Volume Name
8185
volName := req.GetName()
8286
volCapabilities := req.GetVolumeCapabilities()
@@ -476,6 +480,10 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
476480

477481
cloud := cs.Instance
478482

483+
if cs.Driver.blockVolumeCreation {
484+
return nil, status.Error(codes.FailedPrecondition, "The old driver is update/read-only mode please migrate to the new driver")
485+
}
486+
479487
name := req.Name
480488
volumeID := req.GetSourceVolumeId()
481489
snapshotType := req.Parameters[stackit.SnapshotType]

pkg/csi/blockstorage/driver.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ var (
3131
)
3232

3333
type Driver struct {
34-
name string
35-
fqVersion string // Fully qualified version in format {Version}@{CPO version}
36-
endpoint string
37-
clusterID string
38-
legacyDriver bool
34+
name string
35+
fqVersion string // Fully qualified version in format {Version}@{CPO version}
36+
endpoint string
37+
clusterID string
38+
legacyDriver bool
39+
blockVolumeCreation bool
3940

4041
ids *identityServer
4142
cs *controllerServer
@@ -50,9 +51,10 @@ type Driver struct {
5051
}
5152

5253
type DriverOpts struct {
53-
ClusterID string
54-
Endpoint string
55-
LegacyDriverName bool
54+
ClusterID string
55+
Endpoint string
56+
LegacyDriverName bool
57+
BlockVolumeCreation bool
5658

5759
PVCLister corev1.PersistentVolumeClaimLister
5860
}
@@ -71,6 +73,10 @@ func NewDriver(o *DriverOpts) *Driver {
7173
d.legacyDriver = true
7274
}
7375

76+
if o.BlockVolumeCreation {
77+
d.blockVolumeCreation = true
78+
}
79+
7480
klog.Info("Driver: ", d.name)
7581
klog.Info("Driver version: ", d.fqVersion)
7682
klog.Info("CSI Spec version: ", specVersion)

0 commit comments

Comments
 (0)