Skip to content

Commit

Permalink
add some UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru committed Dec 17, 2024
1 parent 26b244e commit 17e5833
Showing 1 changed file with 112 additions and 25 deletions.
137 changes: 112 additions & 25 deletions pkg/controllers/rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 17e5833

Please sign in to comment.