Skip to content

Commit

Permalink
Merge pull request #5889 from mszacillo/cleanup-work-immediately
Browse files Browse the repository at this point in the history
Cleanup works from cluster if purgemode is immediately
  • Loading branch information
karmada-bot authored Nov 28, 2024
2 parents 1b8d09c + 082fe7c commit c8b033d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/util/helper/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ func ObtainBindingSpecExistingClusters(bindingSpec workv1alpha2.ResourceBindingS
}

for _, task := range bindingSpec.GracefulEvictionTasks {
clusterNames.Insert(task.FromCluster)
// EvictionTasks with Immediately PurgeMode should not be treated as existing clusters
// Work on those clusters should be removed immediately and treated as orphans
if task.PurgeMode != policyv1alpha1.Immediately {
clusterNames.Insert(task.FromCluster)
}
}

return clusterNames
Expand Down
31 changes: 31 additions & 0 deletions pkg/util/helper/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
Expand Down Expand Up @@ -335,6 +336,36 @@ func TestObtainBindingSpecExistingClusters(t *testing.T) {
},
want: sets.New("member1", "member2", "member3"),
},
{
name: "unique cluster names with GracefulEvictionTasks with PurgeMode Immediately",
bindingSpec: workv1alpha2.ResourceBindingSpec{
Clusters: []workv1alpha2.TargetCluster{
{
Name: "member1",
Replicas: 2,
},
{
Name: "member2",
Replicas: 3,
},
},
GracefulEvictionTasks: []workv1alpha2.GracefulEvictionTask{
{
FromCluster: "member3",
PurgeMode: policyv1alpha1.Immediately,
},
{
FromCluster: "member4",
PurgeMode: policyv1alpha1.Graciously,
},
{
FromCluster: "member5",
PurgeMode: policyv1alpha1.Never,
},
},
},
want: sets.New("member1", "member2", "member4", "member5"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit c8b033d

Please sign in to comment.