Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #183 from ryanzhang-oss/patch-status
Browse files Browse the repository at this point in the history
patch the status instead of update
  • Loading branch information
wonderflow authored Aug 26, 2020
2 parents bc0db9f + 35a65c5 commit 8f20a23
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 8f20a23

Please sign in to comment.