Skip to content

Commit 39110a4

Browse files
committed
update the ut
Signed-off-by: Zhiying Lin <[email protected]>
1 parent 0cd5fcf commit 39110a4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

pkg/controllers/clusterresourceplacement/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ func (r *Reconciler) deleteRedundantResourceSnapshots(ctx context.Context, crp *
466466
// getOrCreateClusterResourceSnapshot gets or creates a clusterResourceSnapshot for the given clusterResourcePlacement.
467467
// It returns the latest clusterResourceSnapshot if it exists and is up to date, otherwise it creates a new one.
468468
// It also returns the ctrl.Result to indicate whether the request should be requeued or not.
469+
// Note: when the ctrl.Result.Requeue is true, it still returns the current latest resourceSnapshot so that
470+
// placement can update the rollout status.
469471
func (r *Reconciler) getOrCreateClusterResourceSnapshot(ctx context.Context, crp *fleetv1beta1.ClusterResourcePlacement, envelopeObjCount int, resourceSnapshotSpec *fleetv1beta1.ResourceSnapshotSpec, revisionHistoryLimit int) (ctrl.Result, *fleetv1beta1.ClusterResourceSnapshot, error) {
470472
resourceHash, err := resource.HashOf(resourceSnapshotSpec)
471473
crpKObj := klog.KObj(crp)

pkg/controllers/clusterresourceplacement/controller_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,8 @@ func TestGetOrCreateClusterResourceSnapshot(t *testing.T) {
14871487
Spec: fleetv1beta1.ResourceSnapshotSpec{SelectedResources: []fleetv1beta1.ResourceContent{}},
14881488
},
14891489
},
1490-
wantRequeue: true,
1490+
wantRequeue: true,
1491+
wantLatestSnapshotIndex: 0,
14911492
},
14921493
{
14931494
name: "resource has changed and there is an active snapshot with multiple revisionLimit",
@@ -2203,7 +2204,8 @@ func TestGetOrCreateClusterResourceSnapshot(t *testing.T) {
22032204
Spec: fleetv1beta1.ResourceSnapshotSpec{SelectedResources: []fleetv1beta1.ResourceContent{deploymentResourceContent}},
22042205
},
22052206
},
2206-
wantRequeue: true,
2207+
wantRequeue: true,
2208+
wantLatestSnapshotIndex: 0,
22072209
},
22082210
{
22092211
name: "selected resources cross clusterResourceSnapshot limit, revision limit is 1, delete existing clusterResourceSnapshot with missing sub-indexed snapshots & create new clusterResourceSnapshots",
@@ -2708,10 +2710,9 @@ func TestGetOrCreateClusterResourceSnapshot(t *testing.T) {
27082710
if res.RequeueAfter <= 0 {
27092711
t.Fatalf("getOrCreateClusterResourceSnapshot() got RequeueAfter %v, want greater than zero value", res.RequeueAfter)
27102712
}
2711-
} else {
2712-
if diff := cmp.Diff(tc.wantResourceSnapshots[tc.wantLatestSnapshotIndex], *got, options...); diff != "" {
2713-
t.Errorf("getOrCreateClusterResourceSnapshot() mismatch (-want, +got):\n%s", diff)
2714-
}
2713+
}
2714+
if diff := cmp.Diff(tc.wantResourceSnapshots[tc.wantLatestSnapshotIndex], *got, options...); diff != "" {
2715+
t.Errorf("getOrCreateClusterResourceSnapshot() mismatch (-want, +got):\n%s", diff)
27152716
}
27162717
clusterResourceSnapshotList := &fleetv1beta1.ClusterResourceSnapshotList{}
27172718
if err := fakeClient.List(ctx, clusterResourceSnapshotList); err != nil {

0 commit comments

Comments
 (0)