diff --git a/charts/_crds/bases/policy.karmada.io_clusterpropagationpolicies.yaml b/charts/_crds/bases/policy.karmada.io_clusterpropagationpolicies.yaml index 35e4aa9b0bad..b33d8ddb99d2 100644 --- a/charts/_crds/bases/policy.karmada.io_clusterpropagationpolicies.yaml +++ b/charts/_crds/bases/policy.karmada.io_clusterpropagationpolicies.yaml @@ -244,6 +244,13 @@ spec: is set to "Weighted", and WeightPreference is not set, scheduler will weight all clusters the same. properties: + dynamicWeight: + description: DynamicWeight specifies the factor to generates + dynamic weight list. If specified, StaticWeightList + will be ignored. + enum: + - AvailableReplicas + type: string staticWeightList: description: StaticWeightList defines the static cluster weight. diff --git a/charts/_crds/bases/policy.karmada.io_propagationpolicies.yaml b/charts/_crds/bases/policy.karmada.io_propagationpolicies.yaml index 3a4c93e843f5..667d65a295fd 100644 --- a/charts/_crds/bases/policy.karmada.io_propagationpolicies.yaml +++ b/charts/_crds/bases/policy.karmada.io_propagationpolicies.yaml @@ -240,6 +240,13 @@ spec: is set to "Weighted", and WeightPreference is not set, scheduler will weight all clusters the same. properties: + dynamicWeight: + description: DynamicWeight specifies the factor to generates + dynamic weight list. If specified, StaticWeightList + will be ignored. + enum: + - AvailableReplicas + type: string staticWeightList: description: StaticWeightList defines the static cluster weight. diff --git a/charts/_crds/bases/policy.karmada.io_replicaschedulingpolicies.yaml b/charts/_crds/bases/policy.karmada.io_replicaschedulingpolicies.yaml index ee34bfb2ccf5..6febc84195cf 100644 --- a/charts/_crds/bases/policy.karmada.io_replicaschedulingpolicies.yaml +++ b/charts/_crds/bases/policy.karmada.io_replicaschedulingpolicies.yaml @@ -44,6 +44,12 @@ spec: description: Preferences describes weight for each cluster or for each group of cluster. properties: + dynamicWeight: + description: DynamicWeight specifies the factor to generates dynamic + weight list. If specified, StaticWeightList will be ignored. + enum: + - AvailableReplicas + type: string staticWeightList: description: StaticWeightList defines the static cluster weight. items: diff --git a/pkg/apis/policy/v1alpha1/propagation_types.go b/pkg/apis/policy/v1alpha1/propagation_types.go index 583365ec0a31..1d6260a3f822 100644 --- a/pkg/apis/policy/v1alpha1/propagation_types.go +++ b/pkg/apis/policy/v1alpha1/propagation_types.go @@ -168,7 +168,7 @@ type ClusterAffinity struct { ExcludeClusters []string `json:"exclude,omitempty"` } -// ReplicaSchedulingType describes scheduling methods for the "replicas" in a resouce. +// ReplicaSchedulingType describes scheduling methods for the "replicas" in a resource. type ReplicaSchedulingType string const ( diff --git a/pkg/apis/policy/v1alpha1/replicascheduling_types.go b/pkg/apis/policy/v1alpha1/replicascheduling_types.go index fbe3e3288321..164af0e4cc0c 100644 --- a/pkg/apis/policy/v1alpha1/replicascheduling_types.go +++ b/pkg/apis/policy/v1alpha1/replicascheduling_types.go @@ -37,6 +37,11 @@ type ClusterPreferences struct { // StaticWeightList defines the static cluster weight. // +required StaticWeightList []StaticClusterWeight `json:"staticWeightList"` + // DynamicWeight specifies the factor to generates dynamic weight list. + // If specified, StaticWeightList will be ignored. + // +kubebuilder:validation:Enum=AvailableReplicas + // +optional + DynamicWeight DynamicWeightFactor `json:"dynamicWeight,omitempty"` } // StaticClusterWeight defines the static cluster weight. @@ -51,6 +56,25 @@ type StaticClusterWeight struct { Weight int64 `json:"weight"` } +// DynamicWeightFactor represents the weight factor. +// For now only support 'AvailableReplicas', more factors could be extended if there is a need. +type DynamicWeightFactor string + +const ( + // DynamicWeightByAvailableReplicas represents the cluster weight list should be generated according to + // available resource (available replicas). + // Example: + // The scheduler selected 3 clusters (A/B/C) and should divide 12 replicas to them. + // Workload: + // Desired replica: 12 + // Cluster: + // A: Max available replica: 6 + // B: Max available replica: 12 + // C: Max available replica: 18 + // The weight of cluster A:B:C will be 6:12:18 (equals to 1:2:3). At last, the assignment would be 'A: 2, B: 4, C: 6'. + DynamicWeightByAvailableReplicas DynamicWeightFactor = "AvailableReplicas" +) + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // ReplicaSchedulingPolicyList contains a list of ReplicaSchedulingPolicy. diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 738c61144b33..647f9dd1bc93 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -64,7 +64,10 @@ func (c *Clientset) Tracker() testing.ObjectTracker { return c.tracker } -var _ clientset.Interface = &Clientset{} +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) // ClusterV1alpha1 retrieves the ClusterV1alpha1Client func (c *Clientset) ClusterV1alpha1() clusterv1alpha1.ClusterV1alpha1Interface {