Skip to content

Conversation

@chaunceyjiang
Copy link
Member

@chaunceyjiang chaunceyjiang commented Feb 23, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #3187

Special notes for your reviewer:
the scheduler support SpreadByLabel constraints
Does this PR introduce a user-facing change?:

`karmada-scheduler`: the scheduler support SpreadByLabel constraints.

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 23, 2023
@karmada-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign kevin-wangzefeng after the PR has been reviewed.
You can assign the PR to them by writing /assign @kevin-wangzefeng in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 23, 2023
@RainbowMango RainbowMango added this to the v1.6 milestone Feb 23, 2023
@chaunceyjiang
Copy link
Member Author

apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: nginx
spec:
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: nginx
  placement:
    clusterAffinity:
      labelSelector:
        matchExpressions:
        - key: stage
          operator: In
          values:
          - dev
          - prod
    replicaScheduling:
      replicaSchedulingType: Divided
      replicaDivisionPreference: Weighted
      weightPreference:
        dynamicWeight: AvailableReplicas
    spreadConstraints:
    - maxGroups: 2
      minGroups: 2
      spreadByLabel: stage

@chaunceyjiang
Copy link
Member Author

/cc @RainbowMango @Garrybest @jwcesign

Please take a look.

@XiShanYongYe-Chang
Copy link
Member

/assign

@RainbowMango
Copy link
Member

Ping @XiShanYongYe-Chang

Comment on lines 41 to 44
if _, exist := spreadConstraintMap[policyv1alpha1.SpreadByFieldRegion]; exist {
return selectBestClustersByRegion(spreadConstraintMap, groupClustersInfo)
} else if _, exist := spreadConstraintMap[policyv1alpha1.SpreadByFieldCluster]; exist {
return selectBestClustersByCluster(spreadConstraintMap[policyv1alpha1.SpreadByFieldCluster], groupClustersInfo, needReplicas)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question about the previous logic.

Here bypass the logic according to spreadByField, what if we have two spread constraints? E.g:

    spreadConstraints:
      - spreadByField: region
        maxGroups: 2
        minGroups: 2
      - spreadByField: cluster
        maxGroups: 2
        minGroups: 2

This example has two constraints, one is spreadByField: region the other one is spreadByField: cluster. For this case, we are going to select the cluster only by region?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I get it.

regions := selectRegions(groupClustersInfo.Regions, spreadConstraintMap[policyv1alpha1.SpreadByFieldRegion], spreadConstraintMap[policyv1alpha1.SpreadByFieldCluster])

Here checked the cluster group.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't understand the purpose of your question. 'spreadByField' and 'spreadByLabel' cannot co-exist.

Comment on lines +29 to +31
if selector.Matches(labels.Set(clusterInfos[j].Cluster.GetLabels())) {
selectedClusters = append(selectedClusters, clusterInfos[j])
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question if two clusters have the same label(same key and value), should they be considered one group or two groups?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one group.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But two clusters that have the same label(same key but different value) should be considered two groups, right?

Comment on lines +45 to +46
} else if hasSpreadByLabel {
return selectBestClustersByClusterLabels(spreadConstraints, groupClustersInfo, needReplicas)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouping by label and field cannot take effect at the same time?

Such as the below config:

...
    spreadConstraints:
    - maxGroups: 2
      minGroups: 2
      spreadByLabel: stage
    - maxGroups: 2
      minGroups: 2
      spreadByField: cluster
    ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// SpreadByField and SpreadByLabel should not co-exist
if len(constraint.SpreadByField) > 0 && len(constraint.SpreadByLabel) > 0 {
allErrs = append(allErrs, field.Invalid(fldPath.Index(index), constraint, "spreadByLabel should not co-exist with spreadByField"))
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that's forbidden is the same constraint, they're in two constraints in the example.

Copy link
Member Author

@chaunceyjiang chaunceyjiang Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the reminder. Currently, spreadByLabel is being ignored in this situation. Do you have any good suggestions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't have a good idea yet. I feel that there are many factors to consider when implementing, and it may be complicated to implement.

@RainbowMango RainbowMango modified the milestones: v1.6, v1.7 May 29, 2023
@RainbowMango
Copy link
Member

I'm trying to figure out which PR/Issue should be included in the coming v1.7 release which is planned at the end of this month.
I guess we don't have enough time for this feature, so I'm moving this to v1.8.

I'll try to get back on the scheduler in v1.8, let's see if we can move this forward then.

@RainbowMango RainbowMango modified the milestones: v1.7, v1.8 Aug 25, 2023
@RainbowMango RainbowMango modified the milestones: v1.8, v1.9 Jan 9, 2024
@RainbowMango RainbowMango modified the milestones: v1.9, v1.10 Feb 29, 2024
@RainbowMango RainbowMango modified the milestones: v1.10, v1.11 May 29, 2024
@chenzhiguo
Copy link

I was about to open the same issue and found that it already exists. Is there any progress on this? Are any additional PRs needed?

@RainbowMango RainbowMango modified the milestones: v1.11, v1.12 Aug 28, 2024
@RainbowMango RainbowMango modified the milestones: v1.12, v1.13 Nov 28, 2024
@RainbowMango RainbowMango modified the milestones: v1.13, v1.14 Apr 28, 2025
@RainbowMango RainbowMango modified the milestones: v1.14, v1.15 Jul 8, 2025
@RainbowMango RainbowMango added the priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. label Jul 8, 2025
@RainbowMango RainbowMango modified the milestones: v1.15, v1.17 Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

spreadByLabel报错

6 participants