From 51007f5ae1b8942c05569aad2e822d51a8b8a2fd Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Wed, 7 Oct 2020 08:48:15 -0400 Subject: [PATCH] csi: allow more than 1 writer claim for multi-writer mode Fixes a bug where CSI volumes with the `MULTI_NODE_MULTI_WRITER` access mode were using the same logic as `MULTI_NODE_SINGLE_WRITER` to determine whether the volume had writer claims available for scheduling. --- CHANGELOG.md | 1 + nomad/structs/csi.go | 7 ++++++- nomad/structs/csi_test.go | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 823b2b729b9a..8b1ad6ae0fb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ IMPROVEMENTS: * client: Added support for fingerprinting the client node's Consul segment. [[GH-7214](https://github.com/hashicorp/nomad/issues/7214)] * client: Updated consul-template to v0.25.0 - config function_blacklist deprecated and replaced with function_denylist [[GH-8988](https://github.com/hashicorp/nomad/pull/8988)] * consul: Support Consul namespace (Consul Enterprise) in client configuration. [[GH-8849](https://github.com/hashicorp/nomad/pull/8849)] + * csi: Fixed a bug where multi-writer volumes were allowed only 1 write claim. [[GH-9040](https://github.com/hashicorp/nomad/issues/9040)] * driver/docker: Upgrade pause container and detect architecture [[GH-8957](https://github.com/hashicorp/nomad/pull/8957)] * jobspec: Lowered minimum CPU allowed from 10 to 1. [[GH-8996](https://github.com/hashicorp/nomad/issues/8996)] diff --git a/nomad/structs/csi.go b/nomad/structs/csi.go index 2c2b688853c7..30404344ddf1 100644 --- a/nomad/structs/csi.go +++ b/nomad/structs/csi.go @@ -384,8 +384,13 @@ func (v *CSIVolume) WriteSchedulable() bool { // WriteFreeClaims determines if there are any free write claims available func (v *CSIVolume) WriteFreeClaims() bool { switch v.AccessMode { - case CSIVolumeAccessModeSingleNodeWriter, CSIVolumeAccessModeMultiNodeSingleWriter, CSIVolumeAccessModeMultiNodeMultiWriter: + case CSIVolumeAccessModeSingleNodeWriter, CSIVolumeAccessModeMultiNodeSingleWriter: return len(v.WriteAllocs) == 0 + case CSIVolumeAccessModeMultiNodeMultiWriter: + // the CSI spec doesn't allow for setting a max number of writers. + // we track node resource exhaustion through v.ResourceExhausted + // which is checked in WriteSchedulable + return true default: return false } diff --git a/nomad/structs/csi_test.go b/nomad/structs/csi_test.go index e048ec938a28..d5f63b2413d1 100644 --- a/nomad/structs/csi_test.go +++ b/nomad/structs/csi_test.go @@ -36,6 +36,11 @@ func TestCSIVolumeClaim(t *testing.T) { vol.ClaimRelease(claim) require.True(t, vol.ReadSchedulable()) require.True(t, vol.WriteFreeClaims()) + + vol.AccessMode = CSIVolumeAccessModeMultiNodeMultiWriter + require.NoError(t, vol.ClaimWrite(claim, alloc)) + require.NoError(t, vol.ClaimWrite(claim, alloc)) + require.True(t, vol.WriteFreeClaims()) } func TestCSIPluginJobs(t *testing.T) {