Skip to content

Commit

Permalink
add more UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru committed Dec 17, 2024
1 parent 17e5833 commit 9a35ffc
Showing 1 changed file with 170 additions and 0 deletions.
170 changes: 170 additions & 0 deletions pkg/controllers/rollout/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
cluster3 = "cluster-3"
cluster4 = "cluster-4"
cluster5 = "cluster-5"
cluster6 = "cluster-6"

cmpOptions = []cmp.Option{
cmp.AllowUnexported(toBeUpdatedBinding{}),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 9a35ffc

Please sign in to comment.