How rancher/system-agent works
Project Type & Purpose
• This is a Go-based system daemon (“rancher-system-agent”) that runs on a host OS.
• It watches for “plans” (locally on disk or remotely via the Kubernetes API), then executes those plans to configure or upgrade the node.
• It integrates tightly with Rancher/CAPI clusters, but remains a standalone agent.
Main Components
A. Configuration Loader (pkg/config)
• Reads CLI flags, environment variables, config files (Unix/Windows variants).
B. Plan Watchers
• LocalPlanWatcher (pkg/localplan/watcher.go) watches a filesystem directory for plan files.
• K8sPlanWatcher (pkg/k8splan/watcher.go) watches Kubernetes Custom Resources via the API server.
C. Event Dispatcher / Controller Core
• Receives plan events from watchers, deduplicates, and schedules them.
D. Applyinator (pkg/applyinator)
• Core engine that applies plans—file operations, script execution, state reconciliation (with OS-specific helpers).
E. Image Utilities (pkg/image)
• Pulls, unpacks, or loads container images referenced by plans.
F. Prober (pkg/prober)
• Executes health-check probes defined in plans to verify success.
G. Version Info (pkg/version)
• Embeds build metadata.
H. Packaging & Delivery
• Dockerfiles (package/), cross-compile scripts, and install.sh for distribution.
External Systems & Dependencies
• Kubernetes API Server (for remote plans)
• Container Registry (for pulling images)
• Local File System (for local plans and storing unpacked artifacts)
• OS (Unix/Windows) for applying changes
Architectural Patterns
• Event-Driven: Watchers emit plan events to a central dispatcher.
• Plugin-style: OS-specific code lives side by side (file_unix.go / file_windows.go).
• Separation of Concerns: Watching vs. planning vs. executing vs. probing.