@@ -473,7 +473,6 @@ type policyChange struct {
473473 cfg * config.Config
474474 action fleetapi.Action
475475 acker acker.Acker
476- commit bool
477476 ackWatcher chan struct {}
478477}
479478
@@ -482,9 +481,9 @@ func newPolicyChange(
482481 config * config.Config ,
483482 action fleetapi.Action ,
484483 acker acker.Acker ,
485- commit bool ) * policyChange {
484+ makeCh bool ) * policyChange {
486485 var ackWatcher chan struct {}
487- if commit {
486+ if makeCh {
488487 // we don't need it otherwise
489488 ackWatcher = make (chan struct {})
490489 }
@@ -493,7 +492,6 @@ func newPolicyChange(
493492 cfg : config ,
494493 action : action ,
495494 acker : acker ,
496- commit : true ,
497495 ackWatcher : ackWatcher ,
498496 }
499497}
@@ -502,30 +500,29 @@ func (l *policyChange) Config() *config.Config {
502500 return l .cfg
503501}
504502
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.
505505func (l * policyChange ) Ack () error {
506- if l .action == nil {
506+ if l .action == nil || l . ackWatcher == nil {
507507 return nil
508508 }
509509 err := l .acker .Ack (l .ctx , l .action )
510510 if err != nil {
511511 return err
512512 }
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 )
519516 }
520- return nil
517+ return err
521518}
522519
523520// WaitAck waits for policy change to be acked.
524521// Policy change ack is awaitable only in case commit flag was set.
525522// Caller is responsible to use any reasonable deadline otherwise
526523// function call can be endlessly blocking.
527524func (l * policyChange ) WaitAck (ctx context.Context ) {
528- if ! l . commit || l .ackWatcher == nil {
525+ if l .ackWatcher == nil {
529526 return
530527 }
531528
0 commit comments