Skip to content

Commit

Permalink
add more UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru committed Nov 8, 2024
1 parent 3f52fd2 commit cb5830f
Showing 1 changed file with 172 additions and 1 deletion.
173 changes: 172 additions & 1 deletion pkg/controllers/clusterresourceplacementeviction/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestGetOrCreateClusterSchedulingPolicySnapshot(t *testing.T) {
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{scheduledUnavailableBinding, boundAvailableBinding, boundUnavailableBinding, unScheduledAvailableBinding},
bindings: []placementv1beta1.ClusterResourceBinding{scheduledUnavailableBinding, boundAvailableBinding, anotherBoundAvailableBinding, boundUnavailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
Expand Down Expand Up @@ -440,6 +440,177 @@ func TestGetOrCreateClusterSchedulingPolicySnapshot(t *testing.T) {
},
want: true,
},
{
name: "PlacementType PickAll, minAvailable specified as Integer large number greater than target number - blocks eviction",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{scheduledUnavailableBinding, boundAvailableBinding, anotherBoundAvailableBinding, boundUnavailableBinding, unScheduledAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 10,
},
},
},
want: false,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage zero - allow eviction, all bindings are unavailable",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{scheduledUnavailableBinding, boundUnavailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "0%",
},
},
},
want: true,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage zero - allow eviction, all bindings are available",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding, anotherBoundAvailableBinding, unScheduledAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "0%",
},
},
},
want: true,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage rounds upto one - block eviction, binding unavailable",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{scheduledUnavailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "10%",
},
},
},
want: false,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage rounds upto one - block eviction, binding available",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "10%",
},
},
},
want: false,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage rounds upto one - allow eviction",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding, unScheduledAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "10%",
},
},
},
want: true,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage greater than zero, rounds up to greater than 1 - block eviction",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{scheduledUnavailableBinding, boundAvailableBinding, anotherBoundAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "40%",
},
},
},
want: false,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage greater than zero, rounds up to greater than 1 - allow eviction",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding, anotherBoundAvailableBinding, unScheduledAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "40%",
},
},
},
want: true,
},
{
name: "PlacementType PickAll, minAvailable specified as percentage hundred - block eviction",
policy: &placementv1beta1.PlacementPolicy{
PlacementType: placementv1beta1.PickAllPlacementType,
},
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding, anotherBoundAvailableBinding, unScheduledAvailableBinding},
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{
Name: "test-disruption-budget",
},
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{
MinAvailable: &intstr.IntOrString{
Type: intstr.String,
StrVal: "100%",
},
},
},
want: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit cb5830f

Please sign in to comment.