Skip to content

Route #263

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

Merged
merged 27 commits into from
Jul 20, 2025
Merged

Route #263

merged 27 commits into from
Jul 20, 2025

Conversation

weibaohui
Copy link
Owner

No description provided.

weibaohui added 27 commits July 20, 2025 10:00
将分散的污点路由处理逻辑集中到 TaintController 中
移除 AllTaintList 函数并使用新的 List 方法替代
统一污点操作的路由注册方式
将原有的节点控制器功能拆分为多个子控制器(ActionController、ResourceController、MetadataController、ShellController)
并分别注册路由,提高代码可维护性和模块化程度
将OptionList、CreateResourceQuota和CreateLimitRange方法重构为Controller结构体的方法
统一通过RegisterRoutes注册路由,提高代码组织性
将原有的直接路由注册改为通过RegisterActionRoutes方法统一注册
将分散的路由注册逻辑集中到 ActionController 结构体中
通过 RegisterActionRoutes 方法统一注册所有部署相关路由
将main.go中分散的pod关联路由注册逻辑提取到独立的RegisterPodLinkRoutes方法中
统一管理所有pod关联路由,提高代码可维护性
将分散的容忍度路由处理函数重构为集中的 TolerationController 结构体
通过 RegisterTolerationRoutes 方法统一注册路由,提高代码可维护性
将分散的Pod亲和性路由注册逻辑重构为统一的RegisterAffinityRoutes方法
新增AffinityController结构体集中管理相关方法
将节点亲和性、Pod亲和性和Pod反亲和性的路由注册逻辑重构为控制器模式
统一路由注册方式,提高代码可维护性和一致性
将直接注册的路由函数改为通过控制器结构体方法注册
移除已废弃的CrdTree相关代码
将分散的容器相关路由集中注册到RegisterContainerRoutes
将容器相关函数重构为ContainerController的方法
提取getResourcePaths函数到单独文件
将原有的标签更新功能合并到新的metadata.go文件中,并添加注解的过滤逻辑
新增不可变键列表,防止修改系统关键注解
添加注解列表功能,返回过滤后的注解数据
将原有的直接路由处理函数重构为MetadataController结构体方法
通过RegisterMetadataRoutes统一注册元数据相关路由
提高代码组织性和可维护性
将动态路由的注册逻辑从直接注册改为通过ActionController统一管理
所有相关方法重构为ActionController的成员方法,提高代码组织性
将分散的路由注册集中到 RegisterRoutes 方法中
将原有的直接路由注册改为通过控制器结构体注册路由
统一管理路由相关方法,提高代码组织性和可维护性
将网关类的路由注册从直接调用改为通过控制器方法注册
将ingressclass的路由注册逻辑从main.go移出并重构为控制器模式
统一路由注册方式,提高代码可维护性
将storage_class的路由注册从main.go移至控制器内部,使用控制器结构体封装路由方法
将分散的路由注册集中到RegisterRoutes方法中,提高代码可维护性
将configmap的路由注册逻辑集中到RegisterRoutes方法中
引入Controller结构体来组织相关方法,提高代码可维护性
将分散的路由注册集中到RegisterRoutes方法中
统一控制器方法接收者为Controller结构体
将分散的路由注册代码重构为统一的RegisterRoutes方法
所有控制器方法改为Controller的成员方法
将分散的路由定义重构为通过RegisterRoutes方法集中注册
将独立函数重构为Controller结构体的方法
Copy link
Contributor

coderabbitai bot commented Jul 20, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • 重构

    • 所有 Kubernetes 相关 API 路由注册方式统一,采用分组注册函数,提升结构清晰度和可维护性。
    • 控制器方法全面结构化,相关接口归入各自控制器,路由注册集中管理。
    • 多数原有接口无功能变更,仅组织方式和调用结构优化。
    • 节点、动态资源、容器、亲和性、污点、元数据等接口分组更明确,便于扩展和维护。
  • 其他变更

    • 个别已废弃的接口被移除,接口命名更简洁统一,部分变量命名更直观。

Walkthrough

本次变更对主路由注册逻辑进行了大规模重构,将各类 Kubernetes 资源相关的 HTTP 路由注册,从原本在 main.go 中的逐条声明,统一改为通过各自控制器的注册函数集中注册。同时,几乎所有控制器的 handler 函数都被封装进结构体方法,并增加了对应的注册方法,进一步实现了路由注册和控制器逻辑的模块化与归类。部分遗留的独立函数被移除或合并进新的结构体方法。

Changes

文件/分组 变更摘要
main.go 路由注册重构,所有资源相关路由统一调用各控制器的注册函数
pkg/controller/cluster_status/status.go handler 封装为结构体方法,新增 RegisterClusterRoutes 注册函数
pkg/controller/cm/cm.go
pkg/controller/cronjob/cronjob.go
pkg/controller/deploy/deploy.go
pkg/controller/doc/doc.go
pkg/controller/ds/ds.go
pkg/controller/rs/rs.go
pkg/controller/sts/sts.go
pkg/controller/k8sgpt/k8sgpt.go
pkg/controller/storageclass/storage_class.go
pkg/controller/ingressclass/ingress_class.go
pkg/controller/gatewayapi/gateway_class.go
pkg/controller/svc/svc.go
handler 全面封装为结构体方法,增加 RegisterRoutes/RegisterActionRoutes 注册函数
pkg/controller/dynamic/dynamic.go
pkg/controller/dynamic/crd_option.go
pkg/controller/dynamic/crd_status.go
pkg/controller/dynamic/container.go
pkg/controller/dynamic/metadata.go
pkg/controller/dynamic/node_affinity.go
pkg/controller/dynamic/pod_affinity.go
pkg/controller/dynamic/pod_anti_affinity.go
pkg/controller/dynamic/pod_link.go
pkg/controller/dynamic/toleration.go
dynamic 相关 handler 封装为结构体方法,统一注册,部分废弃函数删除,metadata/label 相关合并
pkg/controller/node/node.go
pkg/controller/node/taint.go
pkg/controller/node/resource.go
pkg/controller/node/xterm.go
pkg/controller/node/metadata.go
node 相关 handler 拆分为 ActionController、TaintController、ResourceController、ShellController、MetadataController,分别注册路由,原有部分 handler 移除或合并
pkg/controller/ns/ns.go
pkg/controller/ns/resource_quota.go
pkg/controller/ns/limit_range.go
ns 相关 handler 封装为 Controller 方法,集中注册路由
pkg/controller/dynamic/label.go label handler 删除,功能合并至 metadata controller
pkg/controller/dynamic/comm.go getResourcePaths 函数迁移,现仅保留在 comm.go
pkg/controller/helm/helm_repo.go RepoController 方法重命名,路由注册同步调整

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Router
    participant Controller
    participant Service

    Client->>Router: HTTP 请求 /k8s/cluster/:cluster/...
    Router->>Controller: 路由分发到对应控制器方法
    Controller->>Service: 调用业务逻辑
    Service-->>Controller: 返回处理结果
    Controller-->>Router: 返回 JSON 响应
    Router-->>Client: 响应结果
Loading

Possibly related PRs

  • weibaohui/k8m#262: 也对 main.go 路由注册做了类似分组重构,和本 PR 直接相关。
  • weibaohui/k8m#104: 对控制器 handler 增加了集群选择错误处理,与本 PR handler 分组和结构体化相关。
  • weibaohui/k8m#235: 涉及 Helm controller 结构调整,与本 PR 对 Helm 路由注册及 controller 结构化相关。

Poem

(=^·ω·^=)ゝ
路由成群不再散,
控制器兔子来分拣。
handler 归类皆有主,
注册一行清如泉。
结构重塑如新园,
K8s 路径更好看!
🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0ca56e and b014bb9.

📒 Files selected for processing (35)
  • main.go (2 hunks)
  • pkg/controller/cluster_status/status.go (1 hunks)
  • pkg/controller/cm/cm.go (5 hunks)
  • pkg/controller/cronjob/cronjob.go (4 hunks)
  • pkg/controller/deploy/deploy.go (16 hunks)
  • pkg/controller/doc/doc.go (2 hunks)
  • pkg/controller/ds/ds.go (6 hunks)
  • pkg/controller/dynamic/comm.go (1 hunks)
  • pkg/controller/dynamic/container.go (25 hunks)
  • pkg/controller/dynamic/crd_option.go (2 hunks)
  • pkg/controller/dynamic/crd_status.go (1 hunks)
  • pkg/controller/dynamic/dynamic.go (15 hunks)
  • pkg/controller/dynamic/label.go (0 hunks)
  • pkg/controller/dynamic/metadata.go (3 hunks)
  • pkg/controller/dynamic/node_affinity.go (2 hunks)
  • pkg/controller/dynamic/pod_affinity.go (3 hunks)
  • pkg/controller/dynamic/pod_anti_affinity.go (2 hunks)
  • pkg/controller/dynamic/pod_link.go (12 hunks)
  • pkg/controller/dynamic/toleration.go (4 hunks)
  • pkg/controller/gatewayapi/gateway_class.go (1 hunks)
  • pkg/controller/helm/helm_repo.go (3 hunks)
  • pkg/controller/ingressclass/ingress_class.go (2 hunks)
  • pkg/controller/k8sgpt/k8sgpt.go (4 hunks)
  • pkg/controller/node/metadata.go (1 hunks)
  • pkg/controller/node/node.go (6 hunks)
  • pkg/controller/node/resource.go (1 hunks)
  • pkg/controller/node/taint.go (2 hunks)
  • pkg/controller/node/xterm.go (2 hunks)
  • pkg/controller/ns/limit_range.go (1 hunks)
  • pkg/controller/ns/ns.go (1 hunks)
  • pkg/controller/ns/resource_quota.go (1 hunks)
  • pkg/controller/rs/rs.go (7 hunks)
  • pkg/controller/storageclass/storage_class.go (2 hunks)
  • pkg/controller/sts/sts.go (8 hunks)
  • pkg/controller/svc/svc.go (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch route

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@weibaohui weibaohui merged commit 5c6c791 into main Jul 20, 2025
4 of 5 checks passed
@weibaohui weibaohui deleted the route branch July 20, 2025 03:39
@coderabbitai coderabbitai bot mentioned this pull request Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant