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

refactor ensure work #5660

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

XiShanYongYe-Chang
Copy link
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

The ensureWork function has some load, and its complexity will continue to increase during ongoing iterations. Therefore, some refactoring has been done on this function.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Oct 10, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from xishanyongye-chang. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 10, 2024
Signed-off-by: changzhen <changzhen5@huawei.com>
@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 10, 2024
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 34.34343% with 65 lines in your changes missing coverage. Please review.

Project coverage is 35.86%. Comparing base (5692e28) to head (8413ed6).

Files with missing lines Patch % Lines
pkg/controllers/binding/common.go 35.95% 55 Missing and 2 partials ⚠️
pkg/controllers/binding/binding_controller.go 20.00% 4 Missing ⚠️
...ers/binding/cluster_resource_binding_controller.go 20.00% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5660      +/-   ##
==========================================
- Coverage   35.91%   35.86%   -0.05%     
==========================================
  Files         648      648              
  Lines       45079    45095      +16     
==========================================
- Hits        16189    16174      -15     
- Misses      27645    27675      +30     
- Partials     1245     1246       +1     
Flag Coverage Δ
unittests 35.86% <34.34%> (-0.05%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@XiShanYongYe-Chang
Copy link
Member Author

/cc @RainbowMango

@RainbowMango
Copy link
Member

OK. will do.

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.

I tried to understand the ideal, please correct me if not the case.
The benefits include:

  • Reduced the number of parameters passed in ensureWork.
  • Split the ensureWork into two functions.

Comment on lines +40 to +44
type workSyncer struct {
client client.Client
interpreter resourceinterpreter.ResourceInterpreter
overrider overridemanager.OverrideManager
}
Copy link
Member

Choose a reason for hiding this comment

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

The workSyncer holds some immutable parameters, mainly used to reduce the number of parameters passed to ensureWork(). Is this the idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's like this.

}
}
// ensureWork ensure Work to be created or updated in the target cluster.
func (s *workSyncer) ensureWork(ctx context.Context, workload *unstructured.Unstructured, binding metav1.Object, targetCluster workv1alpha2.TargetCluster, config extraConfig) error {
Copy link
Member

Choose a reason for hiding this comment

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

The ensureWork is dedicated to syncing a single work, which is split from the original ensureWork.

Copy link
Member Author

@XiShanYongYe-Chang XiShanYongYe-Chang Oct 11, 2024

Choose a reason for hiding this comment

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

Yes, more dependencies on single work generation will be extended in extraConfig in the future.

switch scope {
case apiextensionsv1.NamespaceScoped:
// workSyncer is design for syncing work objects as expected.
type workSyncer struct {
Copy link
Member

Choose a reason for hiding this comment

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

I believe it would be more appropriate to have this workSyncer placed in a separate new Go file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I plan to change the common.go file name to worksyncer.go when the review is almost complete. This makes it easier to see which parts have been modified during review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants