Skip to content

Commit

Permalink
Add LastTransitionTime field to phase progress
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Ghangal <[email protected]>
  • Loading branch information
PrasadG193 committed Apr 19, 2023
1 parent 1aed8dd commit 5146900
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/cr/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/customresource/actionset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ spec:
type: integer
estimatedUploadSizeB:
type: integer
lastTransitionTime:
type: string
format: date-time
type: object
type: object
phases:
Expand All @@ -300,6 +303,9 @@ spec:
type: integer
estimatedUploadSizeB:
type: integer
lastTransitionTime:
type: string
format: date-time
type: object
type: object
type: array
Expand Down
8 changes: 7 additions & 1 deletion pkg/function/kube_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions pkg/progress/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand All @@ -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)

Expand Down

0 comments on commit 5146900

Please sign in to comment.