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

分离 client 中的真实和 fake 调用 k8s api,以便于 ut 不依赖于当前的 k8s 环境。 #914

Closed
wants to merge 2 commits into from

Conversation

yangshiqi
Copy link
Contributor

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
ut 不依赖于当前的 k8s 环境,更快速进行 ut。
k8s_client.go: 将当前散落的 k8s client 调用逻辑和日志记录,统一封装到 中,职责更单一。
factory.go: 将创建和管理逻辑统一,方便调用和切换fake/real。

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
后续将逐步替换当前依赖 client.GetClient()的调用点,最终全部统一后,再替换 client.go。
另外,当前util 中对k8s 接口还有组合调用的逻辑部分,感觉不合理。后续也考虑将独立抽离成领域类,不混淆在 util 工具类中。

Does this PR introduce a user-facing change?:
nope

Copy link
Contributor

hami-robott bot commented Mar 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: yangshiqi
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. 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

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 8.72483% with 136 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/util/client/k8s_client.go 3.29% 87 Missing and 1 partial ⚠️
pkg/util/client/factory.go 6.81% 40 Missing and 1 partial ⚠️
pkg/util/util.go 42.85% 4 Missing ⚠️
pkg/util/client/client.go 57.14% 2 Missing and 1 partial ⚠️
Flag Coverage Δ
unittests 62.36% <8.72%> (+15.38%) ⬆️

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

Files with missing lines Coverage Δ
pkg/util/client/client.go 46.42% <57.14%> (-7.74%) ⬇️
pkg/util/util.go 59.34% <42.85%> (+1.59%) ⬆️
pkg/util/client/factory.go 6.81% <6.81%> (ø)
pkg/util/client/k8s_client.go 3.29% <3.29%> (ø)

... and 10 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lengrongfu
Copy link
Member

Please compress the commit.

@yangshiqi
Copy link
Contributor Author

Please compress the commit.

done

@yangshiqi yangshiqi force-pushed the master branch 4 times, most recently from 73454a2 to ee132dd Compare March 6, 2025 03:48
factory.go: 将client的实例管理逻辑统一,方便调用和切换fake。兼容当前 KubeClient 全局变量的使用。
k8s_client.go: 统一实现 k8s 真实调用行为, 记录调用日志,去掉全局变量。

2.修改 util 和 util_test 中的相关调用, 统一 util_test 中测试用例的命名风格。
本次修改仅关注于 real 和 mock 分离,后续将完善更多 ut 测试,逐步替换当前 client 中的直接调用方式。

3.兼容当前新老调用 KubeClient 的用法,特别是 fake 替换全部变量时。

Signed-off-by: yangshiqi <[email protected]>
@yangshiqi yangshiqi closed this Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants