Skip to content

Commit 3e4771b

Browse files
authored
Merge pull request #6462 from abhinav-1305/fix/api-enablement-no-deletion
fix: ensure APIEnablement plugin never deletes scheduled resources
2 parents d74b6da + f86aca8 commit 3e4771b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

pkg/scheduler/framework/plugins/apienablement/api_enablement.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package apienablement
1919
import (
2020
"context"
2121

22-
"k8s.io/apimachinery/pkg/api/meta"
2322
"k8s.io/klog/v2"
2423

2524
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
@@ -55,15 +54,21 @@ func (p *APIEnablement) Filter(
5554
_ *workv1alpha2.ResourceBindingStatus,
5655
cluster *clusterv1alpha1.Cluster,
5756
) *framework.Result {
58-
if helper.IsAPIEnabled(cluster.Status.APIEnablements, bindingSpec.Resource.APIVersion, bindingSpec.Resource.Kind) {
57+
// If the cluster is already in the target list, always allow it to pass
58+
// This ensures the scheduler never deletes scheduled resources by this plugin.
59+
// In case of the required APIs(CRDs) are accidentally deleted from member cluster, Karmada
60+
// controllers will try recreating these resources once the API becomes available again.
61+
if bindingSpec.TargetContains(cluster.Name) {
5962
return framework.NewResult(framework.Success)
6063
}
6164

62-
// Let the cluster pass if it is already on the list of schedule result and the cluster's
63-
// API enablements is incomplete, to avoid the issue that cluster be accidentally removed
64-
// due to untrusted API enablements.
65-
if bindingSpec.TargetContains(cluster.Name) &&
66-
!meta.IsStatusConditionTrue(cluster.Status.Conditions, clusterv1alpha1.ClusterConditionCompleteAPIEnablements) {
65+
// For new scheduling decisions, check if the API is enabled to ensure the application
66+
// is deployed to a cluster that supports all required APIs.
67+
// Note: Although controllers may not always get the complete API list,
68+
// we enforce strict checks to maintain consistency. This may occasionally
69+
// exclude clusters prematurely. Users requiring a specific number of target
70+
// clusters should use SpreadConstraints(in PropagationPolicy) to meet their requirements.
71+
if helper.IsAPIEnabled(cluster.Status.APIEnablements, bindingSpec.Resource.APIVersion, bindingSpec.Resource.Kind) {
6772
return framework.NewResult(framework.Success)
6873
}
6974

pkg/scheduler/framework/plugins/apienablement/api_enablement_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestAPIEnablement_Filter(t *testing.T) {
9393
expectError: true,
9494
},
9595
{
96-
name: "cluster in target list with incomplete API enablements",
96+
name: "cluster in target list with API not enabled",
9797
bindingSpec: &workv1alpha2.ResourceBindingSpec{
9898
Resource: workv1alpha2.ObjectReference{
9999
APIVersion: "custom.io/v1",
@@ -110,10 +110,14 @@ func TestAPIEnablement_Filter(t *testing.T) {
110110
Name: "cluster1",
111111
},
112112
Status: clusterv1alpha1.ClusterStatus{
113-
Conditions: []metav1.Condition{
113+
APIEnablements: []clusterv1alpha1.APIEnablement{
114114
{
115-
Type: clusterv1alpha1.ClusterConditionCompleteAPIEnablements,
116-
Status: metav1.ConditionFalse,
115+
GroupVersion: "apps/v1",
116+
Resources: []clusterv1alpha1.APIResource{
117+
{
118+
Kind: "Deployment",
119+
},
120+
},
117121
},
118122
},
119123
},

0 commit comments

Comments
 (0)