From a006e5612b3025faf26d24482e293a9e2d5e48fa Mon Sep 17 00:00:00 2001 From: caicloud-bot Date: Tue, 21 Apr 2020 17:06:36 +0800 Subject: [PATCH] fix: overall last transition time not correct (#1416) Co-authored-by: zhujian --- pkg/server/handler/init.go | 7 ++++++- pkg/workflow/workflowrun/operator.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/server/handler/init.go b/pkg/server/handler/init.go index 454e46364..5b0d14415 100644 --- a/pkg/server/handler/init.go +++ b/pkg/server/handler/init.go @@ -2,9 +2,11 @@ package handler import ( "encoding/json" + "time" "github.com/caicloud/cyclone/pkg/apis/cyclone/v1alpha1" "github.com/caicloud/cyclone/pkg/k8s/clientset" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var ( @@ -51,8 +53,11 @@ type JSONPatch struct { // BuildWfrStatusPatch builds patch for updating status of workflowrun func BuildWfrStatusPatch(statusPhase v1alpha1.StatusPhase) ([]byte, error) { + now := metav1.Time{Time: time.Now()} + p := map[string]string{ - "/status/overall/phase": string(statusPhase), + "/status/overall/phase": string(statusPhase), + "/status/overall/lastTransitionTime": now.UTC().Format(time.RFC3339), } return BuildPatch(p) } diff --git a/pkg/workflow/workflowrun/operator.go b/pkg/workflow/workflowrun/operator.go index 10765ff1c..504999abe 100644 --- a/pkg/workflow/workflowrun/operator.go +++ b/pkg/workflow/workflowrun/operator.go @@ -184,6 +184,10 @@ func (o *operator) Update() error { if !reflect.DeepEqual(staticStatus(&latest.Status), staticStatus(&combined.Status)) || len(latest.OwnerReferences) != len(combined.OwnerReferences) { + + // If status has any change, the overall last transition time need to update + combined.Status.Overall.LastTransitionTime = metav1.Time{Time: time.Now()} + _, err = o.client.CycloneV1alpha1().WorkflowRuns(latest.Namespace).Update(combined) if err == nil { log.WithField("wfr", latest.Name).