From 079778ed87672305e06d7257c54ca9f2fbf01b40 Mon Sep 17 00:00:00 2001 From: Garrybest Date: Wed, 20 Oct 2021 20:31:39 +0800 Subject: [PATCH 1/2] add dispersal replica division preference Signed-off-by: Garrybest --- ...karmada.io_clusterpropagationpolicies.yaml | 7 +++++ ...policy.karmada.io_propagationpolicies.yaml | 7 +++++ ....karmada.io_replicaschedulingpolicies.yaml | 6 ++++ pkg/apis/policy/v1alpha1/propagation_types.go | 2 +- .../v1alpha1/replicascheduling_types.go | 29 +++++++++++++++++++ .../versioned/fake/clientset_generated.go | 5 +++- 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/charts/_crds/bases/policy.karmada.io_clusterpropagationpolicies.yaml b/charts/_crds/bases/policy.karmada.io_clusterpropagationpolicies.yaml index 35e4aa9b0..b33d8ddb9 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 3a4c93e84..667d65a29 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 ee34bfb2c..6febc8419 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 583365ec0..1d6260a3f 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 fbe3e3288..f7cd49e2b 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,30 @@ 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). e.g. + // The scheduler has 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 738c61144..647f9dd1b 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 { From 2b79b311317615afe4290e5d4c20b1001495d810 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Fri, 29 Oct 2021 12:49:12 +0800 Subject: [PATCH 2/2] Update pkg/apis/policy/v1alpha1/replicascheduling_types.go Signed-off-by: Kevin Wang --- .../v1alpha1/replicascheduling_types.go | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pkg/apis/policy/v1alpha1/replicascheduling_types.go b/pkg/apis/policy/v1alpha1/replicascheduling_types.go index f7cd49e2b..164af0e4c 100644 --- a/pkg/apis/policy/v1alpha1/replicascheduling_types.go +++ b/pkg/apis/policy/v1alpha1/replicascheduling_types.go @@ -62,21 +62,16 @@ type DynamicWeightFactor string const ( // DynamicWeightByAvailableReplicas represents the cluster weight list should be generated according to - // available resource(available replicas). e.g. - // The scheduler has 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'. + // 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" )