diff --git a/pkg/controllers/rollout/controller_test.go b/pkg/controllers/rollout/controller_test.go index 5774b9971..e9783a915 100644 --- a/pkg/controllers/rollout/controller_test.go +++ b/pkg/controllers/rollout/controller_test.go @@ -1510,31 +1510,118 @@ func TestPickBindingsToRoll(t *testing.T) { wantNeedRoll: false, wantWaitTime: time.Second, }, - //"test policy change with MaxSurge specified, evict resources on unscheduled cluster": { - // allBindings: []*fleetv1beta1.ClusterResourceBinding{ - // generateDeletingClusterResourceBinding(fleetv1beta1.BindingStateUnscheduled, cluster1), - // generateClusterResourceBinding(fleetv1beta1.BindingStateUnscheduled, "snapshot-1", cluster2), - // generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster3), - // generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster4), - // }, - // crp: clusterResourcePlacementForTest("test", - // createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 2), - // createPlacementRolloutStrategyForTest(fleetv1beta1.RollingUpdateRolloutStrategyType, &fleetv1beta1.RollingUpdateConfig{ - // MaxUnavailable: &intstr.IntOrString{ - // Type: intstr.Int, - // IntVal: 0, - // }, - // MaxSurge: &intstr.IntOrString{ - // Type: intstr.Int, - // IntVal: 1, - // }, - // UnavailablePeriodSeconds: nil, - // }, nil)), - // wantTobeUpdatedBindings: []int{}, - // wantStaleUnselectedBindings: []int{}, - // wantNeedRoll: false, - // wantWaitTime: time.Second, - //}, + "test policy change with MaxSurge specified, evict resources on unscheduled cluster - rollout allowed for one scheduled binding": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateCanBeReadyClusterResourceBinding(fleetv1beta1.BindingStateUnscheduled, "snapshot-1", cluster1)), + generateCanBeReadyClusterResourceBinding(fleetv1beta1.BindingStateUnscheduled, "snapshot-1", cluster2), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster3), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster4), + }, + latestResourceSnapshotName: "snapshot-1", + crp: clusterResourcePlacementForTest("test", + createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 2), + 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", + }, + }, + wantTobeUpdatedBindings: []int{2}, + wantStaleUnselectedBindings: []int{3}, + wantNeedRoll: true, + wantWaitTime: time.Second, + }, + "test policy change with MaxUnavailable specified, evict resources on unscheduled cluster - rollout allowed for one unscheduled binding": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateReadyClusterResourceBinding(fleetv1beta1.BindingStateUnscheduled, "snapshot-1", cluster1)), + generateReadyClusterResourceBinding(fleetv1beta1.BindingStateUnscheduled, "snapshot-1", cluster2), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster3), + generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-1", cluster4), + }, + latestResourceSnapshotName: "snapshot-1", + crp: clusterResourcePlacementForTest("test", + createPlacementPolicyForTest(fleetv1beta1.PickNPlacementType, 2), + createPlacementRolloutStrategyForTest(fleetv1beta1.RollingUpdateRolloutStrategyType, &fleetv1beta1.RollingUpdateConfig{ + MaxUnavailable: &intstr.IntOrString{ + Type: intstr.Int, + IntVal: 2, + }, + 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{1}, + wantStaleUnselectedBindings: []int{2, 3}, + wantNeedRoll: true, + wantWaitTime: 0, + }, + "test resource snapshot change with MaxUnavailable specified, evict resources on ready bound binding - rollout allowed for one ready bound binding": { + allBindings: []*fleetv1beta1.ClusterResourceBinding{ + setDeletionTimeStampForBinding(generateReadyClusterResourceBinding(fleetv1beta1.BindingStateBound, "snapshot-1", cluster1)), + generateReadyClusterResourceBinding(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: 2, + }, + 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: 0, + }, //"test one scheduled, one deleting bound binding - rollout allowed": { // allBindings: []*fleetv1beta1.ClusterResourceBinding{ // generateClusterResourceBinding(fleetv1beta1.BindingStateScheduled, "snapshot-2", cluster1),