How kusionstack/controller-mesh works
Project Type and Purpose
• This is an open-source Kubernetes extension tool (“Controller Mesh”) that sits alongside existing controller/operator deployments to provide sharding, canary upgrades, circuit breaking, rate limiting, and fault injection features.
• It consists of two main binaries (ctrlmesh-manager and ctrlmesh-proxy), a set of CRDs, admission webhooks, and integration with the Kubernetes API server.
File Structure
• Top-level dirs:
• pkg/cmd/{manager,proxy,cert-generator} – entrypoints for the controller manager, proxy sidecar, and certificate generation tool.
• pkg/manager/controllers – Kubernetes controller logic for CRDs (ShardingConfig, CircuitBreaker, FaultInjection, ManagerState, etc.).
• pkg/proxy – sidecar proxy code handling HTTP/gRPC, caching, lease management, injection logic, and leader election.
• pkg/webhook – mutating/validating admission webhook implementations (namespace, pod, resources, shardingconfig).
• config – Kubernetes YAMLs (CRD definitions, RBAC, webhooks, manager Deployment, Service).
• artifacts, e2e – Dockerfiles, scripts for building images and end-to-end testing.
• Patterns:
• Controller-Manager pattern (built on controller-runtime)
• Sidecar proxy pattern (injected into operator Pods)
• Admission Webhook pattern
• CustomResource definitions for rule configuration
README for Additional Insights
• Key components: ctrlmesh-proxy (injected into each operator Pod to intercept requests), ctrlmesh-manager (central dispatcher of sharding & routing rules).
• Proxy uses iptables NAT or fake kubeconfig to intercept Apiserver traffic.
• ShardingConfig CRD holds all routing and limit rules.
• Manager applies labels and pushes config to proxies; proxies enforce flow control on HTTP/gRPC.