@@ -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.
@@ -282,7 +280,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
282280 return nil , false , errors .WithStack (err )
283281 }
284282 } else {
285- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskRunningState )
283+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskRunningState )
286284 if ! plan [0 ].IsStarted () {
287285 // The action has been started in this iteration, but it is not finished yet.
288286 actionsCurrentPlan .WithLabelValues (d .context .GetName (), planAction .Group .AsRole (), planAction .MemberID ,
@@ -373,27 +371,26 @@ func (d *Reconciler) createAction(action api.Action) (Action, ActionContext) {
373371 return f (action , actionCtx ), actionCtx
374372}
375373
376- func (d * Reconciler ) getTaskFromAction (ctx context.Context , action api.Action ) * api.ArangoTask {
374+ func (d * Reconciler ) updateTaskStatus (ctx context.Context , action api.Action , state api.ArangoTaskState ) {
377375 if action .TaskID == "" {
378- return nil
376+ return
377+ }
378+
379+ err := d .context .ACS ().Cache ().ArangoTask ().Refresh (ctx )
380+ if err != nil {
381+ d .log .Err (err ).Error ("Failed to refresh ArangoTask" )
382+ return
379383 }
380384
381- tasks , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
385+ tasksCache , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
382386 if err != nil {
383387 d .log .Err (err ).Error ("Failed to get ArangoTask cache" )
384- return nil
388+ return
385389 }
386390
387- task , exist := tasks .GetSimpleById (action .TaskID )
391+ task , exist := tasksCache .GetSimpleById (action .TaskID )
388392 if ! exist {
389393 d .log .Error ("ArangoTask not found" )
390- return nil
391- }
392- return task
393- }
394-
395- func (d * Reconciler ) updateTaskStatus (ctx context.Context , action api.Action , task * api.ArangoTask , state api.ArangoTaskState ) {
396- if task == nil {
397394 return
398395 }
399396
@@ -410,7 +407,6 @@ func (d *Reconciler) updateTaskStatus(ctx context.Context, action api.Action, ta
410407 }
411408
412409 cache := d .context .ACS ().CurrentClusterCache ()
413- var err error
414410 if task , err = cache .Client ().Arango ().DatabaseV1 ().ArangoTasks (cache .Namespace ()).UpdateStatus (ctx , task , metav1.UpdateOptions {}); err != nil {
415411 if err != nil {
416412 d .log .Err (err ).Error ("Failed to update ArangoTask" )
0 commit comments