Skip to content

Commit

Permalink
Add more unit test for Rollout ProgressivePerGroup case
Browse files Browse the repository at this point in the history
Signed-off-by: melserngawy <melserng@redhat.com>
  • Loading branch information
serngawy committed Nov 3, 2023
1 parent c9fd8e3 commit 9f51eb9
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cluster/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func progressivePerGroup(

// As it is perGroup Return if there are clusters to rollOut,
// or there was a breach of the MaxFailure configuration
if len(rolloutClusters) > 0 || failureBreach {
if len(rolloutClusters) > maxGroupFailures || failureBreach {
return RolloutResult{
ClustersToRollout: rolloutClusters,
ClustersTimeOut: timeoutClusters,
Expand Down
152 changes: 152 additions & 0 deletions cluster/v1alpha1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,102 @@ func TestGetRolloutCluster_ProgressivePerGroup(t *testing.T) {
},
},
},
{
name: "test progressivePerGroup rollout with timeout None, first group 1 cluster is failing and maxFailures is 1",
rolloutStrategy: RolloutStrategy{
Type: ProgressivePerGroup,
ProgressivePerGroup: &RolloutProgressivePerGroup{
RolloutConfig: RolloutConfig{ProgressDeadline: "None", MaxFailures: intstr.FromInt(1)},
},
},
existingScheduledClusterGroups: map[clusterv1beta1.GroupKey]sets.Set[string]{
{GroupName: "group1", GroupIndex: 0}: sets.New[string]("cluster1", "cluster2", "cluster3"),
{GroupName: "", GroupIndex: 1}: sets.New[string]("cluster4", "cluster5", "cluster6"),
{GroupName: "", GroupIndex: 2}: sets.New[string]("cluster7", "cluster8", "cluster9"),
},
clusterRolloutStatusFunc: dummyWorkloadClusterRolloutStatusFunc,
expectRolloutStrategy: &RolloutStrategy{
Type: ProgressivePerGroup,
ProgressivePerGroup: &RolloutProgressivePerGroup{
RolloutConfig: RolloutConfig{ProgressDeadline: "None", MaxFailures: intstr.FromInt(1)},
},
},
existingWorkloads: []dummyWorkload{
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster1",
State: done,
LastTransitionTime: &fakeTime_60s,
},
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster2",
State: failed,
LastTransitionTime: &fakeTime_120s,
},
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster3",
State: done,
LastTransitionTime: &fakeTime_60s,
},
},
expectRolloutResult: RolloutResult{
ClustersToRollout: []ClusterRolloutStatus{
{ClusterName: "cluster2", GroupKey: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0}, Status: Failed, LastTransitionTime: &fakeTime_120s, TimeOutTime: &fakeTimeMax_120s},
{ClusterName: "cluster4", GroupKey: clusterv1beta1.GroupKey{GroupIndex: 1}, Status: ToApply},
{ClusterName: "cluster5", GroupKey: clusterv1beta1.GroupKey{GroupIndex: 1}, Status: ToApply},
{ClusterName: "cluster6", GroupKey: clusterv1beta1.GroupKey{GroupIndex: 1}, Status: ToApply},
},
},
},
{
name: "test progressivePerGroup rollout with timeout None, first group 2 clusters are failing 2 and maxFailures is 30%",
rolloutStrategy: RolloutStrategy{
Type: ProgressivePerGroup,
ProgressivePerGroup: &RolloutProgressivePerGroup{
RolloutConfig: RolloutConfig{ProgressDeadline: "None", MaxFailures: intstr.FromString("30%")},
},
},
existingScheduledClusterGroups: map[clusterv1beta1.GroupKey]sets.Set[string]{
{GroupName: "group1", GroupIndex: 0}: sets.New[string]("cluster1", "cluster2", "cluster3"),
{GroupName: "", GroupIndex: 1}: sets.New[string]("cluster4", "cluster5", "cluster6"),
{GroupName: "", GroupIndex: 2}: sets.New[string]("cluster7", "cluster8", "cluster9"),
},
clusterRolloutStatusFunc: dummyWorkloadClusterRolloutStatusFunc,
expectRolloutStrategy: &RolloutStrategy{
Type: ProgressivePerGroup,
ProgressivePerGroup: &RolloutProgressivePerGroup{
RolloutConfig: RolloutConfig{ProgressDeadline: "None", MaxFailures: intstr.FromString("30%")},
},
},
existingWorkloads: []dummyWorkload{
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster1",
State: done,
LastTransitionTime: &fakeTime_60s,
},
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster2",
State: failed,
LastTransitionTime: &fakeTime_120s,
},
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster3",
State: failed,
LastTransitionTime: &fakeTime_120s,
},
},
expectRolloutResult: RolloutResult{
ClustersToRollout: []ClusterRolloutStatus{
{ClusterName: "cluster2", GroupKey: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0}, Status: Failed, LastTransitionTime: &fakeTime_120s, TimeOutTime: &fakeTimeMax_120s},
{ClusterName: "cluster3", GroupKey: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0}, Status: Failed, LastTransitionTime: &fakeTime_120s, TimeOutTime: &fakeTimeMax_120s},
},
},
},
{
name: "test ProgressivePerGroup rollout with mandatoryDecisionGroup failing and timeout 90s ",
rolloutStrategy: RolloutStrategy{
Expand Down Expand Up @@ -1311,6 +1407,62 @@ func TestGetRolloutCluster_ProgressivePerGroup(t *testing.T) {
},
},
},
{
name: "test progressivePerGroup rollout with mandatoryDecisionGroup failing 1 cluster, timeout 90s and with maxFailures is 1",
rolloutStrategy: RolloutStrategy{
Type: ProgressivePerGroup,
ProgressivePerGroup: &RolloutProgressivePerGroup{
MandatoryDecisionGroups: MandatoryDecisionGroups{
MandatoryDecisionGroups: []MandatoryDecisionGroup{
{GroupName: "group1"},
},
},
RolloutConfig: RolloutConfig{ProgressDeadline: "90s", MaxFailures: intstr.FromInt(1)},
},
},
existingScheduledClusterGroups: map[clusterv1beta1.GroupKey]sets.Set[string]{
{GroupName: "group1", GroupIndex: 0}: sets.New[string]("cluster1", "cluster2", "cluster3"),
{GroupName: "", GroupIndex: 1}: sets.New[string]("cluster4", "cluster5", "cluster6"),
{GroupName: "", GroupIndex: 2}: sets.New[string]("cluster7", "cluster8", "cluster9"),
},
clusterRolloutStatusFunc: dummyWorkloadClusterRolloutStatusFunc,
expectRolloutStrategy: &RolloutStrategy{
Type: ProgressivePerGroup,
ProgressivePerGroup: &RolloutProgressivePerGroup{
MandatoryDecisionGroups: MandatoryDecisionGroups{
MandatoryDecisionGroups: []MandatoryDecisionGroup{
{GroupName: "group1"},
},
},
RolloutConfig: RolloutConfig{ProgressDeadline: "90s", MaxFailures: intstr.FromInt(1)},
},
},
existingWorkloads: []dummyWorkload{
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster1",
State: done,
LastTransitionTime: &fakeTime_60s,
},
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster2",
State: failed,
LastTransitionTime: &fakeTime_120s,
},
{
ClusterGroup: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0},
ClusterName: "cluster3",
State: done,
LastTransitionTime: &fakeTime_60s,
},
},
expectRolloutResult: RolloutResult{
ClustersTimeOut: []ClusterRolloutStatus{
{ClusterName: "cluster2", GroupKey: clusterv1beta1.GroupKey{GroupName: "group1", GroupIndex: 0}, Status: TimeOut, LastTransitionTime: &fakeTime_120s, TimeOutTime: &fakeTime_30s},
},
},
},
{
name: "test ProgressivePerGroup rollout with mandatoryDecisionGroup Succeeded and timeout 90s ",
rolloutStrategy: RolloutStrategy{
Expand Down

0 comments on commit 9f51eb9

Please sign in to comment.