llm-wiki wiki · sources 2026-06-14

原文:raw/controller-tools-architecture-analysis.md · 仓库:https://github.com/kubernetes-sigs/controller-tools · 优先级 P0

一句话定位

controller-tools 提供 controller-gen,用 Go marker 生成 CRD、RBAC、webhook、deepcopy 等 Kubernetes API 工程资产。

核心架构图

┌────────────────────────────────────────────────────────────────────────────┐
│ Go API source                                                              │
│ Types, Kubebuilder markers, RBAC comments, webhook comments, and object    │
│ metadata.                                                                  │
└────────────────────────────────────────────────────────────────────────────┘
                                       │
                                       ▼
┌────────────────────────────────────────────────────────────────────────────┐
│ controller-gen                                                             │
│ Parses markers and type information to generate Kubernetes integration     │
│ artifacts.                                                                 │
└────────────────────────────────────────────────────────────────────────────┘
                                       │
                                       ▼
┌────────────────────────────────────────────────────────────────────────────┐
│ Generated artifacts                                                        │
│ CRD schemas, deepcopy code, RBAC manifests, webhook configs, and object    │
│ YAML.                                                                      │
└────────────────────────────────────────────────────────────────────────────┘
                                       │
                                       ▼
┌────────────────────────────────────────────────────────────────────────────┐
│ Consumers                                                                  │
│ Kubebuilder/operator build pipelines and cluster installation workflows.   │
└────────────────────────────────────────────────────────────────────────────┘

模块分层

层 / 模块 职责
Markers parser 读取 Go type/comment markers
CRD generator OpenAPI schema and validation
RBAC/webhook generators RBAC/webhook generators
object/deepcopy generation object/deepcopy generation

关键数据流

开发者在 API types 写 markers
        │
        ▼
controller-gen 解析 package
        │
        ▼
生成 CRD/RBAC/webhook/deepcopy
        │
        ▼
kubebuilder/kustomize 打包部署

设计决策与哲学