Skip to content

Commit

Permalink
Removing filter logic
Browse files Browse the repository at this point in the history
Signed-off-by: mszacillo <mszacillo@bloomberg.net>
  • Loading branch information
mszacillo committed Oct 30, 2024
1 parent 1d8fe66 commit 5dba54e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package clustereviction

import (
"context"
"fmt"

"k8s.io/klog/v2"

Expand Down Expand Up @@ -48,30 +47,11 @@ 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")
}

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package clustereviction
import (
"context"
"testing"
"time"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -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",
Expand All @@ -47,7 +45,6 @@ func TestClusterEviction_Filter(t *testing.T) {
},
},
},
bindingStatus: &workv1alpha2.ResourceBindingStatus{},
cluster: &clusterv1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand All @@ -65,7 +62,6 @@ func TestClusterEviction_Filter(t *testing.T) {
},
},
},
bindingStatus: &workv1alpha2.ResourceBindingStatus{},
cluster: &clusterv1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1",
Expand All @@ -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",
Expand All @@ -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)
})
Expand Down

0 comments on commit 5dba54e

Please sign in to comment.