Skip to content

Commit 01a9728

Browse files
Backport of host volumes: require allocs to be client terminal to delete vols into release/1.10.x (#26214)
Co-authored-by: Tim Gross <[email protected]>
1 parent 74dcbc3 commit 01a9728

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.changelog/26213.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
host volumes: Fixed a bug where volumes with server-terminal allocations could be deleted from clients but not the state store
3+
```

nomad/state/state_store_host_volumes.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ func (s *StateStore) deleteHostVolumeTxn(txn *txn, index uint64, ns string, id s
143143
if obj != nil {
144144
vol := obj.(*structs.HostVolume)
145145

146-
allocs, err := s.AllocsByNodeTerminal(nil, vol.NodeID, false)
146+
// we can't use AllocsByNodeTerminal because we only want to filter out
147+
// allocs that are client-terminal, not server-terminal
148+
allocs, err := s.AllocsByNode(nil, vol.NodeID)
147149
if err != nil {
148150
return fmt.Errorf("could not query allocs to check for host volume claims: %w", err)
149151
}
150152
for _, alloc := range allocs {
153+
if alloc.ClientTerminalStatus() {
154+
continue
155+
}
151156
for _, volClaim := range alloc.Job.LookupTaskGroup(alloc.TaskGroup).Volumes {
152157
if volClaim.Type == structs.VolumeTypeHost && volClaim.Name == vol.Name {
153158
return fmt.Errorf("could not delete volume %s in use by alloc %s",

nomad/state/state_store_host_volumes_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ func TestStateStore_HostVolumes_CRUD(t *testing.T) {
149149
must.EqError(t, err, fmt.Sprintf(
150150
"could not delete volume %s in use by alloc %s", vols[2].ID, alloc.ID))
151151

152+
alloc = alloc.Copy()
153+
alloc.DesiredStatus = structs.AllocDesiredStatusStop
154+
index++
155+
must.NoError(t, store.UpdateAllocsFromClient(structs.MsgTypeTestSetup,
156+
index, []*structs.Allocation{alloc}))
157+
158+
index++
159+
err = store.DeleteHostVolume(index, vol2.Namespace, vols[2].ID)
160+
must.EqError(t, err, fmt.Sprintf(
161+
"could not delete volume %s in use by alloc %s", vols[2].ID, alloc.ID),
162+
must.Sprint("allocs must be client-terminal to delete their volumes"))
163+
152164
err = store.DeleteHostVolume(index, vol2.Namespace, vols[1].ID)
153165
must.NoError(t, err)
154166
vol, err = store.HostVolumeByID(nil, vols[1].Namespace, vols[1].ID, true)

0 commit comments

Comments
 (0)