diff --git a/pkg/apis/kudo/v1beta1/instance_types_helpers.go b/pkg/apis/kudo/v1beta1/instance_types_helpers.go index 7142bb3f1..044460b6c 100644 --- a/pkg/apis/kudo/v1beta1/instance_types_helpers.go +++ b/pkg/apis/kudo/v1beta1/instance_types_helpers.go @@ -2,7 +2,6 @@ package v1beta1 import ( "fmt" - "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" @@ -56,10 +55,10 @@ func (i *Instance) NoPlanEverExecuted() bool { } // UpdateInstanceStatus updates `Status.PlanStatus` and `Status.AggregatedStatus` property based on the given plan -func (i *Instance) UpdateInstanceStatus(planStatus *PlanStatus) { +func (i *Instance) UpdateInstanceStatus(planStatus *PlanStatus, updatedTimestamp *metav1.Time) { for k, v := range i.Status.PlanStatus { if v.Name == planStatus.Name { - planStatus.LastUpdatedTimestamp = &metav1.Time{Time: time.Now()} + planStatus.LastUpdatedTimestamp = updatedTimestamp i.Status.PlanStatus[k] = *planStatus i.Status.AggregatedStatus.Status = planStatus.Status if planStatus.Status.IsTerminal() { @@ -71,7 +70,7 @@ func (i *Instance) UpdateInstanceStatus(planStatus *PlanStatus) { // ResetPlanStatus method resets a PlanStatus for a passed plan name and instance. Plan/phase/step statuses // are set to ExecutionPending meaning that the controller will restart plan execution. -func (i *Instance) ResetPlanStatus(plan string) error { +func (i *Instance) ResetPlanStatus(plan string, updatedTimestamp *metav1.Time) error { planStatus := i.PlanStatus(plan) if planStatus == nil { return fmt.Errorf("failed to find planStatus for the plan '%s'", plan) @@ -90,7 +89,7 @@ func (i *Instance) ResetPlanStatus(plan string) error { } // update instance aggregated status - i.UpdateInstanceStatus(planStatus) + i.UpdateInstanceStatus(planStatus, updatedTimestamp) return nil } diff --git a/pkg/apis/kudo/v1beta1/instance_types_helpers_test.go b/pkg/apis/kudo/v1beta1/instance_types_helpers_test.go index f8d2e3400..9a5cebb66 100644 --- a/pkg/apis/kudo/v1beta1/instance_types_helpers_test.go +++ b/pkg/apis/kudo/v1beta1/instance_types_helpers_test.go @@ -124,7 +124,7 @@ func TestInstance_ResetPlanStatus(t *testing.T) { oldUID := instance.Status.PlanStatus["deploy"].UID - err := instance.ResetPlanStatus("deploy") + err := instance.ResetPlanStatus("deploy", &metav1.Time{Time: time.Now()}) assert.NoError(t, err) // we test that UID has changed. afterwards, we replace it with the old one and compare new diff --git a/pkg/controller/instance/instance_controller.go b/pkg/controller/instance/instance_controller.go index ef7ced56e..2bd2104c5 100644 --- a/pkg/controller/instance/instance_controller.go +++ b/pkg/controller/instance/instance_controller.go @@ -22,7 +22,9 @@ import ( "fmt" "log" "reflect" + "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/client-go/discovery" "k8s.io/client-go/rest" @@ -241,7 +243,7 @@ func (r *Reconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) { // ---------- 5. Update status of instance after the execution proceeded ---------- if newStatus != nil { - instance.UpdateInstanceStatus(newStatus) + instance.UpdateInstanceStatus(newStatus, &metav1.Time{Time: time.Now()}) } if err != nil { err = r.handleError(err, instance, oldInstance)