diff --git a/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction.go b/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction.go index 1b1abec9f0cc..3ba4ef06e2a2 100644 --- a/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction.go +++ b/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction.go @@ -18,7 +18,6 @@ package clustereviction import ( "context" - "fmt" "k8s.io/klog/v2" @@ -48,16 +47,7 @@ func (p *ClusterEviction) Name() string { } // Filter checks if the target cluster is in the GracefulEvictionTasks which means it is in the process of eviction. -func (p *ClusterEviction) Filter(_ context.Context, bindingSpec *workv1alpha2.ResourceBindingSpec, bindingStatus *workv1alpha2.ResourceBindingStatus, cluster *clusterv1alpha1.Cluster) *framework.Result { - failoverHistory := bindingStatus.FailoverHistory - if len(failoverHistory) != 0 { - lastFailover := failoverHistory[len(failoverHistory)-1] - if containsCluster(lastFailover.ClustersBeforeFailover, cluster.Name) { - klog.V(2).Infof("Workload has been failed over from this cluster %s.", cluster.Name) - return framework.NewResult(framework.Unschedulable, fmt.Sprintf("workload has been failed over from this cluster %s", cluster.Name)) - } - } - +func (p *ClusterEviction) Filter(_ context.Context, bindingSpec *workv1alpha2.ResourceBindingSpec, _ *workv1alpha2.ResourceBindingStatus, cluster *clusterv1alpha1.Cluster) *framework.Result { if bindingSpec.ClusterInGracefulEvictionTasks(cluster.Name) { klog.V(2).Infof("Cluster(%s) is in the process of eviction.", cluster.Name) return framework.NewResult(framework.Unschedulable, "cluster(s) is in the process of eviction") @@ -65,13 +55,3 @@ func (p *ClusterEviction) Filter(_ context.Context, bindingSpec *workv1alpha2.Re return framework.NewResult(framework.Success) } - -// containsCluster checks if selected cluster has been previously failed over from -func containsCluster(clusters []string, findCluster string) bool { - for _, cluster := range clusters { - if cluster == findCluster { - return true - } - } - return false -} diff --git a/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction_test.go b/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction_test.go index 5abe44da8111..18111cb1927b 100644 --- a/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction_test.go +++ b/pkg/scheduler/framework/plugins/clustereviction/cluster_eviction_test.go @@ -19,7 +19,6 @@ package clustereviction import ( "context" "testing" - "time" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,12 +30,11 @@ import ( func TestClusterEviction_Filter(t *testing.T) { tests := []struct { - name string - bindingSpec *workv1alpha2.ResourceBindingSpec - bindingStatus *workv1alpha2.ResourceBindingStatus - cluster *clusterv1alpha1.Cluster - expectedCode framework.Code - expectError bool + name string + bindingSpec *workv1alpha2.ResourceBindingSpec + cluster *clusterv1alpha1.Cluster + expectedCode framework.Code + expectError bool }{ { name: "cluster is in graceful eviction tasks", @@ -47,7 +45,6 @@ func TestClusterEviction_Filter(t *testing.T) { }, }, }, - bindingStatus: &workv1alpha2.ResourceBindingStatus{}, cluster: &clusterv1alpha1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -65,7 +62,6 @@ func TestClusterEviction_Filter(t *testing.T) { }, }, }, - bindingStatus: &workv1alpha2.ResourceBindingStatus{}, cluster: &clusterv1alpha1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -75,29 +71,8 @@ func TestClusterEviction_Filter(t *testing.T) { expectError: false, }, { - name: "cluster has just been failed over from", + name: "no graceful eviction tasks", bindingSpec: &workv1alpha2.ResourceBindingSpec{}, - bindingStatus: &workv1alpha2.ResourceBindingStatus{ - FailoverHistory: []workv1alpha2.FailoverHistoryItem{ - { - ClustersBeforeFailover: []string{"cluster1"}, - Reason: workv1alpha2.ApplicationFailover, - StartTime: metav1.Time{Time: time.Now()}, - }, - }, - }, - cluster: &clusterv1alpha1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: "cluster1", - }, - }, - expectedCode: framework.Unschedulable, - expectError: true, - }, - { - name: "no graceful eviction tasks", - bindingSpec: &workv1alpha2.ResourceBindingSpec{}, - bindingStatus: &workv1alpha2.ResourceBindingStatus{}, cluster: &clusterv1alpha1.Cluster{ ObjectMeta: metav1.ObjectMeta{ Name: "cluster1", @@ -111,7 +86,7 @@ func TestClusterEviction_Filter(t *testing.T) { p := &ClusterEviction{} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result := p.Filter(context.Background(), tt.bindingSpec, tt.bindingStatus, tt.cluster) + result := p.Filter(context.Background(), tt.bindingSpec, nil, tt.cluster) assert.Equal(t, tt.expectedCode, result.Code()) assert.Equal(t, tt.expectError, result.AsError() != nil) })