-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
050e214
commit a1debfb
Showing
2 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
pkg/controllers/clusterresourceplacementeviction/controller_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package clusterresourceplacementeviction | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
|
||
placementv1alpha1 "go.goms.io/fleet/apis/placement/v1alpha1" | ||
placementv1beta1 "go.goms.io/fleet/apis/placement/v1beta1" | ||
) | ||
|
||
func TestGetOrCreateClusterSchedulingPolicySnapshot(t *testing.T) { | ||
availableCondition := metav1.Condition{ | ||
Type: string(placementv1beta1.ResourceBindingAvailable), | ||
Status: metav1.ConditionTrue, | ||
Reason: "available", | ||
ObservedGeneration: 1, | ||
} | ||
scheduledBinding := placementv1beta1.ClusterResourceBinding{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "scheduled-binding", | ||
Labels: map[string]string{placementv1beta1.CRPTrackingLabel: "test-crp"}, | ||
}, | ||
Spec: placementv1beta1.ResourceBindingSpec{ | ||
State: placementv1beta1.BindingStateScheduled, | ||
ResourceSnapshotName: "test-resource-snapshot", | ||
SchedulingPolicySnapshotName: "test-scheduling-policy-snapshot", | ||
TargetCluster: "test-cluster-1", | ||
}, | ||
} | ||
boundAvailableBinding := placementv1beta1.ClusterResourceBinding{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "bound-available-binding", | ||
Labels: map[string]string{placementv1beta1.CRPTrackingLabel: "test-crp"}, | ||
}, | ||
Spec: placementv1beta1.ResourceBindingSpec{ | ||
State: placementv1beta1.BindingStateBound, | ||
ResourceSnapshotName: "test-resource-snapshot", | ||
SchedulingPolicySnapshotName: "test-scheduling-policy-snapshot", | ||
TargetCluster: "test-cluster-2", | ||
}, | ||
Status: placementv1beta1.ResourceBindingStatus{ | ||
Conditions: []metav1.Condition{availableCondition}, | ||
}, | ||
} | ||
//boundUnavailableBinding := placementv1beta1.ClusterResourceBinding{ | ||
// ObjectMeta: metav1.ObjectMeta{ | ||
// Name: "bound-unavailable-binding", | ||
// Labels: map[string]string{placementv1beta1.CRPTrackingLabel: "test-crp"}, | ||
// }, | ||
// Spec: placementv1beta1.ResourceBindingSpec{ | ||
// State: placementv1beta1.BindingStateBound, | ||
// ResourceSnapshotName: "test-resource-snapshot", | ||
// SchedulingPolicySnapshotName: "test-scheduling-policy-snapshot", | ||
// TargetCluster: "test-cluster-3", | ||
// }, | ||
//} | ||
//unScheduledAvailableBinding := placementv1beta1.ClusterResourceBinding{ | ||
// ObjectMeta: metav1.ObjectMeta{ | ||
// Name: "unscheduled-available-binding", | ||
// Labels: map[string]string{placementv1beta1.CRPTrackingLabel: "test-crp"}, | ||
// }, | ||
// Spec: placementv1beta1.ResourceBindingSpec{ | ||
// State: placementv1beta1.BindingStateBound, | ||
// ResourceSnapshotName: "test-resource-snapshot", | ||
// SchedulingPolicySnapshotName: "test-scheduling-policy-snapshot", | ||
// TargetCluster: "test-cluster-2", | ||
// }, | ||
// Status: placementv1beta1.ResourceBindingStatus{ | ||
// Conditions: []metav1.Condition{availableCondition}, | ||
// }, | ||
//} | ||
tests := []struct { | ||
name string | ||
policy *placementv1beta1.PlacementPolicy | ||
bindings []placementv1beta1.ClusterResourceBinding | ||
disruptionBudget placementv1alpha1.ClusterResourcePlacementDisruptionBudget | ||
want bool | ||
}{ | ||
{ | ||
name: "PlacementType PickFixed, maxUnavailable specified as Integer zero - block eviction", | ||
policy: &placementv1beta1.PlacementPolicy{ | ||
PlacementType: placementv1beta1.PickFixedPlacementType, | ||
ClusterNames: []string{"test-cluster-2"}, | ||
}, | ||
bindings: []placementv1beta1.ClusterResourceBinding{boundAvailableBinding}, | ||
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-disruption-budget", | ||
}, | ||
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{ | ||
MaxUnavailable: &intstr.IntOrString{ | ||
Type: intstr.Int, | ||
IntVal: 0, | ||
}, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "PlacementType PickAll, maxUnavailable specified as Integer greater than zero - block eviction", | ||
policy: &placementv1beta1.PlacementPolicy{ | ||
PlacementType: placementv1beta1.PickAllPlacementType, | ||
}, | ||
bindings: []placementv1beta1.ClusterResourceBinding{scheduledBinding, boundAvailableBinding}, | ||
disruptionBudget: placementv1alpha1.ClusterResourcePlacementDisruptionBudget{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-disruption-budget", | ||
}, | ||
Spec: placementv1alpha1.PlacementDisruptionBudgetSpec{ | ||
MaxUnavailable: &intstr.IntOrString{ | ||
Type: intstr.Int, | ||
IntVal: 1, | ||
}, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := isEvictionAllowed(tc.policy, tc.bindings, tc.disruptionBudget) | ||
if got != tc.want { | ||
t.Errorf("isEvictionAllowed test `%s` failed got: %v, want: %v", tc.name, got, tc.want) | ||
} | ||
}) | ||
} | ||
} |