diff --git a/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration.go b/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration.go index 48032b22..9ea0abe9 100644 --- a/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration.go +++ b/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration.go @@ -294,20 +294,23 @@ func (r *OAMApplicationReconciler) Reconcile(req reconcile.Request) (result reco record.Event(ac, event.Normal(reasonGGComponent, "Successfully garbage collected component")) } + // patch the final status + acPatch := client.MergeFrom(ac.DeepCopyObject()) + ac.Status.Workloads = make([]v1alpha2.WorkloadStatus, len(workloads)) for i := range workloads { ac.Status.Workloads[i] = workloads[i].Status() } - ac.SetConditions(v1alpha1.ReconcileSuccess()) - ac.Status.Dependency = v1alpha2.DependencyStatus{} waitTime := longWait if len(depStatus.Unsatisfied) != 0 { waitTime = dependCheckWait ac.Status.Dependency = *depStatus } - return reconcile.Result{RequeueAfter: waitTime}, errors.Wrap(r.client.Status().Update(ctx, ac), errUpdateAppConfigStatus) + + return reconcile.Result{RequeueAfter: waitTime}, + errors.Wrap(r.client.Status().Patch(ctx, ac, acPatch, client.FieldOwner(ac.GetUID())), errUpdateAppConfigStatus) } // if any finalizers newly registered, return true diff --git a/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration_test.go b/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration_test.go index c30ec922..c1707d78 100644 --- a/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration_test.go +++ b/pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration_test.go @@ -272,6 +272,25 @@ func TestReconciler(t *testing.T) { } return nil }), + MockStatusPatch: test.NewMockStatusPatchFn(nil, func(o runtime.Object) error { + want := ac( + withConditions(runtimev1alpha1.ReconcileSuccess()), + withWorkloadStatuses(v1alpha2.WorkloadStatus{ + ComponentName: componentName, + Reference: runtimev1alpha1.TypedReference{ + APIVersion: workload.GetAPIVersion(), + Kind: workload.GetKind(), + Name: workload.GetName(), + }, + }), + withDependencyStatus(depStatus), + ) + if diff := cmp.Diff(want, o.(*v1alpha2.ApplicationConfiguration), cmpopts.EquateEmpty()); diff != "" { + t.Errorf("\nclient.Status().Update(): -want, +got:\n%s", diff) + return errUnexpectedStatus + } + return nil + }), }, }, o: []ReconcilerOption{ @@ -362,6 +381,24 @@ func TestReconciler(t *testing.T) { } return nil }), + MockStatusPatch: test.NewMockStatusPatchFn(nil, func(o runtime.Object) error { + want := ac( + withWorkloadStatuses(v1alpha2.WorkloadStatus{ + ComponentName: componentName, + Reference: runtimev1alpha1.TypedReference{ + APIVersion: workload.GetAPIVersion(), + Kind: workload.GetKind(), + Name: workload.GetName(), + }, + }), + ) + want.SetConditions(runtimev1alpha1.ReconcileSuccess()) + if diff := cmp.Diff(want, o.(*v1alpha2.ApplicationConfiguration), cmpopts.EquateEmpty()); diff != "" { + t.Errorf("\nclient.Status().Update(): -want, +got:\n%s", diff) + return errUnexpectedStatus + } + return nil + }), }, }, o: []ReconcilerOption{ @@ -461,6 +498,24 @@ func TestReconciler(t *testing.T) { } return nil }), + MockStatusPatch: test.NewMockStatusPatchFn(nil, func(o runtime.Object) error { + want := ac( + withConditions(runtimev1alpha1.ReconcileSuccess()), + withWorkloadStatuses(v1alpha2.WorkloadStatus{ + ComponentName: componentName, + Reference: runtimev1alpha1.TypedReference{ + APIVersion: workload.GetAPIVersion(), + Kind: workload.GetKind(), + Name: workload.GetName(), + }, + }), + ) + if diff := cmp.Diff(want, o.(*v1alpha2.ApplicationConfiguration), cmpopts.EquateEmpty()); diff != "" { + t.Errorf("\nclient.Status().Update(): -want, +got:\n%s", diff) + return errUnexpectedStatus + } + return nil + }), }, }, o: []ReconcilerOption{