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

fix: Validate replicaSchedulingType and replicaDivisionPreference #3014

Merged

Conversation

chaunceyjiang
Copy link
Member

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

What type of PR is this?
/kind bug

What this PR does / why we need it:
Validate replicaSchedulingType and replicaDivisionPreference
Which issue(s) this PR fixes:
Fixes #3013

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

`karmada-webhook`: Validate replicaSchedulingType and replicaDivisionPreference.

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 31, 2022
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 31, 2022
@chaunceyjiang
Copy link
Member Author

chaunceyjiang commented Dec 31, 2022

apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: nginx-propagation
spec:
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: nginx
  placement:
    clusterAffinity:
      clusterNames:
        - member1
        - member2
    replicaScheduling:
      replicaDivisionPreference: Weighted

image

apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: nginx-propagation
spec:
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: nginx
  placement:
    clusterAffinity:
      clusterNames:
        - member1
        - member2
    replicaScheduling:
      replicaSchedulingType: Divided

image

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2022

Codecov Report

Merging #3014 (7a3207c) into master (617409f) will increase coverage by 0.12%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #3014      +/-   ##
==========================================
+ Coverage   38.61%   38.74%   +0.12%     
==========================================
  Files         206      206              
  Lines       18808    18919     +111     
==========================================
+ Hits         7263     7330      +67     
- Misses      11115    11155      +40     
- Partials      430      434       +4     
Flag Coverage Δ
unittests 38.74% <0.00%> (+0.12%) ⬆️

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

Impacted Files Coverage Δ
pkg/util/helper/policy.go 81.60% <0.00%> (-4.98%) ⬇️
pkg/search/proxy/controller.go 83.97% <0.00%> (-1.65%) ⬇️
.../resourceinterpreter/defaultinterpreter/healthy.go 65.76% <0.00%> (-1.23%) ⬇️
...einterpreter/defaultinterpreter/aggregatestatus.go 72.09% <0.00%> (-0.85%) ⬇️
pkg/scheduler/core/division_algorithm.go 85.71% <0.00%> (-0.38%) ⬇️
pkg/scheduler/scheduler.go 18.07% <0.00%> (-0.23%) ⬇️
pkg/util/names/names.go 96.38% <0.00%> (-0.17%) ⬇️
pkg/util/namespace.go 100.00% <0.00%> (ø)
pkg/detector/detector.go 0.00% <0.00%> (ø)
pkg/scheduler/core/assignment.go 79.76% <0.00%> (ø)
... and 10 more

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

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.

BTW, policyv1 really needs to be promoted and collated because some fields are not decent enough🤔.

pkg/util/validation/validation.go Outdated Show resolved Hide resolved
@RainbowMango
Copy link
Member

/assign

@karmada-bot karmada-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 6, 2023
@@ -255,6 +255,7 @@ type ReplicaSchedulingStrategy struct {
// "Divided" divides replicas into parts according to number of valid candidate member
// clusters, and exact replicas for each cluster are determined by ReplicaDivisionPreference.
// +kubebuilder:validation:Enum=Duplicated;Divided
// +kubebuilder:default=Divided
Copy link
Member

Choose a reason for hiding this comment

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

Emmm🤔, I think this solution does not have an effect on #3013 because the empty field is ReplicaDivisionPreference.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, It looks good for this instruction.

But it can't fix #3013.

For the ReplicaDivisionPreference, maybe we can't just set a default value by kubebuilder instruction, because it has a precondition that is when replicaSchedulingType is Divided.

How about deal replicaSchedulingType with the mutating webhook?

Copy link
Member

@Garrybest Garrybest Jan 9, 2023

Choose a reason for hiding this comment

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

+1. Meanwhile, I suggest we gather our own default function of all API objects in zz_generated.defaults.go which generated by code-generator and fill up with the default value in mutating webhook.

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 interested in the defaults thing, is there an example?

Copy link
Member

@Garrybest Garrybest Jan 9, 2023

Choose a reason for hiding this comment

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

Take corev1.Pod as an example. AFAIK, the code-generator helps us generate zz_generated.defaults.go and we only need to implement the customized default function in defaults.go. Once the scheme is added, we could use these codes to dump all default values into an object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Right, I have used this tool before.

Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
@karmada-bot karmada-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 9, 2023
@chaunceyjiang
Copy link
Member Author

chaunceyjiang commented Jan 9, 2023

yaml

apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: nginx-propagation
spec:
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: nginx
  placement:
    clusterAffinity:
      clusterNames:
        - member1
        - member2
    replicaScheduling:
      replicaSchedulingType: Divided

image

@RainbowMango RainbowMango added this to the v1.5 milestone Jan 9, 2023
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

Please @Garrybest take a look?

@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 Jan 9, 2023
@chaunceyjiang
Copy link
Member Author

apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: nginx-propagation3
spec:
  resourceSelectors:
    - apiVersion: apps/v1
      kind: Deployment
      name: nginx
  placement:
    clusterAffinity:
      clusterNames:
        - member1
        - member2
    replicaScheduling:
      weightPreference:
        staticWeightList:
          - targetCluster:
              clusterNames:
                - member1
            weight: 1
          - targetCluster:
              clusterNames:
                - member2
            weight: 1

image

@Garrybest
Copy link
Member

/lgtm

Thanks😄.

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2023
@karmada-bot karmada-bot merged commit 0330535 into karmada-io:master Jan 9, 2023
@chaunceyjiang chaunceyjiang deleted the ValidateReplicaScheduling branch January 9, 2023 11:26
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/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid propagation policy creates successfully but does not schedule deployments
6 participants