Merge pull request #5216 from yanfeng1992/fix-apienables

skip the filter if the cluster is already in the list of scheduling result even if the API is missed
This commit is contained in:
karmada-bot 2024-09-18 20:28:04 +08:00 committed by GitHub
commit ec0521a754
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 4 deletions

View File

@ -19,6 +19,7 @@ package apienablement
import ( import (
"context" "context"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/klog/v2" "k8s.io/klog/v2"
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
@ -54,10 +55,19 @@ func (p *APIEnablement) Filter(
_ *workv1alpha2.ResourceBindingStatus, _ *workv1alpha2.ResourceBindingStatus,
cluster *clusterv1alpha1.Cluster, cluster *clusterv1alpha1.Cluster,
) *framework.Result { ) *framework.Result {
if !helper.IsAPIEnabled(cluster.Status.APIEnablements, bindingSpec.Resource.APIVersion, bindingSpec.Resource.Kind) { if helper.IsAPIEnabled(cluster.Status.APIEnablements, bindingSpec.Resource.APIVersion, bindingSpec.Resource.Kind) {
klog.V(2).Infof("Cluster(%s) not fit as missing API(%s, kind=%s)", cluster.Name, bindingSpec.Resource.APIVersion, bindingSpec.Resource.Kind) return framework.NewResult(framework.Success)
return framework.NewResult(framework.Unschedulable, "cluster(s) did not have the API resource")
} }
return framework.NewResult(framework.Success) // Let the cluster pass if it is already on the list of schedule result and the cluster's
// API enablements is incomplete, to avoid the issue that cluster be accidentally removed
// due to untrusted API enablements.
if bindingSpec.TargetContains(cluster.Name) &&
!meta.IsStatusConditionTrue(cluster.Status.Conditions, clusterv1alpha1.ClusterConditionCompleteAPIEnablements) {
return framework.NewResult(framework.Success)
}
klog.V(2).Infof("Cluster(%s) not fit as missing API(%s, kind=%s)", cluster.Name, bindingSpec.Resource.APIVersion, bindingSpec.Resource.Kind)
return framework.NewResult(framework.Unschedulable, "cluster(s) did not have the API resource")
} }