@@ -207,9 +207,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
207
207
208
208
// Take first action
209
209
planAction := plan [0 ]
210
-
211
210
action , actionContext := d .createAction (planAction )
212
- task := d .getTaskFromAction (ctx , planAction )
213
211
214
212
done , abort , recall , retry , err := d .executeAction (ctx , planAction , action )
215
213
if err != nil {
@@ -222,7 +220,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
222
220
223
221
actionsFailedMetrics .WithLabelValues (d .context .GetName (), planAction .Type .String (), pg .Type ()).Inc ()
224
222
225
- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskFailedState )
223
+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskFailedState )
226
224
return nil , false , errors .WithStack (err )
227
225
}
228
226
@@ -233,12 +231,12 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
233
231
234
232
actionsFailedMetrics .WithLabelValues (d .context .GetName (), planAction .Type .String (), pg .Type ()).Inc ()
235
233
236
- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskFailedState )
234
+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskFailedState )
237
235
return nil , true , nil
238
236
}
239
237
240
238
if done {
241
- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskSuccessState )
239
+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskSuccessState )
242
240
243
241
if planAction .IsStarted () {
244
242
// 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
282
280
return nil , false , errors .WithStack (err )
283
281
}
284
282
} else {
285
- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskRunningState )
283
+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskRunningState )
286
284
if ! plan [0 ].IsStarted () {
287
285
// The action has been started in this iteration, but it is not finished yet.
288
286
actionsCurrentPlan .WithLabelValues (d .context .GetName (), planAction .Group .AsRole (), planAction .MemberID ,
@@ -373,27 +371,26 @@ func (d *Reconciler) createAction(action api.Action) (Action, ActionContext) {
373
371
return f (action , actionCtx ), actionCtx
374
372
}
375
373
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 ) {
377
375
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
379
383
}
380
384
381
- tasks , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
385
+ tasksCache , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
382
386
if err != nil {
383
387
d .log .Err (err ).Error ("Failed to get ArangoTask cache" )
384
- return nil
388
+ return
385
389
}
386
390
387
- task , exist := tasks .GetSimpleById (action .TaskID )
391
+ task , exist := tasksCache .GetSimpleById (action .TaskID )
388
392
if ! exist {
389
393
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 {
397
394
return
398
395
}
399
396
@@ -410,7 +407,6 @@ func (d *Reconciler) updateTaskStatus(ctx context.Context, action api.Action, ta
410
407
}
411
408
412
409
cache := d .context .ACS ().CurrentClusterCache ()
413
- var err error
414
410
if task , err = cache .Client ().Arango ().DatabaseV1 ().ArangoTasks (cache .Namespace ()).UpdateStatus (ctx , task , metav1.UpdateOptions {}); err != nil {
415
411
if err != nil {
416
412
d .log .Err (err ).Error ("Failed to update ArangoTask" )
0 commit comments