How rancher/cluster-api-provider-rke2 works
1. This repository is a Cluster API provider for RKE2, split into two independent provider surfaces: a Bootstrap Provider under bootstrap/ and a Control Plane Provider under controlplane/. Both are Kubernetes controllers that watch Cluster API custom resources and reconcile generated machine bootstrap data or control plane state.
2. The bootstrap side owns RKE2Config and RKE2ConfigTemplate APIs in bootstrap/api/v1beta1 and bootstrap/api/v1beta2. Its controller logic lives in bootstrap/internal/controllers, and its main job is to turn user-specified config into machine bootstrap payloads for joining RKE2 nodes.
3. The control plane side owns RKE2ControlPlane and RKE2ControlPlaneTemplate APIs in controlplane/api/v1beta1 and controlplane/api/v1beta2. Its controller logic in controlplane/internal/controllers manages the desired control plane size, lifecycle, remediation, status, and update behavior for RKE2 control plane machines.
4. A major architectural boundary is versioning. Both providers expose parallel v1beta1 and v1beta2 API packages with conversion code, deepcopy generation, and webhook validation/defaulting. The repo is structured to support cross-version compatibility while keeping provider-specific behavior isolated.
5. The bootstrap data path goes through helper packages in bootstrap/internal/cloudinit and bootstrap/internal/ignition. These generate the actual node initialization material, including cloud-init and ignition/butane output, before it is handed back to Cluster API for use by infrastructure machines.
6. The control plane data path is centered on pkg/rke2 plus pkg/capi helpers. pkg/rke2 contains RKE2-specific logic for control plane configuration, registries, workload cluster interaction, etcd handling, and machine filtering. pkg/capi contains reusable Cluster API integration code such as runtime client wrappers, extension config handling, patch utilities, in-place upgrade support, and registry/hooks helpers.
7. Several shared utility packages form the lower-level service layer for both providers: pkg/kubeconfig for connecting to clusters, pkg/secret for certificate handling, pkg/locking for coordinating control-plane initialization, pkg/proxy for transport/proxying, pkg/registration for node registration behavior, and pkg/etcd for etcd client and cluster state logic.
8. The control plane controller has additional internal submodules that map closely to reconciliation responsibilities: scale management, status computation, remediation, lifecycle hooks, and in-place update coordination. This separation suggests the controller orchestrates multiple policy decisions rather than being a single linear reconcile loop.
9. The repo is built and deployed as two controller images/managers, one for bootstrap and one for control plane. Each side has its own main.go, config/ tree, CRDs, RBAC, webhook manifests, and default Kustomize overlays under bootstrap/config and controlplane/config.
10. Webhooks and CRDs are first-class architecture components. Both providers define webhook validation/defaulting logic in the API packages, and the generated manifests in config/crd and config/webhook wire certificate injection and service endpoints for admission control.
11. The repository also contains a strong test and validation layer. Unit tests are spread through controller, API, and utility packages; envtest-based suites validate webhook and controller behavior; and test/e2e contains full integration scenarios like cluster class workflows, upgrades, pivoting, remediation, and external datastore support.
12. Supporting infrastructure includes documentation, examples, and image-building assets. docs/ hosts the user and developer book, examples/ provides cluster templates for multiple infrastructure providers, and image-builder/ plus bootstrap/ support producing RKE2 node images and bootstrap artifacts for air-gapped or specialized deployments.
13. Operationally, the controllers depend on Kubernetes APIs, Cluster API CRDs, admission webhooks, and generated manifests rather than external SaaS services. The main runtime boundary is the management cluster: controllers reconcile management-cluster custom resources and drive changes into workload cluster machines and control plane state.
14. For an architecture diagram, the core flow is: user submits Cluster API provider CRs and templates -> webhooks validate/default -> bootstrap and control plane controllers reconcile -> helper packages generate config, cloud-init/ignition, kubeconfigs, and RKE2-specific cluster operations -> Cluster API and infrastructure providers consume the results to create/update machine and cluster resources.
Main entry points: internal/controllers CP Ctrl · internal/controllers Bootstrap Ctrl · bootstrap/api Bootstrap API · controlplane/api Control Plane API
Components 19
Bootstrap Provider
RKE2 bootstrap API and controller surface
- Bootstrap API · RKE2Config and RKE2ConfigTemplate versions, conversions, defaults, and validation
bootstrap/api - Bootstrap Ctrl · Reconciles bootstrap configs into machine bootstrap data
bootstrap/internal/controllers - Node Init · Generates cloud-init, ignition, and butane output for node startup
bootstrap/internal/cloudinit - Ignition · Transforms bootstrap content into ignition-compatible material
bootstrap/internal/ignition - Bootstrap Manifests · Controller image, RBAC, CRDs, webhooks, and kustomize overlays
bootstrap/config
Control Plane Provider
RKE2 control plane API and controller surface
- Control Plane API · RKE2ControlPlane and RKE2ControlPlaneTemplate versions, conversions, defaults, and validation
controlplane/api - CP Ctrl · Orchestrates size, lifecycle, remediation, status, and update behavior
controlplane/internal/controllers - Scale · Maintains desired replicas and machine selection
controlplane/internal/controllers/scale.go - Status · Computes control plane readiness and rollout state
controlplane/internal/controllers/status.go - Remediation · Detects unhealthy machines and drives recovery actions
controlplane/internal/controllers/remediation.go - In-place Updates · Coordinates in-place machine updates and trigger logic
controlplane/internal/controllers/inplace.go - Lifecycle Hooks · Processes lifecycle hook state during reconciliation
controlplane/internal/controllers/lifecycle_hook.go - CP Manifests · Controller image, RBAC, CRDs, webhooks, and kustomize overlays
controlplane/config - CP Utilities · Reusable utilities for server-side apply, hashing, and patch intent
controlplane/internal/util
Shared Packages
Reusable domain and utility packages
- RKE2 Logic · RKE2 control plane config, registries, workload cluster, etcd, and machine filtering
pkg/rke2 - CAPI Helpers · Cluster API runtime client, extension config, patch, in-place, registry, and hooks support
pkg/capi - Shared Services · Kubeconfig, secret handling, locking, proxying, registration, and etcd support
pkg
Docs & Examples
Documentation, examples, and image assets
- Docs & Examples · Documentation, examples, and image-building assets for operators and developers
docs
Other components
- Runtime Surfaces · Two controller binaries plus generated manifests and admission wiring
bootstrap/main.go
Connections 23
- Bootstrap Manifests → Bootstrap API: serves · CRDs and webhooks are generated from bootstrap API types
- Bootstrap API → Bootstrap Ctrl: watched by · Validated bootstrap resources are reconciled into node bootstrap data
- Bootstrap Ctrl → Node Init: builds · Controller turns config into cloud-init or ignition payloads
- Node Init → Ignition: converts · Ignition helpers handle butane and ignition rendering
- Bootstrap Ctrl → Shared Services: uses · Bootstrap reconciliation relies on shared kubeconfig, secret, and etcd helpers
- Bootstrap Ctrl → CAPI Helpers: integrates · Bootstrap controller cooperates with Cluster API extension and patch helpers
- CP Manifests → Control Plane API: serves · CRDs and webhooks are generated from control plane API types
- Control Plane API → CP Ctrl: watched by · Validated control plane resources are reconciled into cluster state
- CP Ctrl → Scale: orchestrates · Scale logic manages desired replica count and machine selection
- CP Ctrl → Status: orchestrates · Status logic computes rollout and readiness conditions
- CP Ctrl → Remediation: orchestrates · Remediation logic handles unhealthy control plane machines
- CP Ctrl → In-place Updates: orchestrates · In-place update logic coordinates machine upgrades
- CP Ctrl → Lifecycle Hooks: orchestrates · Lifecycle hooks gate reconciliation transitions
- CP Ctrl → RKE2 Logic: uses · Core RKE2 domain logic powers control plane reconciliation
- CP Ctrl → CAPI Helpers: uses · Controller relies on Cluster API integration helpers
- RKE2 Logic → Shared Services: uses · RKE2 domain logic depends on cluster, secret, and etcd services
- RKE2 Logic → CAPI Helpers: uses · RKE2 logic composes CAPI runtime and patch utilities
- CAPI Helpers → Shared Services: uses · Cluster API helpers build on common transport and secret primitives
- Runtime Surfaces → Bootstrap Manifests: deploys · Bootstrap manager image, RBAC, and webhook wiring are packaged here
- Runtime Surfaces → CP Manifests: deploys · Control plane manager image, RBAC, and webhook wiring are packaged here
- Docs & Examples → Bootstrap API: documents · Documentation and examples describe bootstrap API usage
- Docs & Examples → Control Plane API: documents · Documentation and examples describe control plane API usage
- Bootstrap API → Control Plane API: version-paired · Parallel API versions share the repo-wide compatibility boundary