Skip to content

Commit 7836176

Browse files
committed
controller: create/delete vms with 2 seconds interval
1 parent f20e4bd commit 7836176

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

Development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Kubernetes-style declarative orchestration tool for Apache CloudStack
88
go build -o cloudstackctl main.go
99

1010
# Build binary for Controller (if run locally)
11-
go build -o cloudstackctl-controller cmd/controller
11+
go build -o cloudstackctl-controller cmd/controller/main.go
1212

1313
# Install to PATH
1414
sudo mv cloudstackctl /usr/local/bin/

controller/controller.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,17 @@ func (c *Controller) stopAppWorker(appName string) {
127127
vmsByComp[comp] = append(vmsByComp[comp], vm)
128128
}
129129

130-
// Process components in deterministic order, deleting each component's VMs in parallel
130+
// Process components in deterministic order, deleting each component's VMs in parallel.
131+
// Launches are staggered 2 seconds apart to avoid concurrent CloudStack
132+
// API contention; goroutines themselves run concurrently after their delay.
131133
for _, comp := range compOrder {
132134
vms := vmsByComp[comp]
133135
log.Printf("stopAppWorker: removing %d VMs for component '%s'", len(vms), comp)
134136
var wg sync.WaitGroup
135-
for _, vm := range vms {
137+
for i, vm := range vms {
138+
if i > 0 {
139+
time.Sleep(2 * time.Second)
140+
}
136141
wg.Add(1)
137142
vmCopy := vm
138143
go func(v v1.VirtualMachine) {

controller/reconcile.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,23 @@ func (c *Controller) createComponentVMs(appName string, comp *v1.Component, comp
431431
vms = append(vms, vm)
432432
}
433433

434-
// Create VMs in parallel (limit concurrency with a semaphore)
434+
// Create VMs in parallel (limit concurrency with a semaphore).
435+
// Launches are staggered 2 seconds apart to avoid concurrent CloudStack
436+
// API contention; goroutines themselves run concurrently after their delay.
435437
var wg sync.WaitGroup
436438
errCh := make(chan error, len(vms))
437439
sem := make(chan struct{}, 5) // max 5 concurrent creations
438440

441+
launchIdx := 0
439442
for _, vm := range vms {
440443
// if VM already has CloudStackID, skip
441444
if vm.CloudStackID != "" {
442445
continue
443446
}
447+
if launchIdx > 0 {
448+
time.Sleep(2 * time.Second)
449+
}
450+
launchIdx++
444451
wg.Add(1)
445452
sem <- struct{}{}
446453
go func(vmName string) {

0 commit comments

Comments
 (0)