diff --git a/pkg/apis/cr/v1alpha1/types.go b/pkg/apis/cr/v1alpha1/types.go index fe3088f95e7..803ce12659a 100644 --- a/pkg/apis/cr/v1alpha1/types.go +++ b/pkg/apis/cr/v1alpha1/types.go @@ -206,6 +206,9 @@ type PhaseProgress struct { // remaining data estimated with EstimatedUploadSizeB. // This field will be empty for phases which do not involve data movement. EstimatedTimeSeconds int64 `json:"estinatedTimeSeconds,omitempty"` + // LastTransitionTime represents the last date time when the progress status + // was received. + LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"` } // k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index fd423b86f37..f6729e56af9 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -537,6 +537,11 @@ func (c *Controller) runAction(ctx context.Context, t *tomb.Tomb, as *crv1alpha1 func (c *Controller) updateActionSetRunningPhase(ctx context.Context, as *crv1alpha1.ActionSet, phase string) { err := reconcile.ActionSet(ctx, c.crClient.CrV1alpha1(), as.Namespace, as.Name, func(as *crv1alpha1.ActionSet) error { as.Status.Progress.RunningPhase = phase + for i := 0; i < len(as.Status.Actions[0].Phases); i++ { + if as.Status.Actions[0].Phases[i].Name == phase { + as.Status.Actions[0].Phases[i].State = crv1alpha1.StateRunning + } + } return nil }) if err != nil { diff --git a/pkg/customresource/actionset.yaml b/pkg/customresource/actionset.yaml index 1f25cde816b..ddc31a8580f 100644 --- a/pkg/customresource/actionset.yaml +++ b/pkg/customresource/actionset.yaml @@ -277,6 +277,9 @@ spec: type: integer estimatedUploadSizeB: type: integer + lastTransitionTime: + type: string + format: date-time type: object type: object phases: @@ -300,6 +303,9 @@ spec: type: integer estimatedUploadSizeB: type: integer + lastTransitionTime: + type: string + format: date-time type: object type: object type: array diff --git a/pkg/function/kube_task.go b/pkg/function/kube_task.go index 5bc078a849b..1cc045573ff 100644 --- a/pkg/function/kube_task.go +++ b/pkg/function/kube_task.go @@ -16,9 +16,11 @@ package function import ( "context" + "time" "github.com/pkg/errors" v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" kanister "github.com/kanisterio/kanister/pkg" @@ -138,5 +140,9 @@ func (*kubeTaskFunc) Arguments() []string { } func (k *kubeTaskFunc) ExecProgress() (crv1alpha1.PhaseProgress, error) { - return crv1alpha1.PhaseProgress{ProgressPercent: k.progressPercent}, nil + metav1Time := metav1.NewTime(time.Now()) + return crv1alpha1.PhaseProgress{ + ProgressPercent: k.progressPercent, + LastTransitionTime: &metav1Time, + }, nil } diff --git a/pkg/progress/action.go b/pkg/progress/action.go index c3373a60197..3e43fead2f9 100644 --- a/pkg/progress/action.go +++ b/pkg/progress/action.go @@ -201,8 +201,9 @@ func updateActionSetPhaseProgress(actionSet *crv1alpha1.ActionSet, phaseProgress // Update or create phase status in ActionSet status for i := 0; i < len(actionSet.Status.Actions[0].Phases); i++ { if actionSet.Status.Actions[0].Phases[i].Name == actionSet.Status.Progress.RunningPhase { - actionSet.Status.Actions[0].Phases[i].State = crv1alpha1.StateRunning - actionSet.Status.Actions[0].Phases[i].Progress = phaseProgress + if actionSet.Status.Actions[0].Phases[i].Progress.ProgressPercent != phaseProgress.ProgressPercent { + actionSet.Status.Actions[0].Phases[i].Progress = phaseProgress + } } } } @@ -211,8 +212,8 @@ func updateActionSetPhaseProgress(actionSet *crv1alpha1.ActionSet, phaseProgress // is calculated by taking an average of all the involved phases. func UpdateActionSetProgress(actionSet *crv1alpha1.ActionSet) { actionProgress := 0 - for i := 0; i < len(actionSet.Status.Actions[0].Phases); i++ { - actionProgress += actionSet.Status.Actions[0].Phases[i].Progress.ProgressPercent + for _, phase := range actionSet.Status.Actions[0].Phases { + actionProgress += phase.Progress.ProgressPercent } actionProgress = actionProgress / len(actionSet.Status.Actions[0].Phases)