@@ -22,7 +22,7 @@ import (
22
22
type Upgrade struct {
23
23
log * logger.Logger
24
24
coord upgradeCoordinator
25
- bkgActions []fleetapi.Action
25
+ bkgActions []* fleetapi.ActionUpgrade
26
26
bkgCancel context.CancelFunc
27
27
bkgMutex sync.Mutex
28
28
@@ -50,7 +50,7 @@ func (h *Upgrade) Handle(ctx context.Context, a fleetapi.Action, ack acker.Acker
50
50
return fmt .Errorf ("invalid type, expected ActionUpgrade and received %T" , a )
51
51
}
52
52
53
- asyncCtx , runAsync := h .getAsyncContext (ctx , a , ack )
53
+ asyncCtx , runAsync := h .getAsyncContext (ctx , action , ack )
54
54
if ! runAsync {
55
55
return nil
56
56
}
@@ -115,28 +115,19 @@ func (h *Upgrade) ackAction(ctx context.Context, ack acker.Acker, action fleetap
115
115
}
116
116
117
117
// getAsyncContext returns a cancelContext and whether or not to run the upgrade
118
- func (h * Upgrade ) getAsyncContext (ctx context.Context , action fleetapi.Action , ack acker.Acker ) (context.Context , bool ) {
118
+ func (h * Upgrade ) getAsyncContext (ctx context.Context , upgradeAction * fleetapi.ActionUpgrade , ack acker.Acker ) (context.Context , bool ) {
119
119
h .bkgMutex .Lock ()
120
120
defer h .bkgMutex .Unlock ()
121
121
// If no existing actions, run this one
122
122
if len (h .bkgActions ) == 0 {
123
- h .bkgActions = append (h .bkgActions , action )
123
+ h .bkgActions = append (h .bkgActions , upgradeAction )
124
124
c , cancel := context .WithCancel (ctx )
125
125
h .bkgCancel = cancel
126
126
return c , true
127
127
}
128
128
// If upgrade to same version, save action to ack when first upgrade completes
129
- upgradeAction , ok := action .(* fleetapi.ActionUpgrade )
130
- if ! ok {
131
- h .log .Errorf ("invalid type, expected ActionUpgrade and received %T" , action )
132
- return nil , false
133
- }
134
129
// only need to check first action since all actions must be upgrades to same version
135
- bkgAction , ok := h .bkgActions [0 ].(* fleetapi.ActionUpgrade )
136
- if ! ok {
137
- h .log .Errorf ("invalid type, expected ActionUpgrade and received %T" , action )
138
- return nil , false
139
- }
130
+ bkgAction := h .bkgActions [0 ]
140
131
if upgradeAction .ActionID == bkgAction .ActionID {
141
132
h .log .Infof ("Duplicate upgrade to version %s received" ,
142
133
bkgAction .Data .Version )
@@ -164,7 +155,7 @@ func (h *Upgrade) getAsyncContext(ctx context.Context, action fleetapi.Action, a
164
155
// Ack here because we have the lock, and we need to clear out the saved actions
165
156
h .ackActions (ctx , ack )
166
157
167
- h .bkgActions = append (h .bkgActions , action )
158
+ h .bkgActions = append (h .bkgActions , upgradeAction )
168
159
c , cancel := context .WithCancel (ctx )
169
160
h .bkgCancel = cancel
170
161
return c , true
0 commit comments