Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add implicit priority for OP and COP #2609

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

chaunceyjiang
Copy link
Member

@chaunceyjiang chaunceyjiang commented Oct 3, 2022

Signed-off-by: chaunceyjiang chaunceyjiang@gmail.com

What type of PR is this?
/kind feature

What this PR does / why we need it:

add implicit priority for OP and COP

Which issue(s) this PR fixes:

like #2267

Special notes for your reviewer:

  1. get the list of PP(or OP) that matches the workload.
  2. sort the list by priority (I assume the list won't be so long, so performance won't be a concern here.)
  3. for PP, we just pick the first item from the list, for OP, we apply the whole list by order.

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Now the `OverridePolicy` and `ClusterOverridePolicy` will be applied by implicit priority order. The one with lower priority will be applied before the one with higher priority.

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 3, 2022
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 3, 2022
@RainbowMango
Copy link
Member

/assign

@RainbowMango RainbowMango added this to the v1.4 milestone Oct 8, 2022
pkg/util/selector.go Outdated Show resolved Hide resolved
Copy link
Member

@Garrybest Garrybest left a comment

Choose a reason for hiding this comment

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

Well, this PR can really work but also a little complicated. I suppose we actually don't need to sort this slice, the only thing we need is to find the most appropriate one, right?

IMO, sort function could be transformed to pick up a most appropriate one. This function receives a []util.GeneralPolicy as an input and returns a int index as output. This index indicates the most appropriate one, or -1 if mismatches.

How do you think?

@RainbowMango
Copy link
Member

IMO, sort function could be transformed to pick up a most appropriate one. This function receives a []util.GeneralPolicy as an input and returns a int index as output. This index indicates the most appropriate one, or -1 if mismatches.

+1
I have a similar idea but haven't a clear thought yet.

By the way, I think combining PropagationPolicy and OverridePolicy might not be a good idea, my concern is they are different APIs, and the behavior is not exactly the same(or can't guarantee).

@chaunceyjiang
Copy link
Member Author

sort function could be transformed to pick up a most appropriate one. This function receives a []util.GeneralPolicy as an input and returns a int index as output. This index indicates the most appropriate one, or -1 if mismatches.

🤔
OP (COP) may have several appropriate items

@chaunceyjiang
Copy link
Member Author

I think combining PropagationPolicy and OverridePolicy might not be a good idea, my concern is they are different APIs, and the behavior is not exactly the same(or can't guarantee).

+1

@Garrybest
Copy link
Member

Seems like it's not appropriate to combine OP and PP. IIRC, all matched OP should be applied while only one pp will be selected. It's totally different.

@chaunceyjiang
Copy link
Member Author

chaunceyjiang commented Oct 10, 2022

Seems like it's not appropriate to combine OP and PP. IIRC, all matched OP should be applied while only one pp will be selected. It's totally different.

yes, But the SortPolicy() function in this pr only focuses on sorting, not whether pp(op) is applied

@Garrybest
Copy link
Member

Garrybest commented Oct 10, 2022

Got it. However, I thought we don't actually need a sort function indeed, against PP we pick up the most appropriate one, against OP we pick up all the appropriate ones. The complexity could be optimized from O(NlogN) to O(N).

@chaunceyjiang
Copy link
Member Author

OP we pick up all the appropriate ones. The complexity could be optimized from O(NlogN) to O(N).

🤔
I don't think so.

There are two OP sample-1 and sample-2.

Apply sample-1 first, then sample-2 and sample-2 first, then sample-1.

The final result is different

apiVersion: policy.karmada.io/v1alpha1
kind: OverridePolicy
metadata:
  name: sample-1
spec: 
  resourceSelectors: 
  - apiVersion: webapp.my.domain/v1 
    kind: Guestbook
  overrideRules: 
  - targetCluster: 
      clusterNames:
      - member1
    overriders:
      plaintext:
      - path: /spec/size
        operator: replace
        value: 4
apiVersion: policy.karmada.io/v1alpha1
kind: OverridePolicy
metadata:
  name: sample-2
spec: 
  resourceSelectors: 
  - apiVersion: webapp.my.domain/v1 
    kind: Guestbook
  overrideRules: 
  - targetCluster: 
      clusterNames:
      - member1
    overriders:
      plaintext:
      - path: /spec/size
        operator: add
        value: 4

@Garrybest
Copy link
Member

Indeed. This is a sort case.

@karmada-bot karmada-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 15, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Merging #2609 (200a587) into master (b0eb90b) will increase coverage by 0.09%.
The diff coverage is 69.23%.

@@            Coverage Diff             @@
##           master    #2609      +/-   ##
==========================================
+ Coverage   37.61%   37.71%   +0.09%     
==========================================
  Files         189      200      +11     
  Lines       17657    18445     +788     
==========================================
+ Hits         6642     6956     +314     
- Misses      10612    11082     +470     
- Partials      403      407       +4     
Flag Coverage Δ
unittests 37.71% <69.23%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/util/overridemanager/overridemanager.go 23.39% <69.23%> (+1.75%) ⬆️
pkg/util/helper/binding.go 66.50% <0.00%> (-15.60%) ⬇️
pkg/registry/cluster/storage/proxy.go 59.09% <0.00%> (-9.34%) ⬇️
...armadactl/cmdinit/karmada/webhook_configuration.go 83.25% <0.00%> (-5.19%) ⬇️
pkg/util/worker.go 66.66% <0.00%> (-4.77%) ⬇️
pkg/util/serviceaccount.go 87.71% <0.00%> (-2.56%) ⬇️
pkg/search/proxy/store/util.go 93.36% <0.00%> (-0.21%) ⬇️
pkg/descheduler/descheduler.go 22.88% <0.00%> (-0.12%) ⬇️
pkg/util/rbac.go 100.00% <0.00%> (ø)
pkg/util/namespace.go 100.00% <0.00%> (ø)
... and 46 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@chaunceyjiang
Copy link
Member Author

@Garrybest What do you think?

@chaunceyjiang chaunceyjiang requested review from Garrybest and removed request for XiShanYongYe-Chang November 16, 2022 02:01
@Garrybest
Copy link
Member

Generally LGTM, except this nit. #2609 (comment)

@Garrybest
Copy link
Member

/lgtm

@RainbowMango
Copy link
Member

@chaunceyjiang

add implicit priority for OP and COP

I'm asking myself, what benefits can we get from it? What's the possible use case? Can you remind me?

@chaunceyjiang
Copy link
Member Author

chaunceyjiang commented Nov 28, 2022

I'm asking myself, what benefits can we get from it? What's the possible use case? Can you remind me?

I think it's reasonable, like applying the user's OP first(MatchName), then applying the administrator's OP(MatchAll or MatchLabelSelector).
In that case, we might need to build a sorted OP list.

@RainbowMango

@RainbowMango
Copy link
Member

That's a reasonable case. Thanks.

@RainbowMango
Copy link
Member

I'll take a look it tomorrow and try my best to add this to release 1.4.

@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 28, 2022
@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 28, 2022
pkg/util/selector.go Outdated Show resolved Hide resolved
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
@jwcesign
Copy link
Member

jwcesign commented Dec 5, 2022

Generally, it looks good to me, cc @RainbowMango to take a look

@chaunceyjiang
Copy link
Member Author

chaunceyjiang commented Dec 5, 2022

@RainbowMango @XiShanYongYe-Chang What do you think?

@RainbowMango
Copy link
Member

Generally looks good to me.
I just updated the release note:

karmada-controller-manager: Now the OverridePolicy and ClusterOverridePolicy will be applied by implicit priority order. The one with lower priority will be applied before the one with higher priority.

Please help to confirm.

@chaunceyjiang
Copy link
Member Author

karmada-controller-manager: Now the OverridePolicy and ClusterOverridePolicy will be applied by implicit priority order. The one with lower priority will be applied before the one with higher priority.

+1

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve

Thanks for the quick response.

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

The pull request process is described here

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2022
@RainbowMango
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 6, 2022
@karmada-bot karmada-bot merged commit 9784ed3 into karmada-io:master Dec 6, 2022
@chaunceyjiang chaunceyjiang deleted the implicit branch December 19, 2022 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants