Skip to content

Commit 0acb4e9

Browse files
authored
refactor: enable 'revive.use-waitgroup-go' rule (#7284)
1 parent 6b1f938 commit 0acb4e9

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

‎.golangci.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ linters:
7171
- name: var-naming
7272
- name: redundant-import-alias
7373
- name: use-any
74+
- name: use-waitgroup-go
7475
forbidigo:
7576
forbid:
7677
- pattern: ^sort\.Slice$

‎pkg/controller/admissionchecks/multikueue/fswatch_test.go‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ func TestFSWatch(t *testing.T) {
156156
// start the recorder
157157
gotEventsForClusters := set.New[string]()
158158
wg := sync.WaitGroup{}
159-
wg.Add(1)
160-
go func() {
161-
defer wg.Done()
159+
wg.Go(func() {
162160
for {
163161
select {
164162
case ev := <-watcher.reconcile:
@@ -170,7 +168,7 @@ func TestFSWatch(t *testing.T) {
170168
return
171169
}
172170
}
173-
}()
171+
})
174172
_ = watcher.Start(ctx)
175173

176174
gotAddErrors := map[string]error{}

‎test/performance/scheduler/runner/main.go‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
292292
}
293293
startTime := time.Now()
294294

295-
wg.Add(1)
296-
go func() {
297-
defer wg.Done()
295+
wg.Go(func() {
298296
err := cmd.Wait()
299297
if err != nil {
300298
select {
@@ -325,7 +323,7 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
325323
if err != nil {
326324
log.Error(err, "Writing cmd stats")
327325
}
328-
}()
326+
})
329327
return nil
330328
}
331329

@@ -346,9 +344,7 @@ func runGenerator(ctx context.Context, cfg *rest.Config, generatorConfig string,
346344
}
347345

348346
statTime := time.Now()
349-
wg.Add(1)
350-
go func() {
351-
defer wg.Done()
347+
wg.Go(func() {
352348
defer close(genDone)
353349
err := generator.Generate(ctx, c, cohorts)
354350
if err != nil {
@@ -357,7 +353,7 @@ func runGenerator(ctx context.Context, cfg *rest.Config, generatorConfig string,
357353
return
358354
}
359355
log.Info("Generator done", "duration", time.Since(statTime))
360-
}()
356+
})
361357

362358
log.Info("Generator started", "qps", cfg.QPS, "burst", cfg.Burst)
363359
return nil
@@ -366,17 +362,15 @@ func runGenerator(ctx context.Context, cfg *rest.Config, generatorConfig string,
366362
func startRecorder(ctx context.Context, errCh chan<- error, wg *sync.WaitGroup, genDone <-chan struct{}, recordTimeout time.Duration) (*recorder.Recorder, error) {
367363
log := ctrl.LoggerFrom(ctx).WithName("Start recorder")
368364
recorder := recorder.New(recordTimeout)
369-
wg.Add(1)
370-
go func() {
371-
defer wg.Done()
365+
wg.Go(func() {
372366
err := recorder.Run(ctx, genDone)
373367
if err != nil {
374368
log.Error(err, "Recorder run")
375369
} else {
376370
log.Info("Recorder done")
377371
}
378372
errCh <- err
379-
}()
373+
})
380374

381375
log.Info("Recorder started", "timeout", recordTimeout)
382376
return recorder, nil
@@ -408,17 +402,15 @@ func runManager(ctx context.Context, cfg *rest.Config, errCh chan<- error, wg *s
408402
return err
409403
}
410404

411-
wg.Add(1)
412-
go func() {
413-
defer wg.Done()
405+
wg.Go(func() {
414406
log.Info("Starting manager")
415407
if err := mgr.Start(ctx); err != nil {
416408
log.Error(err, "Could not run manager")
417409
errCh <- err
418410
} else {
419411
log.Info("End manager")
420412
}
421-
}()
413+
})
422414

423415
log.Info("Manager started")
424416
return nil
@@ -429,17 +421,15 @@ func runScraper(ctx context.Context, interval time.Duration, output, url string,
429421

430422
s := scraper.NewScraper(interval, url, "%d.prometheus")
431423

432-
wg.Add(1)
433-
go func() {
434-
defer wg.Done()
424+
wg.Go(func() {
435425
err := s.Run(ctx, output)
436426
if err != nil {
437427
log.Error(err, "Running the scraper")
438428
errCh <- err
439429
return
440430
}
441431
log.Info("Scrape done")
442-
}()
432+
})
443433

444434
log.Info("Scrape started")
445435
return nil

0 commit comments

Comments
 (0)