Skip to content

Commit

Permalink
csi: rename method checking that free write claims are available
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Feb 22, 2022
1 parent 950ccaf commit 4391a0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions nomad/structs/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ func (v *CSIVolume) WriteSchedulable() bool {
return false
}

// WriteFreeClaims determines if there are any free write claims available
func (v *CSIVolume) WriteFreeClaims() bool {
// HasFreeWriteClaims determines if there are any free write claims available
func (v *CSIVolume) HasFreeWriteClaims() bool {
switch v.AccessMode {
case CSIVolumeAccessModeSingleNodeWriter, CSIVolumeAccessModeMultiNodeSingleWriter:
return len(v.WriteClaims) == 0
Expand Down Expand Up @@ -560,7 +560,7 @@ func (v *CSIVolume) claimWrite(claim *CSIVolumeClaim, alloc *Allocation) error {
return fmt.Errorf("unschedulable")
}

if !v.WriteFreeClaims() {
if !v.HasFreeWriteClaims() {
// Check the blocking allocations to see if they belong to this job
for _, a := range v.WriteAllocs {
if a != nil && (a.Namespace != alloc.Namespace || a.JobID != alloc.JobID) {
Expand Down
32 changes: 16 additions & 16 deletions nomad/structs/csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestCSIVolumeClaim(t *testing.T) {
require.NoError(vol.Claim(claim, alloc1))
require.True(vol.ReadSchedulable())
require.False(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.PastClaims, 0)
Expand All @@ -61,7 +61,7 @@ func TestCSIVolumeClaim(t *testing.T) {
require.EqualError(vol.Claim(claim, alloc2), "unschedulable")
require.True(vol.ReadSchedulable())
require.False(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.PastClaims, 0)
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestCSIVolumeClaim(t *testing.T) {
require.NoError(vol.Claim(claim, alloc2))
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 0)
require.Len(vol.WriteClaims, 1)
require.Len(vol.PastClaims, 0)
Expand All @@ -121,7 +121,7 @@ func TestCSIVolumeClaim(t *testing.T) {
require.NoError(vol.Claim(claim, alloc1))
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 1)
require.Len(vol.PastClaims, 0)
Expand All @@ -148,7 +148,7 @@ func TestCSIVolumeClaim(t *testing.T) {
vol.Claim(claim, nil)
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 1) // claim still exists until we're done
require.Len(vol.PastClaims, 1)
Expand All @@ -160,7 +160,7 @@ func TestCSIVolumeClaim(t *testing.T) {
vol.Claim(claim, nil)
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.True(vol.WriteFreeClaims())
require.True(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.WriteAllocs, 0)
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestCSIVolumeClaim_CompatOldClaims(t *testing.T) {
require.NoError(vol.Claim(claim, alloc1))
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.True(vol.WriteFreeClaims())
require.True(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.PastClaims, 0)
Expand All @@ -226,7 +226,7 @@ func TestCSIVolumeClaim_CompatOldClaims(t *testing.T) {
require.NoError(vol.Claim(claim, alloc2))
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 1)
require.Len(vol.PastClaims, 0)
Expand All @@ -246,7 +246,7 @@ func TestCSIVolumeClaim_CompatOldClaims(t *testing.T) {
vol.Claim(claim, nil)
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 1) // claim still exists until we're done
require.Len(vol.PastClaims, 1)
Expand All @@ -258,7 +258,7 @@ func TestCSIVolumeClaim_CompatOldClaims(t *testing.T) {
vol.Claim(claim, nil)
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.True(vol.WriteFreeClaims())
require.True(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.WriteAllocs, 0)
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestCSIVolumeClaim_CompatNewClaimsOK(t *testing.T) {
require.NoError(vol.Claim(claim, alloc1))
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.True(vol.WriteFreeClaims())
require.True(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.PastClaims, 0)
Expand All @@ -325,7 +325,7 @@ func TestCSIVolumeClaim_CompatNewClaimsOK(t *testing.T) {
require.NoError(vol.Claim(claim, alloc2))
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 1)
require.Len(vol.PastClaims, 0)
Expand All @@ -351,7 +351,7 @@ func TestCSIVolumeClaim_CompatNewClaimsOK(t *testing.T) {
vol.Claim(claim, nil)
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 1) // claim still exists until we're done
require.Len(vol.PastClaims, 1)
Expand All @@ -363,7 +363,7 @@ func TestCSIVolumeClaim_CompatNewClaimsOK(t *testing.T) {
vol.Claim(claim, nil)
require.True(vol.ReadSchedulable())
require.True(vol.WriteSchedulable())
require.True(vol.WriteFreeClaims())
require.True(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.WriteAllocs, 0)
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestCSIVolumeClaim_CompatNewClaimsNoUpgrade(t *testing.T) {
require.NoError(vol.Claim(claim, alloc1))
require.True(vol.ReadSchedulable())
require.False(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.PastClaims, 0)
Expand All @@ -431,7 +431,7 @@ func TestCSIVolumeClaim_CompatNewClaimsNoUpgrade(t *testing.T) {
require.EqualError(vol.Claim(claim, alloc2), "unschedulable")
require.True(vol.ReadSchedulable())
require.False(vol.WriteSchedulable())
require.False(vol.WriteFreeClaims())
require.False(vol.HasFreeWriteClaims())
require.Len(vol.ReadClaims, 1)
require.Len(vol.WriteClaims, 0)
require.Len(vol.PastClaims, 0)
Expand Down
2 changes: 1 addition & 1 deletion scheduler/feasible.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (c *CSIVolumeChecker) isFeasible(n *structs.Node) (bool, string) {
if !vol.WriteSchedulable() {
return false, fmt.Sprintf(FilterConstraintCSIVolumeNoWriteTemplate, vol.ID)
}
if !vol.WriteFreeClaims() {
if !vol.HasFreeWriteClaims() {
for id := range vol.WriteAllocs {
a, err := c.ctx.State().AllocByID(ws, id)
// the alloc for this blocking claim has been
Expand Down

0 comments on commit 4391a0a

Please sign in to comment.