Skip to content

Commit

Permalink
csi: enforce single-node reader check for read-only volumes
Browse files Browse the repository at this point in the history
When the alloc runner makes a claim for a read-only volume, we only
check that the volume is potentially schedulable and not that it
actually has free read claims.
  • Loading branch information
tgross committed Feb 23, 2022
1 parent 3128710 commit 85c086e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,26 @@ func (v *CSIVolume) WriteSchedulable() bool {
return false
}

// HasFreeReadClaims determines if there are any free read claims available
func (v *CSIVolume) HasFreeReadClaims() bool {
switch v.AccessMode {
case CSIVolumeAccessModeSingleNodeReader:
return len(v.ReadClaims) == 0
case CSIVolumeAccessModeSingleNodeWriter:
return len(v.ReadClaims) == 0 && len(v.WriteClaims) == 0
case CSIVolumeAccessModeUnknown:
// This volume was created but not yet claimed, so its
// capabilities have been checked in ReadSchedulable
return true
default:
// For multi-node AccessModes, the CSI spec doesn't allow for
// setting a max number of readers we track node resource
// exhaustion through v.ResourceExhausted which is checked in
// ReadSchedulable
return true
}
}

// HasFreeWriteClaims determines if there are any free write claims available
func (v *CSIVolume) HasFreeWriteClaims() bool {
switch v.AccessMode {
Expand Down Expand Up @@ -527,6 +547,10 @@ func (v *CSIVolume) claimRead(claim *CSIVolumeClaim, alloc *Allocation) error {
return ErrCSIVolumeUnschedulable
}

if !v.HasFreeReadClaims() {
return ErrCSIVolumeMaxClaims
}

// Allocations are copy on write, so we want to keep the id but don't need the
// pointer. We'll get it from the db in denormalize.
v.ReadAllocs[claim.AllocationID] = nil
Expand Down

0 comments on commit 85c086e

Please sign in to comment.