Skip to content

Commit 9535385

Browse files
Remove policy change action acks
1 parent f3c044b commit 9535385

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

internal/pkg/agent/application/actions/handlers/handler_action_policy_change.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
505505
func (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.
527524
func (l *policyChange) WaitAck(ctx context.Context) {
528-
if !l.commit || l.ackWatcher == nil {
525+
if l.ackWatcher == nil {
529526
return
530527
}
531528

internal/pkg/agent/application/actions/handlers/handler_action_policy_change_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestPolicyAcked(t *testing.T) {
105105
agentInfo := &info.AgentInfo{}
106106
nullStore := &storage.NullStore{}
107107

108-
t.Run("Config change should ACK", func(t *testing.T) {
108+
t.Run("Config change shouldn't ACK", func(t *testing.T) {
109109
ch := make(chan coordinator.ConfigChange, 1)
110110
tacker := &testAcker{}
111111

@@ -129,8 +129,7 @@ func TestPolicyAcked(t *testing.T) {
129129
require.NoError(t, change.Ack())
130130

131131
actions := tacker.Items()
132-
assert.EqualValues(t, 1, len(actions))
133-
assert.Equal(t, actionID, actions[0])
132+
assert.Empty(t, actions)
134133
})
135134
}
136135

0 commit comments

Comments
 (0)