Skip to content

Commit 0721e6f

Browse files
Remove policy change action acks
1 parent f3c044b commit 0721e6f

File tree

5 files changed

+12
-51
lines changed

5 files changed

+12
-51
lines changed

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

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (h *PolicyChangeHandler) Handle(ctx context.Context, a fleetapi.Action, ack
111111
return err
112112
}
113113

114-
h.ch <- newPolicyChange(ctx, c, a, acker, false)
114+
h.ch <- newPolicyChange(c, false)
115115
return nil
116116
}
117117

@@ -469,31 +469,20 @@ func fleetToReader(agentID string, headers map[string]string, cfg *configuration
469469
}
470470

471471
type policyChange struct {
472-
ctx context.Context
473472
cfg *config.Config
474-
action fleetapi.Action
475-
acker acker.Acker
476-
commit bool
477473
ackWatcher chan struct{}
478474
}
479475

480476
func newPolicyChange(
481-
ctx context.Context,
482477
config *config.Config,
483-
action fleetapi.Action,
484-
acker acker.Acker,
485-
commit bool) *policyChange {
478+
createCh bool) *policyChange {
486479
var ackWatcher chan struct{}
487-
if commit {
480+
if createCh {
488481
// we don't need it otherwise
489482
ackWatcher = make(chan struct{})
490483
}
491484
return &policyChange{
492-
ctx: ctx,
493485
cfg: config,
494-
action: action,
495-
acker: acker,
496-
commit: true,
497486
ackWatcher: ackWatcher,
498487
}
499488
}
@@ -502,30 +491,19 @@ func (l *policyChange) Config() *config.Config {
502491
return l.cfg
503492
}
504493

494+
// Ack will close the channel that WaitAck uses but is otherwise a nop.
505495
func (l *policyChange) Ack() error {
506-
if l.action == nil {
507-
return nil
508-
}
509-
err := l.acker.Ack(l.ctx, l.action)
510-
if err != nil {
511-
return err
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
496+
if l.ackWatcher != nil {
497+
close(l.ackWatcher)
519498
}
520499
return nil
521500
}
522501

523502
// WaitAck waits for policy change to be acked.
524-
// Policy change ack is awaitable only in case commit flag was set.
525503
// Caller is responsible to use any reasonable deadline otherwise
526504
// function call can be endlessly blocking.
527505
func (l *policyChange) WaitAck(ctx context.Context) {
528-
if !l.commit || l.ackWatcher == nil {
506+
if l.ackWatcher == nil {
529507
return
530508
}
531509

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *Unenroll) handle(ctx context.Context, a fleetapi.Action, acker acker.Ac
9393
}
9494

9595
// Generate empty policy change, this removing all the running components
96-
unenrollPolicy := newPolicyChange(ctx, config.New(), a, acker, true)
96+
unenrollPolicy := newPolicyChange(config.New(), true)
9797
h.ch <- unenrollPolicy
9898

9999
// backup action for future start to avoid starting fleet gateway loop

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func TestActionUnenrollHandler(t *testing.T) {
226226

227227
// autoUnenroll isn't acked
228228
if tc.wantErr == nil && !tc.autoUnenroll {
229-
require.Len(t, acker.Acked, 1)
229+
require.Empty(t, acker.Acked)
230230
}
231231
require.Equal(t, tc.wantPerformedActions, coord.performedActions.Load())
232232
})

internal/pkg/agent/application/coordinator/coordinator.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,23 +1463,7 @@ func (c *Coordinator) runLoopIteration(ctx context.Context) {
14631463
c.logger.Errorf("applying new policy: %s", err.Error())
14641464
change.Fail(err)
14651465
} else {
1466-
if err := change.Ack(); err != nil {
1467-
err = fmt.Errorf("failed to ack configuration change: %w", err)
1468-
// Workaround: setConfigManagerError is usually used by the config
1469-
// manager to report failed ACKs / etc when communicating with Fleet.
1470-
// We need to report a failed ACK here, but the policy change has
1471-
// already been successfully applied so we don't want to report it as
1472-
// a general Coordinator or policy failure.
1473-
// This arises uniquely here because this is the only case where an
1474-
// action is responsible for reporting the failure of its own ACK
1475-
// call. The "correct" fix is to make this Ack() call unfailable
1476-
// and handle ACK retries and reporting in the config manager like
1477-
// with other action types -- this error would then end up invoking
1478-
// setConfigManagerError "organically" via the config manager's
1479-
// reporting channel. In the meantime, we do it manually.
1480-
c.setConfigManagerError(err)
1481-
c.logger.Errorf("%s", err.Error())
1482-
}
1466+
_ = change.Ack() // will not return errors
14831467
}
14841468

14851469
case vars := <-c.managerChans.varsManagerUpdate:

0 commit comments

Comments
 (0)