@@ -22,7 +22,7 @@ import (
2222type Upgrade struct {
2323 log * logger.Logger
2424 coord upgradeCoordinator
25- bkgActions []fleetapi.Action
25+ bkgActions []* fleetapi.ActionUpgrade
2626 bkgCancel context.CancelFunc
2727 bkgMutex sync.Mutex
2828
@@ -50,7 +50,7 @@ func (h *Upgrade) Handle(ctx context.Context, a fleetapi.Action, ack acker.Acker
5050 return fmt .Errorf ("invalid type, expected ActionUpgrade and received %T" , a )
5151 }
5252
53- asyncCtx , runAsync := h .getAsyncContext (ctx , a , ack )
53+ asyncCtx , runAsync := h .getAsyncContext (ctx , action , ack )
5454 if ! runAsync {
5555 return nil
5656 }
@@ -115,28 +115,19 @@ func (h *Upgrade) ackAction(ctx context.Context, ack acker.Acker, action fleetap
115115}
116116
117117// 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 ) {
119119 h .bkgMutex .Lock ()
120120 defer h .bkgMutex .Unlock ()
121121 // If no existing actions, run this one
122122 if len (h .bkgActions ) == 0 {
123- h .bkgActions = append (h .bkgActions , action )
123+ h .bkgActions = append (h .bkgActions , upgradeAction )
124124 c , cancel := context .WithCancel (ctx )
125125 h .bkgCancel = cancel
126126 return c , true
127127 }
128128 // 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- }
134129 // 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 ]
140131 if upgradeAction .ActionID == bkgAction .ActionID {
141132 h .log .Infof ("Duplicate upgrade to version %s received" ,
142133 bkgAction .Data .Version )
@@ -164,7 +155,7 @@ func (h *Upgrade) getAsyncContext(ctx context.Context, action fleetapi.Action, a
164155 // Ack here because we have the lock, and we need to clear out the saved actions
165156 h .ackActions (ctx , ack )
166157
167- h .bkgActions = append (h .bkgActions , action )
158+ h .bkgActions = append (h .bkgActions , upgradeAction )
168159 c , cancel := context .WithCancel (ctx )
169160 h .bkgCancel = cancel
170161 return c , true
0 commit comments