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

Commit 8f20a23

Browse files
authored
Merge pull request #183 from ryanzhang-oss/patch-status
patch the status instead of update
2 parents bc0db9f + 35a65c5 commit 8f20a23

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,20 +294,23 @@ func (r *OAMApplicationReconciler) Reconcile(req reconcile.Request) (result reco
294294
record.Event(ac, event.Normal(reasonGGComponent, "Successfully garbage collected component"))
295295
}
296296

297+
// patch the final status
298+
acPatch := client.MergeFrom(ac.DeepCopyObject())
299+
297300
ac.Status.Workloads = make([]v1alpha2.WorkloadStatus, len(workloads))
298301
for i := range workloads {
299302
ac.Status.Workloads[i] = workloads[i].Status()
300303
}
301-
302304
ac.SetConditions(v1alpha1.ReconcileSuccess())
303-
304305
ac.Status.Dependency = v1alpha2.DependencyStatus{}
305306
waitTime := longWait
306307
if len(depStatus.Unsatisfied) != 0 {
307308
waitTime = dependCheckWait
308309
ac.Status.Dependency = *depStatus
309310
}
310-
return reconcile.Result{RequeueAfter: waitTime}, errors.Wrap(r.client.Status().Update(ctx, ac), errUpdateAppConfigStatus)
311+
312+
return reconcile.Result{RequeueAfter: waitTime},
313+
errors.Wrap(r.client.Status().Patch(ctx, ac, acPatch, client.FieldOwner(ac.GetUID())), errUpdateAppConfigStatus)
311314
}
312315

313316
// if any finalizers newly registered, return true

pkg/controller/v1alpha2/applicationconfiguration/applicationconfiguration_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,25 @@ func TestReconciler(t *testing.T) {
272272
}
273273
return nil
274274
}),
275+
MockStatusPatch: test.NewMockStatusPatchFn(nil, func(o runtime.Object) error {
276+
want := ac(
277+
withConditions(runtimev1alpha1.ReconcileSuccess()),
278+
withWorkloadStatuses(v1alpha2.WorkloadStatus{
279+
ComponentName: componentName,
280+
Reference: runtimev1alpha1.TypedReference{
281+
APIVersion: workload.GetAPIVersion(),
282+
Kind: workload.GetKind(),
283+
Name: workload.GetName(),
284+
},
285+
}),
286+
withDependencyStatus(depStatus),
287+
)
288+
if diff := cmp.Diff(want, o.(*v1alpha2.ApplicationConfiguration), cmpopts.EquateEmpty()); diff != "" {
289+
t.Errorf("\nclient.Status().Update(): -want, +got:\n%s", diff)
290+
return errUnexpectedStatus
291+
}
292+
return nil
293+
}),
275294
},
276295
},
277296
o: []ReconcilerOption{
@@ -362,6 +381,24 @@ func TestReconciler(t *testing.T) {
362381
}
363382
return nil
364383
}),
384+
MockStatusPatch: test.NewMockStatusPatchFn(nil, func(o runtime.Object) error {
385+
want := ac(
386+
withWorkloadStatuses(v1alpha2.WorkloadStatus{
387+
ComponentName: componentName,
388+
Reference: runtimev1alpha1.TypedReference{
389+
APIVersion: workload.GetAPIVersion(),
390+
Kind: workload.GetKind(),
391+
Name: workload.GetName(),
392+
},
393+
}),
394+
)
395+
want.SetConditions(runtimev1alpha1.ReconcileSuccess())
396+
if diff := cmp.Diff(want, o.(*v1alpha2.ApplicationConfiguration), cmpopts.EquateEmpty()); diff != "" {
397+
t.Errorf("\nclient.Status().Update(): -want, +got:\n%s", diff)
398+
return errUnexpectedStatus
399+
}
400+
return nil
401+
}),
365402
},
366403
},
367404
o: []ReconcilerOption{
@@ -461,6 +498,24 @@ func TestReconciler(t *testing.T) {
461498
}
462499
return nil
463500
}),
501+
MockStatusPatch: test.NewMockStatusPatchFn(nil, func(o runtime.Object) error {
502+
want := ac(
503+
withConditions(runtimev1alpha1.ReconcileSuccess()),
504+
withWorkloadStatuses(v1alpha2.WorkloadStatus{
505+
ComponentName: componentName,
506+
Reference: runtimev1alpha1.TypedReference{
507+
APIVersion: workload.GetAPIVersion(),
508+
Kind: workload.GetKind(),
509+
Name: workload.GetName(),
510+
},
511+
}),
512+
)
513+
if diff := cmp.Diff(want, o.(*v1alpha2.ApplicationConfiguration), cmpopts.EquateEmpty()); diff != "" {
514+
t.Errorf("\nclient.Status().Update(): -want, +got:\n%s", diff)
515+
return errUnexpectedStatus
516+
}
517+
return nil
518+
}),
464519
},
465520
},
466521
o: []ReconcilerOption{

0 commit comments

Comments
 (0)