How harvester/harvester works
1. What this repo is
Harvester is the core control-plane repository for a Kubernetes-based HCI platform. It is not just an app server; it bundles API types, controllers, admission webhooks, upgrade tooling, packaging, and deployment manifests for the Harvester cluster itself.
2. Main runtime entry points
There are two primary binaries in this tree: cmd/webhook for the admission webhook service, and cmd/upgradehelper for upgrade-time helper operations. The top-level main.go and pkg/cmd/app.go are the main application entry points for the core Harvester services.
3. Custom API layer
Harvester defines its own CRDs under pkg/apis/harvesterhci.io/v1beta1, with generated clientsets and controllers alongside them. These resources model platform concepts such as VMs, images, backups, templates, settings, upgrades, support bundles, resource quotas, and remote backups.
4. Control-plane reconciliation
The bulk of the system behavior lives in pkg/controller/master and pkg/controller/global. These controllers reconcile Harvester CRs into Kubernetes and dependent-system state, handling things like VM lifecycle, node maintenance, upgrades, image management, backups, storage classes, and cluster settings.
5. Virtualization subsystem
VM operations flow through pkg/controller/master/virtualmachine, pkg/controller/master/migration, and related helpers in pkg/builder and pkg/util/virtualmachine*. This layer translates Harvester VM intent into KubeVirt resources and manages VM instance behavior, migration, and network-related VM settings.
6. Image and importer pipeline
Image handling is split across pkg/image, pkg/controller/master/image, pkg/controller/master/vmimagedownloader, and the pkg/api/image endpoints. This subsystem supports VM image download, upload, backing-image management, and CDI-backed data import flows, with validation/mutation logic split by backend type.
7. Storage and backup subsystem
Storage is centered on Longhorn and Kubernetes snapshot APIs. Controllers in pkg/controller/master/storageclass, pkg/controller/master/pvc, pkg/controller/master/backup, pkg/controller/master/schedulevmbackup, and pkg/controller/master/volumeremotebackup manage storage classes, volume snapshots, VM backups/restores, scheduled backups, and remote backup/restore paths.
8. Networking and node management
Networking-related behavior spans pkg/controller/master/kubevirt, pkg/controller/master/storagenetwork, pkg/controller/master/node, and the generated network client layers. This includes VIP configuration, cluster network settings, node drain/promote flows, CPU and maintenance settings, and integrations with network providers like Kube-OVN and Whereabouts.
9. Admission webhook boundary
pkg/webhook and cmd/webhook implement a separate admission service for validating and mutating Harvester and Kubernetes objects. It covers resource-specific policies for VMs, PVCs, storage classes, namespaces, nodes, secrets, templates, upgrades, bundles, and related CRDs.
10. HTTP/API surface
The pkg/server and pkg/api packages expose Harvester’s REST-style API over Kubernetes-backed resources. Handlers and formatters present cluster, node, VM, volume, snapshot, keypair, support bundle, upgrade log, proxy, readyz, and kubeconfig operations as the external API boundary.
11. Upgrade and lifecycle tooling
Upgrade behavior is split between in-cluster controllers under pkg/controller/master/upgrade and operational scripts under package/upgrade. The cmd/upgradehelper binary and its subcommands provide upgrade-specific support such as version guards, VM live-migration detection, and VM restore helpers.
12. Deployment packaging
The deploy/charts directory contains the Helm packaging for Harvester and its CRDs, plus embedded dependency charts for components like KubeVirt, CDI, Longhorn, Whereabouts, and kube-vip. This repo therefore owns both the operator/control-plane logic and the cluster installation artifacts.
13. External platform dependencies
Harvester’s architecture is strongly shaped by integrations with KubeVirt for virtualization, Longhorn for storage, CDI for image import, Rancher/management.cattle.io APIs for cluster management, and multiple networking/monitoring APIs. The generated clients and controllers show that Harvester continuously reconciles against these external Kubernetes API groups.
14. Testing and generated code
The repo relies heavily on generated Kubernetes clients/controllers under pkg/generated and has integration coverage in tests/integration plus webhook/controller tests. That indicates the system is built around declarative reconciliation, with most behavior verified against live or fake Kubernetes APIs rather than isolated local state.
Main entry points: master Master ctrls · api REST API · charts Deploy charts · app.go App cmd
Components 23
Control Plane
Main application entrypoints and controller orchestration for the Harvester control plane.
- Main app · Top-level application bootstrap for the core Harvester services.
main.go - App cmd · Shared command/app wiring for running the main Harvester process.
pkg/cmd/app.go - Master ctrls · Primary controllers that reconcile Harvester CRs into cluster state.
pkg/controller/master - Global ctrls · Cluster-wide controllers and setup for global settings and shared behavior.
pkg/controller/global - VM control · Virtual machine reconciliation, instance handling, network adjustments, and migration-related logic.
pkg/controller/master/virtualmachine - Image control · Image download, upload, and backing-image controllers.
pkg/controller/master/image - Backup control · VM backup, restore, schedule, and remote-backup controllers.
pkg/controller/master/backup - Node control · Node maintenance, drain/promote, CPU, and node state reconciliation.
pkg/controller/master/node - Upgrade control · Upgrade plans, jobs, nodes, images, settings, and version synchronization.
pkg/controller/master/upgrade
API Surface
REST-style API packages and Kubernetes-backed resource presentation.
- API server · External HTTP and routing layer exposing Harvester APIs.
pkg/server - REST API · Resource formatters, handlers, schemas, and stores for Harvester-facing objects.
pkg/api - VM API · API surface for virtual machines and related templates.
pkg/api/vm - Volume API · API surface for volumes and volume snapshots.
pkg/api/volume - Image API · API surface for VM images and download/upload workflows.
pkg/api/image - Harvester CRDs · Harvester-specific API types for VMs, images, backups, settings, upgrades, bundles, and templates.
pkg/apis/harvesterhci.io/v1beta1
Runtime Integrations
External Kubernetes API groups and virtualization/storage/network integrations Harvester reconciles against.
- KubeVirt · External virtualization API group used for VMs, VIs, and migrations.
pkg/generated/clientset/versioned/typed/kubevirt.io/v1 - Longhorn · External storage API group for volumes, snapshots, and backups.
pkg/generated/clientset/versioned/typed/longhorn.io/v1beta2 - CDI · Containerized Data Importer APIs for upload and data import flows.
pkg/generated/clientset/versioned/typed/cdi.kubevirt.io/v1beta1 - Network APIs · Network-related Kubernetes and Harvester API groups including Kube-OVN, Whereabouts, and networking primitives.
pkg/generated/clientset/versioned
Ops and Packaging
Webhook service, upgrade tooling, and deployment/packaging artifacts.
- Webhook srv · Separate validating and mutating admission service for Harvester and Kubernetes objects.
pkg/webhook - Webhook bin · Standalone webhook binary entrypoint.
cmd/webhook - Upgrade helper · Standalone helper binary for upgrade-time operations.
cmd/upgradehelper - Deploy charts · Helm charts and embedded dependency charts for cluster installation and component packaging.
deploy/charts
Connections 27
- Main app → App cmd: boots · Main binary uses shared command/application wiring.
- App cmd → Master ctrls: starts · Application wiring initializes the primary reconciliation controllers.
- App cmd → Global ctrls: starts · Application wiring initializes global settings controllers.
- Master ctrls → VM control: includes · Master controllers include VM reconciliation.
- Master ctrls → Image control: includes · Master controllers include image lifecycle handling.
- Master ctrls → Backup control: includes · Master controllers include backup and restore handling.
- Master ctrls → Node control: includes · Master controllers include node lifecycle handling.
- Master ctrls → Upgrade control: includes · Master controllers include upgrade orchestration.
- API server → REST API: serves · HTTP server exposes the resource-oriented API layer.
- REST API → VM API: exposes · REST layer includes VM endpoints and formatters.
- REST API → Volume API: exposes · REST layer includes volume and snapshot endpoints.
- REST API → Image API: exposes · REST layer includes image endpoints.
- REST API → Harvester CRDs: maps · API layer is backed by Harvester custom resource definitions.
- VM control → KubeVirt: reconciles · VM controllers project Harvester intent into KubeVirt resources.
- Image control → CDI: imports via · Image flows rely on CDI for upload and import.
- Backup control → Longhorn: backs up via · Backup paths use Longhorn volumes and snapshots.
- Backup control → CDI: restores via · Restore/import flows can use CDI-backed data movement.
- VM control → Network APIs: uses · VM networking behavior depends on network API groups and providers.
- Node control → Network APIs: uses · Node and maintenance flows integrate with networking settings and providers.
- Webhook bin → Webhook srv: hosts · Webhook binary hosts the admission service.
- Webhook srv → Harvester CRDs: validates · Webhook applies policies to Harvester resources.
- Webhook srv → Network APIs: mutates · Webhook also guards selected Kubernetes/network objects.
- Upgrade helper → Upgrade control: supports · Upgrade helper binary supports upgrade-time workflows.
- Upgrade control → Deploy charts: coordinates · Upgrade logic aligns with packaged charts and installation artifacts.
- Deploy charts → KubeVirt: deploys · Packaging includes KubeVirt dependency charts and manifests.
- Deploy charts → Longhorn: deploys · Packaging includes Longhorn dependency charts and manifests.
- Deploy charts → CDI: deploys · Packaging includes CDI dependency charts and manifests.