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

move CreateOrUpdateWork() and related functions to controllers/ctrlutl #6018

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

zach593
Copy link
Contributor

@zach593 zach593 commented Jan 5, 2025

What type of PR is this?
/kind cleanup

What this PR does / why we need it:

When I followed up on #6017, I ran into a circular reference issue, move this package to pkg/util could help solve it.

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 Jan 5, 2025
@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 5, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2025

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

Codecov Report

Attention: Patch coverage is 76.81159% with 16 lines in your changes missing coverage. Please review.

Project coverage is 48.36%. Comparing base (9f8da2c) to head (807153f).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
pkg/controllers/ctrlutil/work.go 88.13% 5 Missing and 2 partials ⚠️
pkg/controllers/binding/common.go 0.00% 3 Missing ⚠️
pkg/controllers/mcs/service_export_controller.go 0.00% 1 Missing ⚠️
...clusterservice/endpointslice_collect_controller.go 0.00% 1 Missing ⚠️
...lusterservice/endpointslice_dispatch_controller.go 0.00% 0 Missing and 1 partial ⚠️
.../controllers/multiclusterservice/mcs_controller.go 0.00% 0 Missing and 1 partial ⚠️
...controllers/namespace/namespace_sync_controller.go 0.00% 0 Missing and 1 partial ⚠️
...controllers/unifiedauth/unified_auth_controller.go 0.00% 0 Missing and 1 partial ⚠️

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

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6018   +/-   ##
=======================================
  Coverage   48.36%   48.36%           
=======================================
  Files         665      666    +1     
  Lines       54831    54831           
=======================================
+ Hits        26520    26521    +1     
+ Misses      26593    26592    -1     
  Partials     1718     1718           
Flag Coverage Δ
unittests 48.36% <76.81%> (+<0.01%) ⬆️

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.

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.

/assign

@RainbowMango
Copy link
Member

I guess the circular dependency issue is due to the package pkg/util/helper importing its upper-level package pkg/util, which is not right.
Another option would be moving these consts to pkg/util/names, can you help to confirm if it works?

@zach593
Copy link
Contributor Author

zach593 commented Jan 6, 2025

Thank you for your attention @RainbowMango , I'm sorry that I didn't provide the detail about the import chain.

What I met is I want to call prune.RemoveIrrelevantFields() in helper.CreateOrUpdateWork() , but prune.removeJobIrrelevantField() calls helper.ConvertToTypedObject(). so that causes the import cycle.

OTOH, the pkg/helper package contains a lot of code that is very close to the business logic layer. Therefore, even if pkg/helper package's direct dependency on pkg/helper/util is removed, other packages referenced by pkg/helper will still depend on pkg/helper/util . So, removing the direct dependency of the pkg/helper package on pkg/helper/util should have little significance.

@RainbowMango
Copy link
Member

What I met is I want to call prune.RemoveIrrelevantFields() in helper.CreateOrUpdateWork() ,
OTOH, the pkg/helper package contains a lot of code that is very close to the business logic layer.

That's the key point. Generally speaking, both pkg/util and pkg/util/helper provide fundamental functions which should be consumed by the business logic layer, and can not refer to business layer.

The function CreateOrUpdateWork you mentioned it's kind of business logic, also part of controllers. Do you think it should be moved out from pkg/util/helpers?

@zach593
Copy link
Contributor Author

zach593 commented Jan 8, 2025

The function CreateOrUpdateWork you mentioned it's kind of business logic, also part of controllers. Do you think it should be moved out from pkg/util/helpers?

I aggre with you, I'll try it and update this PR later.

@zach593
Copy link
Contributor Author

zach593 commented Jan 9, 2025

replace title "move pkg/util/helper/unstructured.go to pkg/util" with "move CreateOrUpdateWork() and related functions to controllers/common"

Looks like it could work, although there is still a lot of business logic in util/helper, but I just moved the necessary parts according to my needs. @RainbowMango

@zach593 zach593 changed the title move pkg/util/helper/unstructured.go to pkg/util move CreateOrUpdateWork() and related functions to controllers/common Jan 9, 2025
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.

Looks great!

How about naming this new package with the following options?

  • ctrlutil
  • ctrlhelper
  • ctrlcommon

It's no big deal, just feel the common seems to be used everywhere, and I don't like the import aliases.

I prefer the first one, and then the second.

@RainbowMango
Copy link
Member

Looks like it could work, although there is still a lot of business logic in util/helper, but I just moved the necessary parts according to my needs. @RainbowMango

Thanks for the reminder, I will be more careful when people try to put more things to util/helper and move things out when they become a blocker.

@zach593
Copy link
Contributor Author

zach593 commented Jan 10, 2025

sure, updated the pkg name.

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.

/lgtm
/approve

/hold
until the ci gets green
Please feel free to unhold this.

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2025
@karmada-bot karmada-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 10, 2025
@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 10, 2025
@RainbowMango RainbowMango changed the title move CreateOrUpdateWork() and related functions to controllers/common move CreateOrUpdateWork() and related functions to controllers/ctrlutl Jan 10, 2025
@RainbowMango
Copy link
Member

/hold cancel

@karmada-bot karmada-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 10, 2025
@RainbowMango RainbowMango added this to the v1.13 milestone Jan 10, 2025
@karmada-bot karmada-bot merged commit 253dc79 into karmada-io:master Jan 10, 2025
21 checks passed
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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants