@@ -207,9 +207,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
207207
208208 // Take first action
209209 planAction := plan [0 ]
210-
211210 action , actionContext := d .createAction (planAction )
212- task := d .getTaskFromAction (ctx , planAction )
213211
214212 done , abort , recall , retry , err := d .executeAction (ctx , planAction , action )
215213 if err != nil {
@@ -222,7 +220,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
222220
223221 actionsFailedMetrics .WithLabelValues (d .context .GetName (), planAction .Type .String (), pg .Type ()).Inc ()
224222
225- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskFailedState )
223+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskFailedState )
226224 return nil , false , errors .WithStack (err )
227225 }
228226
@@ -233,12 +231,12 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
233231
234232 actionsFailedMetrics .WithLabelValues (d .context .GetName (), planAction .Type .String (), pg .Type ()).Inc ()
235233
236- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskFailedState )
234+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskFailedState )
237235 return nil , true , nil
238236 }
239237
240238 if done {
241- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskSuccessState )
239+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskSuccessState )
242240
243241 if planAction .IsStarted () {
244242 // The below metrics was increased in the previous iteration, so it should be decreased now.
@@ -283,7 +281,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
283281 return nil , false , errors .WithStack (err )
284282 }
285283 } else {
286- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskRunningState )
284+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskRunningState )
287285 if ! plan [0 ].IsStarted () {
288286 // The action has been started in this iteration, but it is not finished yet.
289287 actionsCurrentPlan .WithLabelValues (d .context .GetName (), planAction .Group .AsRole (), planAction .MemberID ,
@@ -364,27 +362,26 @@ func (d *Reconciler) createAction(action api.Action) (Action, ActionContext) {
364362 return f (action , actionCtx ), actionCtx
365363}
366364
367- func (d * Reconciler ) getTaskFromAction (ctx context.Context , action api.Action ) * api.ArangoTask {
365+ func (d * Reconciler ) updateTaskStatus (ctx context.Context , action api.Action , state api.ArangoTaskState ) {
368366 if action .TaskID == "" {
369- return nil
367+ return
368+ }
369+
370+ err := d .context .ACS ().Cache ().ArangoTask ().Refresh (ctx )
371+ if err != nil {
372+ d .log .Err (err ).Error ("Failed to refresh ArangoTask" )
373+ return
370374 }
371375
372- tasks , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
376+ tasksCache , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
373377 if err != nil {
374378 d .log .Err (err ).Error ("Failed to get ArangoTask cache" )
375- return nil
379+ return
376380 }
377381
378- task , exist := tasks .GetSimpleById (action .TaskID )
382+ task , exist := tasksCache .GetSimpleById (action .TaskID )
379383 if ! exist {
380384 d .log .Error ("ArangoTask not found" )
381- return nil
382- }
383- return task
384- }
385-
386- func (d * Reconciler ) updateTaskStatus (ctx context.Context , action api.Action , task * api.ArangoTask , state api.ArangoTaskState ) {
387- if task == nil {
388385 return
389386 }
390387
@@ -401,7 +398,6 @@ func (d *Reconciler) updateTaskStatus(ctx context.Context, action api.Action, ta
401398 }
402399
403400 cache := d .context .ACS ().CurrentClusterCache ()
404- var err error
405401 if task , err = cache .Client ().Arango ().DatabaseV1 ().ArangoTasks (cache .Namespace ()).UpdateStatus (ctx , task , metav1.UpdateOptions {}); err != nil {
406402 if err != nil {
407403 d .log .Err (err ).Error ("Failed to update ArangoTask" )
0 commit comments