Skip to content

Commit b9fc321

Browse files
committed
extend ping action flow
1 parent dc968d6 commit b9fc321

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

pkg/apis/deployment/v1/arango_task_spec.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ var _ json.Unmarshaler = &ArangoTaskDetails{}
7373
var _ json.Marshaler = ArangoTaskDetails{}
7474

7575
type ArangoTaskSpec struct {
76-
Type ArangoTaskType `json:"type,required"`
77-
DeploymentName string `json:"deploymentName,required"`
76+
Type ArangoTaskType `json:"type"`
77+
DeploymentName string `json:"deploymentName"`
7878
Details ArangoTaskDetails `json:"details,omitempty"`
7979
}
8080

pkg/apis/deployment/v2alpha1/arango_task_spec.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ var _ json.Unmarshaler = &ArangoTaskDetails{}
7373
var _ json.Marshaler = ArangoTaskDetails{}
7474

7575
type ArangoTaskSpec struct {
76-
Type ArangoTaskType `json:"type,required"`
77-
DeploymentName string `json:"deploymentName,required"`
76+
Type ArangoTaskType `json:"type"`
77+
DeploymentName string `json:"deploymentName"`
7878
Details ArangoTaskDetails `json:"details,omitempty"`
7979
}
8080

pkg/deployment/reconcile/action_ping.go

+34
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package reconcile
2222

2323
import (
2424
"context"
25+
"time"
2526

2627
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2728
)
@@ -52,5 +53,38 @@ func (a *pingAction) Start(ctx context.Context) (bool, error) {
5253
}
5354

5455
func (a *pingAction) CheckProgress(ctx context.Context) (bool, bool, error) {
56+
if a.action.TaskID == "" {
57+
a.log.Error("taskName parameter is missing")
58+
return false, true, nil
59+
}
60+
61+
tasksCache, err := a.actionCtx.ACS().Cache().ArangoTask().V1()
62+
if err != nil {
63+
a.log.Err(err).Error("Failed to get ArangoTask cache")
64+
return false, false, err
65+
}
66+
67+
task, exist := tasksCache.GetSimpleByID(a.action.TaskID)
68+
if !exist {
69+
a.log.Error("ArangoTask not found")
70+
return false, false, err
71+
}
72+
73+
if task.Spec.Details != nil {
74+
pingBody := api.ArangoTaskPing{}
75+
if err := task.Spec.Details.Get(&pingBody); err != nil {
76+
a.log.Err(err).Error("Failed to parse ArangoTaskPing content")
77+
return false, false, err
78+
}
79+
80+
if pingBody.DurationSeconds != 0 {
81+
a.log.Info("Checking ArangoTaskPing duration limits")
82+
upTo := a.action.CreationTime.Add(time.Duration(pingBody.DurationSeconds) * time.Second)
83+
if time.Now().Before(upTo) {
84+
return false, false, nil
85+
}
86+
}
87+
}
88+
5589
return true, false, nil
5690
}

pkg/deployment/reconcile/plan_executor.go

+4
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ func (d *Reconciler) updateTaskStatus(ctx context.Context, action api.Action, st
396396

397397
task.Status.State = state
398398

399+
if task.Status.AcceptedSpec == nil {
400+
task.Status.AcceptedSpec = &task.Spec
401+
}
402+
399403
ind := sort.Search(len(task.Status.ActionsState), func(i int) bool {
400404
return task.Status.ActionsState[i].ActionId == action.ID
401405
})

0 commit comments

Comments
 (0)