How gardener/machine-controller-manager works
Main Components
• Controllers: There are multiple controllers, each with a distinct purpose:
• MachineDeployment Controller: Reconciles MachineDeployment objects and oversees the creation and update of MachineSet objects.
• MachineSet Controller: Ensures that the desired number of Machine objects exist.
• Machine Controller: Manages the lifecycle of individual Machine objects.
• Safety Controller: Monitors safety thresholds and freezes/unfreezes operations if cloud provider or replica inconsistencies occur.
• Custom Resource Definitions (CRDs): Represent the objects that the controllers work with. Essential CRDs include:
• MachineClass (templates for cloud provider specifics)
• Machine (the virtual machine/VM instances)
• MachineSet (grouping and scaling of Machines)
• MachineDeployment (declarative updates and roll-out of MachineSets and Machines)
• Kubernetes Resources: The system inherently interacts with the Kubernetes control plane (e.g., API Server, etcd) and secrets (for cloud credentials and configurations).
Understand the File Structure and Its Architectural Impact
• The top-level directories – “cmd”, “pkg”, “kubernetes”, “docs”, “hack” – clearly indicate separation between binary entry points (cmd), implementation libraries and core logic (pkg), Kubernetes manifests (kubernetes), documentation (docs) and supporting scripts (hack).
• In the “pkg” directory, you have subdirectories for “apis”, “controller”, “client”, “util”, and “metrics”. This maps directly to the various concerns of the system:
• “pkg/apis” contains API definitions and CRDs.
• “pkg/controller” houses the implementation of the controllers.
• “pkg/client” and “pkg/util” include helper functions, shared informers, workqueues, leader election logic, and rate limiting.
• The “kubernetes” folder includes manifests (CRD definitions, deployment YAMLs) that show how the machine-controller-manager is deployed and interacts with Kubernetes.
• The “.ci” directory includes pipelines and sample objects for different cloud providers (AWS, Azure, GCP, Openstack), highlighting that cloud-specific configurations are abstracted via MachineClass YAMLs and similar templates.
Relationships and Data Flow
• Machine-controller-manager as a collection of components (each controller) that watches over and reconciles its respective CRD:
• A hierarchical relationship between:
• MachineDeployment Controller (grandparent) → manages → MachineSet Controller (parent) → manages → Machine Controller (child)
• Safety Controller as a side component that takes input from overall machine state (Machine, MachineSet, MachineDeployment) and can “freeze” actions on these objects if defined thresholds are breached.
• External cloud providers (AWS, Azure, GCP, etc.) as separate entities that the controllers interact with indirectly through the MachineClass templates and cloud credentials (stored in Secrets).
• Incorporate integration with Prometheus for metrics reporting and leader election features that help scale the controllers for high-availability.