diff --git a/.changelog/11852.txt b/.changelog/11852.txt new file mode 100644 index 000000000..fb37815aa --- /dev/null +++ b/.changelog/11852.txt @@ -0,0 +1,3 @@ +```release-note:bug +csi: Fixed a bug where deregistering volumes would attempt to deregister the wrong volume if the ID was a prefix of the intended volume +``` diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 93a7f27d6..484091b38 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -2375,7 +2375,7 @@ func (s *StateStore) CSIVolumeDeregister(index uint64, namespace string, ids []s defer txn.Abort() for _, id := range ids { - existing, err := txn.First("csi_volumes", "id_prefix", namespace, id) + existing, err := txn.First("csi_volumes", "id", namespace, id) if err != nil { return fmt.Errorf("volume lookup failed: %s: %v", id, err) } diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 4942574a8..7195c17f9 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -2995,16 +2995,21 @@ func TestStateStore_CSIVolume(t *testing.T) { // registration is an error when the volume is in use index++ err = state.CSIVolumeRegister(index, []*structs.CSIVolume{v0}) - require.Error(t, err, fmt.Sprintf("volume exists: %s", vol0)) + require.Error(t, err, "volume re-registered while in use") // as is deregistration index++ err = state.CSIVolumeDeregister(index, ns, []string{vol0}, false) - require.Error(t, err, fmt.Sprintf("volume in use: %s", vol0)) + require.Error(t, err, "volume deregistered while in use") // even if forced, because we have a non-terminal claim index++ err = state.CSIVolumeDeregister(index, ns, []string{vol0}, true) - require.Error(t, err, fmt.Sprintf("volume in use: %s", vol0)) + require.Error(t, err, "volume force deregistered while in use") + + // we use the ID, not a prefix + index++ + err = state.CSIVolumeDeregister(index, ns, []string{"fo"}, true) + require.Error(t, err, "volume deregistered by prefix") // release claims to unblock deregister index++