Skip to content

Commit 8a45ae8

Browse files
committed
Not moving alloc data when sticky is turned off
1 parent 3e63908 commit 8a45ae8

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

client/client.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -1069,17 +1069,23 @@ func (c *Client) updateNodeStatus() error {
10691069

10701070
// updateAllocStatus is used to update the status of an allocation
10711071
func (c *Client) updateAllocStatus(alloc *structs.Allocation) {
1072-
// Only send the fields that are updatable by the client.
1072+
select {
1073+
case c.allocUpdates <- alloc:
1074+
case <-c.shutdownCh:
1075+
}
1076+
}
1077+
1078+
// stripAllocation strips the allocation of fields which can be re-assembled in
1079+
// the server.
1080+
func (c *Client) stripAllocation(alloc *structs.Allocation) *structs.Allocation {
10731081
stripped := new(structs.Allocation)
10741082
stripped.ID = alloc.ID
10751083
stripped.NodeID = c.Node().ID
10761084
stripped.TaskStates = alloc.TaskStates
10771085
stripped.ClientStatus = alloc.ClientStatus
10781086
stripped.ClientDescription = alloc.ClientDescription
1079-
select {
1080-
case c.allocUpdates <- stripped:
1081-
case <-c.shutdownCh:
1082-
}
1087+
1088+
return stripped
10831089
}
10841090

10851091
// allocSync is a long lived function that batches allocation updates to the
@@ -1103,7 +1109,10 @@ func (c *Client) allocSync() {
11031109
if blockedAlloc, ok := c.blockedAllocations[alloc.ID]; ok && alloc.Terminated() {
11041110
var prevAllocDir *allocdir.AllocDir
11051111
if ar, ok := c.getAllocRunners()[alloc.ID]; ok {
1106-
prevAllocDir = ar.GetAllocDir()
1112+
tg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)
1113+
if tg != nil && tg.EphemeralDisk.Sticky {
1114+
prevAllocDir = ar.GetAllocDir()
1115+
}
11071116
}
11081117
if err := c.addAlloc(blockedAlloc, prevAllocDir); err != nil {
11091118
c.logger.Printf("[ERR] client: failed to add alloc which was previously blocked %q: %v",
@@ -1120,7 +1129,9 @@ func (c *Client) allocSync() {
11201129

11211130
sync := make([]*structs.Allocation, 0, len(updates))
11221131
for _, alloc := range updates {
1123-
sync = append(sync, alloc)
1132+
// Only send the fields that are updatable by the client.
1133+
stripped := c.stripAllocation(alloc)
1134+
sync = append(sync, stripped)
11241135
}
11251136

11261137
// Send to server.
@@ -1393,7 +1404,7 @@ func (c *Client) runAllocs(update *allocUpdates) {
13931404
// previous allocation
13941405
var prevAllocDir *allocdir.AllocDir
13951406
tg := add.Job.LookupTaskGroup(add.TaskGroup)
1396-
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky == true && ar != nil {
1407+
if tg != nil && tg.EphemeralDisk != nil && tg.EphemeralDisk.Sticky && ar != nil {
13971408
prevAllocDir = ar.GetAllocDir()
13981409
}
13991410

0 commit comments

Comments
 (0)