@@ -473,7 +473,6 @@ type policyChange struct {
473
473
cfg * config.Config
474
474
action fleetapi.Action
475
475
acker acker.Acker
476
- commit bool
477
476
ackWatcher chan struct {}
478
477
}
479
478
@@ -482,9 +481,9 @@ func newPolicyChange(
482
481
config * config.Config ,
483
482
action fleetapi.Action ,
484
483
acker acker.Acker ,
485
- commit bool ) * policyChange {
484
+ makeCh bool ) * policyChange {
486
485
var ackWatcher chan struct {}
487
- if commit {
486
+ if makeCh {
488
487
// we don't need it otherwise
489
488
ackWatcher = make (chan struct {})
490
489
}
@@ -493,7 +492,6 @@ func newPolicyChange(
493
492
cfg : config ,
494
493
action : action ,
495
494
acker : acker ,
496
- commit : true ,
497
495
ackWatcher : ackWatcher ,
498
496
}
499
497
}
@@ -502,30 +500,29 @@ func (l *policyChange) Config() *config.Config {
502
500
return l .cfg
503
501
}
504
502
503
+ // Ack sends an ack for the associated action if the results are expected.
504
+ // An ack will not be sent for a POLICY_CHANGE action, but will be when this method is used by UNENROLL actions.
505
505
func (l * policyChange ) Ack () error {
506
- if l .action == nil {
506
+ if l .action == nil || l . ackWatcher == nil {
507
507
return nil
508
508
}
509
509
err := l .acker .Ack (l .ctx , l .action )
510
510
if err != nil {
511
511
return err
512
512
}
513
- if l .commit {
514
- err := l .acker .Commit (l .ctx )
515
- if l .ackWatcher != nil && err == nil {
516
- close (l .ackWatcher )
517
- }
518
- return err
513
+ err = l .acker .Commit (l .ctx )
514
+ if err == nil {
515
+ close (l .ackWatcher )
519
516
}
520
- return nil
517
+ return err
521
518
}
522
519
523
520
// WaitAck waits for policy change to be acked.
524
521
// Policy change ack is awaitable only in case commit flag was set.
525
522
// Caller is responsible to use any reasonable deadline otherwise
526
523
// function call can be endlessly blocking.
527
524
func (l * policyChange ) WaitAck (ctx context.Context ) {
528
- if ! l . commit || l .ackWatcher == nil {
525
+ if l .ackWatcher == nil {
529
526
return
530
527
}
531
528
0 commit comments