Skip to content

Commit

Permalink
fix: ruduce time complexity by modifying the data structure
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Nov 6, 2024
1 parent ccf133c commit ac313c3
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions pkg/driver/controller_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const BytesInGigabyte int64 = 1024 * 1024 * 1024
// CivoVolumeAvailableRetries is the number of times we will retry to check if a volume is available
const CivoVolumeAvailableRetries int = 20

var supportedAccessModes = []csi.VolumeCapability_AccessMode_Mode{
csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY,
var supportedAccessModes = map[csi.VolumeCapability_AccessMode_Mode]struct{}{
csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER: struct{}{},
csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY: struct{}{},
}

// CreateVolume is the first step when a PVC tries to create a dynamic volume
Expand All @@ -40,17 +40,9 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)

// Check capabilities
for _, cap := range req.VolumeCapabilities {
modeSupported := false
for _, mode := range supportedAccessModes {
if cap.GetAccessMode().GetMode() == mode {
modeSupported = true
}
}

if !modeSupported {
if _, ok := supportedAccessModes[cap.GetAccessMode().GetMode()]; !ok {
return nil, status.Error(codes.InvalidArgument, "CreateVolume access mode isn't supported")
}

if _, ok := cap.GetAccessType().(*csi.VolumeCapability_Block); ok {
return nil, status.Error(codes.InvalidArgument, "CreateVolume block types aren't supported, only mount types")
}
Expand Down Expand Up @@ -474,10 +466,9 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida

accessModeSupported := false
for _, cap := range req.VolumeCapabilities {
for _, m := range supportedAccessModes {
if m == cap.AccessMode.Mode {
accessModeSupported = true
}
if _, ok := supportedAccessModes[cap.GetAccessMode().GetMode()]; ok {
accessModeSupported = true
break
}
}

Expand Down

0 comments on commit ac313c3

Please sign in to comment.