Merge pull request #3014 from chaunceyjiang/ValidateReplicaScheduling
fix: Validate replicaSchedulingType and replicaDivisionPreference
This commit is contained in:
commit
0330535ed8
|
@ -228,6 +228,7 @@ spec:
|
||||||
- Weighted
|
- Weighted
|
||||||
type: string
|
type: string
|
||||||
replicaSchedulingType:
|
replicaSchedulingType:
|
||||||
|
default: Divided
|
||||||
description: ReplicaSchedulingType determines how the replicas
|
description: ReplicaSchedulingType determines how the replicas
|
||||||
is scheduled when karmada propagating a resource. Valid
|
is scheduled when karmada propagating a resource. Valid
|
||||||
options are Duplicated and Divided. "Duplicated" duplicates
|
options are Duplicated and Divided. "Duplicated" duplicates
|
||||||
|
|
|
@ -224,6 +224,7 @@ spec:
|
||||||
- Weighted
|
- Weighted
|
||||||
type: string
|
type: string
|
||||||
replicaSchedulingType:
|
replicaSchedulingType:
|
||||||
|
default: Divided
|
||||||
description: ReplicaSchedulingType determines how the replicas
|
description: ReplicaSchedulingType determines how the replicas
|
||||||
is scheduled when karmada propagating a resource. Valid
|
is scheduled when karmada propagating a resource. Valid
|
||||||
options are Duplicated and Divided. "Duplicated" duplicates
|
options are Duplicated and Divided. "Duplicated" duplicates
|
||||||
|
|
|
@ -255,6 +255,7 @@ type ReplicaSchedulingStrategy struct {
|
||||||
// "Divided" divides replicas into parts according to number of valid candidate member
|
// "Divided" divides replicas into parts according to number of valid candidate member
|
||||||
// clusters, and exact replicas for each cluster are determined by ReplicaDivisionPreference.
|
// clusters, and exact replicas for each cluster are determined by ReplicaDivisionPreference.
|
||||||
// +kubebuilder:validation:Enum=Duplicated;Divided
|
// +kubebuilder:validation:Enum=Duplicated;Divided
|
||||||
|
// +kubebuilder:default=Divided
|
||||||
// +optional
|
// +optional
|
||||||
ReplicaSchedulingType ReplicaSchedulingType `json:"replicaSchedulingType,omitempty"`
|
ReplicaSchedulingType ReplicaSchedulingType `json:"replicaSchedulingType,omitempty"`
|
||||||
|
|
||||||
|
|
|
@ -130,3 +130,11 @@ func GetAppliedPlacement(annotations map[string]string) (*policyv1alpha1.Placeme
|
||||||
}
|
}
|
||||||
return placement, nil
|
return placement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetReplicaDivisionPreferenceWeighted Set the default value of ReplicaDivisionPreference to Weighted
|
||||||
|
func SetReplicaDivisionPreferenceWeighted(strategy *policyv1alpha1.ReplicaSchedulingStrategy) {
|
||||||
|
if strategy == nil || strategy.ReplicaSchedulingType != policyv1alpha1.ReplicaSchedulingTypeDivided || strategy.ReplicaDivisionPreference != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
strategy.ReplicaDivisionPreference = policyv1alpha1.ReplicaDivisionPreferenceWeighted
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,9 @@ func (a *MutatingAdmission) Handle(ctx context.Context, req admission.Request) a
|
||||||
policy.Spec.ResourceSelectors = append(policy.Spec.ResourceSelectors, addedResourceSelectors...)
|
policy.Spec.ResourceSelectors = append(policy.Spec.ResourceSelectors, addedResourceSelectors...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When ReplicaSchedulingType is Divided, set the default value of ReplicaDivisionPreference to Weighted.
|
||||||
|
helper.SetReplicaDivisionPreferenceWeighted(policy.Spec.Placement.ReplicaScheduling)
|
||||||
|
|
||||||
marshaledBytes, err := json.Marshal(policy)
|
marshaledBytes, err := json.Marshal(policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return admission.Errored(http.StatusInternalServerError, err)
|
return admission.Errored(http.StatusInternalServerError, err)
|
||||||
|
|
|
@ -68,6 +68,9 @@ func (a *MutatingAdmission) Handle(ctx context.Context, req admission.Request) a
|
||||||
policy.Spec.ResourceSelectors = append(policy.Spec.ResourceSelectors, addedResourceSelectors...)
|
policy.Spec.ResourceSelectors = append(policy.Spec.ResourceSelectors, addedResourceSelectors...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When ReplicaSchedulingType is Divided, set the default value of ReplicaDivisionPreference to Weighted.
|
||||||
|
helper.SetReplicaDivisionPreferenceWeighted(policy.Spec.Placement.ReplicaScheduling)
|
||||||
|
|
||||||
marshaledBytes, err := json.Marshal(policy)
|
marshaledBytes, err := json.Marshal(policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return admission.Errored(http.StatusInternalServerError, err)
|
return admission.Errored(http.StatusInternalServerError, err)
|
||||||
|
|
Loading…
Reference in New Issue