@@ -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.
@@ -283,7 +281,7 @@ func (d *Reconciler) executePlan(ctx context.Context, statusPlan api.Plan, pg pl
283
281
return nil , false , errors .WithStack (err )
284
282
}
285
283
} else {
286
- d .updateTaskStatus (ctx , planAction , task , api .ArangoTaskRunningState )
284
+ d .updateTaskStatus (ctx , planAction , api .ArangoTaskRunningState )
287
285
if ! plan [0 ].IsStarted () {
288
286
// The action has been started in this iteration, but it is not finished yet.
289
287
actionsCurrentPlan .WithLabelValues (d .context .GetName (), planAction .Group .AsRole (), planAction .MemberID ,
@@ -364,27 +362,26 @@ func (d *Reconciler) createAction(action api.Action) (Action, ActionContext) {
364
362
return f (action , actionCtx ), actionCtx
365
363
}
366
364
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 ) {
368
366
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
370
374
}
371
375
372
- tasks , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
376
+ tasksCache , err := d .context .ACS ().Cache ().ArangoTask ().V1 ()
373
377
if err != nil {
374
378
d .log .Err (err ).Error ("Failed to get ArangoTask cache" )
375
- return nil
379
+ return
376
380
}
377
381
378
- task , exist := tasks .GetSimpleById (action .TaskID )
382
+ task , exist := tasksCache .GetSimpleById (action .TaskID )
379
383
if ! exist {
380
384
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 {
388
385
return
389
386
}
390
387
@@ -401,7 +398,6 @@ func (d *Reconciler) updateTaskStatus(ctx context.Context, action api.Action, ta
401
398
}
402
399
403
400
cache := d .context .ACS ().CurrentClusterCache ()
404
- var err error
405
401
if task , err = cache .Client ().Arango ().DatabaseV1 ().ArangoTasks (cache .Namespace ()).UpdateStatus (ctx , task , metav1.UpdateOptions {}); err != nil {
406
402
if err != nil {
407
403
d .log .Err (err ).Error ("Failed to update ArangoTask" )
0 commit comments