From 9a35ffc7e0063a8fd18c1a5929b25866b57da387 Mon Sep 17 00:00:00 2001 From: Arvind Thirumurugan Date: Tue, 17 Dec 2024 15:49:54 -0800 Subject: [PATCH] add more UTs --- pkg/controllers/rollout/controller_test.go | 170 +++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/pkg/controllers/rollout/controller_test.go b/pkg/controllers/rollout/controller_test.go index e9783a915..6a1deb96a 100644 --- a/pkg/controllers/rollout/controller_test.go +++ b/pkg/controllers/rollout/controller_test.go @@ -39,6 +39,7 @@ var ( cluster3 = "cluster-3" cluster4 = "cluster-4" cluster5 = "cluster-5" + cluster6 = "cluster-6" cmpOptions = []cmp.Option{ cmp.AllowUnexported(toBeUpdatedBinding{}), @@ -1622,6 +1623,175 @@ func TestPickBindingsToRoll(t *testing.T) { wantNeedRoll: true, wantWaitTime: 0, }, + "test resource snapshot change with MaxUnavailable specified, evict resources on failed to apply bound binding - rollout allowed for one failed to apply bound binding": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster1)), + generateFailedToApplyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster2), + }, + latestResourceSnapshotName: "snapshot-2", + crp: clusterResourcePlacementForTest("test", + createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 2), + createPlacementRolloutStrategyForTest(fleetv1beta1.RollingUpdateRolloutStrategyType, &fleetv1beta1.RollingUpdateConfig{ + MaxUnavailable: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 1, + }, + MaxSurge: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 0, + }, + UnavailablePeriodSeconds: ptr.To(1), + }, nil)), + wantDesiredBindingsSpec: []fleetv1beta1.ResourceBindingSpec{ + {}, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster2, + ResourceSnapshotName: "snapshot-2", + }, + }, + wantTobeUpdatedBindings: []int{1}, + wantStaleUnselectedBindings: []int{}, + wantNeedRoll: true, + wantWaitTime: time.Second, + }, + "test upscale, evict resources from ready bound binding": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster1)), + generateReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster2), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster3), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster4), + }, + latestResourceSnapshotName: "snapshot-1", + crp: clusterResourcePlacementForTest("test", + createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 4), + createPlacementRolloutStrategyForTest(fleetv1beta1.RollingUpdateRolloutStrategyType, &fleetv1beta1.RollingUpdateConfig{ + MaxUnavailable: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 0, + }, + MaxSurge: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 0, + }, + UnavailablePeriodSeconds: ptr.To(1), + }, nil)), + wantDesiredBindingsSpec: []fleetv1beta1.ResourceBindingSpec{ + {}, + {}, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster3, + ResourceSnapshotName: "snapshot-1", + }, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster4, + ResourceSnapshotName: "snapshot-1", + }, + }, + wantTobeUpdatedBindings: []int{2, 3}, + wantStaleUnselectedBindings: []int{}, + wantNeedRoll: true, + wantWaitTime: 0, + }, + "test upscale with policy change MaxSurge specified, evict resources from canBeReady bound binding": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateCanBeReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster1)), + generateCanBeReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster2), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster3), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster4), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster5), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster6), + }, + latestResourceSnapshotName: "snapshot-1", + crp: clusterResourcePlacementForTest("test", + createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 4), + createPlacementRolloutStrategyForTest(fleetv1beta1.RollingUpdateRolloutStrategyType, &fleetv1beta1.RollingUpdateConfig{ + MaxUnavailable: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 0, + }, + MaxSurge: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 1, + }, + UnavailablePeriodSeconds: ptr.To(1), + }, nil)), + wantDesiredBindingsSpec: []fleetv1beta1.ResourceBindingSpec{ + {}, + {}, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster3, + ResourceSnapshotName: "snapshot-1", + }, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster4, + ResourceSnapshotName: "snapshot-1", + }, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster5, + ResourceSnapshotName: "snapshot-1", + }, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster6, + ResourceSnapshotName: "snapshot-1", + }, + }, + wantTobeUpdatedBindings: []int{2, 3, 4}, + wantStaleUnselectedBindings: []int{5}, + wantNeedRoll: true, + wantWaitTime: time.Second, + }, + "test upscale with resource change MaxUnavailable specified - rollout allowed for old bound and new scheduled bindings": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster1)), + generateReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster2), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-2", cluster3), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-2", cluster4), + }, + latestResourceSnapshotName: "snapshot-2", + crp: clusterResourcePlacementForTest("test", + createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 4), + createPlacementRolloutStrategyForTest(fleetv1beta1.RollingUpdateRolloutStrategyType, &fleetv1beta1.RollingUpdateConfig{ + MaxUnavailable: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 4, + }, + MaxSurge: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 0, + }, + UnavailablePeriodSeconds: ptr.To(1), + }, nil)), + wantDesiredBindingsSpec: []fleetv1beta1.ResourceBindingSpec{ + {}, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster2, + ResourceSnapshotName: "snapshot-2", + }, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster3, + ResourceSnapshotName: "snapshot-2", + }, + { + State: fleetv1beta1.BindingStateBound, + TargetCluster: cluster4, + ResourceSnapshotName: "snapshot-2", + }, + }, + wantTobeUpdatedBindings: []int{1, 2, 3}, + wantStaleUnselectedBindings: []int{}, + wantNeedRoll: true, + wantWaitTime: 0, + }, + //"test one scheduled, one deleting bound binding - rollout allowed": { // allBindings: []*fleetv1beta1.ClusterResourceBinding{ // generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-2", cluster1),