Skip to content

Commit 8755c3e

Browse files
mutex changes in processInstanceViewFlexible and scaleIn
1 parent 71c6c00 commit 8755c3e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

plugins/builtin/target/azure-vmss/plugin/azure.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,13 @@ func (t *TargetPlugin) scaleIn(ctx context.Context, resourceGroup string, vmScal
198198
if err := t.clusterUtils.RunPostScaleInTasks(ctx, config, ids); err != nil {
199199
return fmt.Errorf("failed to perform post-scale Nomad scale in tasks: %w", err)
200200
}
201-
t.readyFlexibleInstances = []string{}
201+
202+
if vmssMode == orchestrationModeFlexible {
203+
// Clear ready flexible instances after scale in.
204+
t.readyFlexibleInstancesLock.Lock()
205+
defer t.readyFlexibleInstancesLock.Unlock()
206+
t.readyFlexibleInstances = []string{}
207+
}
202208

203209
return nil
204210
}

plugins/builtin/target/azure-vmss/plugin/plugin.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ type TargetPlugin struct {
6868

6969
// readyInstances is a list of instances that are ready for scale in actions.
7070
// used with the flexible orchestration mode to prevent the need for multiple calls to the Azure API to check.
71-
readyFlexibleInstances []string
71+
readyFlexibleInstances []string
72+
readyFlexibleInstancesLock sync.Mutex
7273
}
7374

7475
// NewAzureVMSSPlugin returns the Azure VMSS implementation of the target.Target
@@ -278,9 +279,6 @@ func processInstanceView(instanceView *armcompute.VirtualMachineScaleSetsClientG
278279
}
279280

280281
func (t *TargetPlugin) processInstanceViewFlexible(vms []string, resourceGroup string, status *sdk.TargetStatus) {
281-
readyInstances := []string{}
282-
var mu sync.Mutex
283-
284282
t.logger.Debug("Processing VM instance views for Flexible VMSS", "vm_count", len(vms))
285283
t.readyFlexibleInstances = []string{}
286284

@@ -332,13 +330,12 @@ func (t *TargetPlugin) processInstanceViewFlexible(vms []string, resourceGroup s
332330
}
333331
return
334332
}
335-
mu.Lock()
336-
readyInstances = append(readyInstances, vm)
337-
mu.Unlock()
333+
t.readyFlexibleInstancesLock.Lock()
334+
defer t.readyFlexibleInstancesLock.Unlock()
335+
t.readyFlexibleInstances = append(t.readyFlexibleInstances, vm)
338336
}(vmName)
339337
}
340338
wg.Wait()
341339

342340
status.Ready = !notReady.Load()
343-
t.readyFlexibleInstances = readyInstances
344341
}

0 commit comments

Comments
 (0)