# harvester/harvester architecture

> Architecture diagram of the GitHub repository harvester/harvester, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harvester/harvester
- Repository: https://github.com/harvester/harvester
- Video tour (about a minute): https://gitdiagram.com/harvester/harvester/video

## Overview

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: [`pkg/controller/master`](https://github.com/harvester/harvester/tree/master/pkg/controller/master) (Master ctrls), [`pkg/api`](https://github.com/harvester/harvester/tree/master/pkg/api) (REST API), [`deploy/charts`](https://github.com/harvester/harvester/tree/master/deploy/charts) (Deploy charts), [`pkg/cmd/app.go`](https://github.com/harvester/harvester/blob/master/pkg/cmd/app.go) (App cmd)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Control Plane"]
  node_main_app["Main app<br/>control-plane entrypoint<br/>[main.go]"]
  node_app_cmd["App cmd<br/>runtime wiring<br/>[app.go]"]
  node_master_ctrl["Master ctrls<br/>reconciliation plane"]
  node_global_ctrl["Global ctrls<br/>cluster settings"]
  node_vm_ctrl["VM control<br/>virtual machine reconcile"]
  node_image_ctrl["Image control<br/>image lifecycle"]
  node_backup_ctrl["Backup control<br/>backup lifecycle"]
  node_node_ctrl["Node control<br/>node lifecycle"]
  node_upgrade_ctrl["Upgrade control<br/>upgrade orchestration"]
end

subgraph group_api["API Surface"]
  node_server_api["API server<br/>http boundary"]
  node_rest_api["REST API<br/>resource API"]
  node_vm_api["VM API<br/>vm resource API"]
  node_volume_api["Volume API<br/>storage API"]
  node_image_api["Image API"]
  node_harvester_crd["Harvester CRDs<br/>custom resources<br/>[v1beta1]"]
end

subgraph group_runtime["Runtime Integrations"]
  node_kubevirt_api["KubeVirt<br/>virtualization api<br/>[v1]"]
  node_longhorn_api["Longhorn<br/>storage api<br/>[v1beta2]"]
  node_cdi_api["CDI<br/>import api<br/>[v1beta1]"]
  node_network_api["Network APIs<br/>network api groups"]
end

subgraph group_ops["Ops and Packaging"]
  node_webhook_srv["Webhook srv<br/>admission service"]
  node_webhook_bin["Webhook bin<br/>webhook entrypoint"]
  node_upgrade_bin["Upgrade helper<br/>upgrade entrypoint"]
  node_charts["Deploy charts<br/>helm packaging"]
end

node_main_app -->|"boots"| node_app_cmd
node_app_cmd -->|"starts"| node_master_ctrl
node_app_cmd -->|"starts"| node_global_ctrl
node_master_ctrl -->|"includes"| node_vm_ctrl
node_master_ctrl -->|"includes"| node_image_ctrl
node_master_ctrl -->|"includes"| node_backup_ctrl
node_master_ctrl -->|"includes"| node_node_ctrl
node_master_ctrl -->|"includes"| node_upgrade_ctrl
node_server_api -->|"serves"| node_rest_api
node_rest_api -->|"exposes"| node_vm_api
node_rest_api -->|"exposes"| node_volume_api
node_rest_api -->|"exposes"| node_image_api
node_rest_api -->|"maps"| node_harvester_crd
node_vm_ctrl -->|"reconciles"| node_kubevirt_api
node_image_ctrl -->|"imports via"| node_cdi_api
node_backup_ctrl -->|"backs up via"| node_longhorn_api
node_backup_ctrl -->|"restores via"| node_cdi_api
node_vm_ctrl -->|"uses"| node_network_api
node_node_ctrl -->|"uses"| node_network_api
node_webhook_bin -->|"hosts"| node_webhook_srv
node_webhook_srv -->|"validates"| node_harvester_crd
node_webhook_srv -->|"mutates"| node_network_api
node_upgrade_bin -->|"supports"| node_upgrade_ctrl
node_upgrade_ctrl -->|"coordinates"| node_charts
node_charts -->|"deploys"| node_kubevirt_api
node_charts -->|"deploys"| node_longhorn_api
node_charts -->|"deploys"| node_cdi_api

click node_main_app "https://github.com/harvester/harvester/blob/master/main.go"
click node_app_cmd "https://github.com/harvester/harvester/blob/master/pkg/cmd/app.go"
click node_master_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/master"
click node_global_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/global"
click node_vm_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/master/virtualmachine"
click node_image_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/master/image"
click node_backup_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/master/backup"
click node_node_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/master/node"
click node_upgrade_ctrl "https://github.com/harvester/harvester/tree/master/pkg/controller/master/upgrade"
click node_server_api "https://github.com/harvester/harvester/tree/master/pkg/server"
click node_rest_api "https://github.com/harvester/harvester/tree/master/pkg/api"
click node_vm_api "https://github.com/harvester/harvester/tree/master/pkg/api/vm"
click node_volume_api "https://github.com/harvester/harvester/tree/master/pkg/api/volume"
click node_image_api "https://github.com/harvester/harvester/tree/master/pkg/api/image"
click node_harvester_crd "https://github.com/harvester/harvester/blob/master/pkg/apis/harvesterhci.io/v1beta1"
click node_kubevirt_api "https://github.com/harvester/harvester/blob/master/pkg/generated/clientset/versioned/typed/kubevirt.io/v1"
click node_longhorn_api "https://github.com/harvester/harvester/blob/master/pkg/generated/clientset/versioned/typed/longhorn.io/v1beta2"
click node_cdi_api "https://github.com/harvester/harvester/blob/master/pkg/generated/clientset/versioned/typed/cdi.kubevirt.io/v1beta1"
click node_network_api "https://github.com/harvester/harvester/tree/master/pkg/generated/clientset/versioned"
click node_webhook_srv "https://github.com/harvester/harvester/tree/master/pkg/webhook"
click node_webhook_bin "https://github.com/harvester/harvester/tree/master/cmd/webhook"
click node_upgrade_bin "https://github.com/harvester/harvester/tree/master/cmd/upgradehelper"
click node_charts "https://github.com/harvester/harvester/tree/master/deploy/charts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_app,node_app_cmd,node_master_ctrl,node_global_ctrl,node_vm_ctrl,node_image_ctrl,node_backup_ctrl,node_node_ctrl,node_upgrade_ctrl toneBlue
class node_server_api,node_rest_api,node_vm_api,node_volume_api,node_image_api,node_harvester_crd toneAmber
class node_kubevirt_api,node_longhorn_api,node_cdi_api,node_network_api toneMint
class node_webhook_srv,node_webhook_bin,node_upgrade_bin,node_charts toneRose
```

## Components

### Control Plane

Main application entrypoints and controller orchestration for the Harvester control plane.

- [Main app](https://github.com/harvester/harvester/blob/master/main.go): control-plane entrypoint · Top-level application bootstrap for the core Harvester services. · `main.go`
- [App cmd](https://github.com/harvester/harvester/blob/master/pkg/cmd/app.go): runtime wiring · Shared command/app wiring for running the main Harvester process. · `pkg/cmd/app.go`
- [Master ctrls](https://github.com/harvester/harvester/tree/master/pkg/controller/master): reconciliation plane · Primary controllers that reconcile Harvester CRs into cluster state. · `pkg/controller/master`
- [Global ctrls](https://github.com/harvester/harvester/tree/master/pkg/controller/global): cluster settings · Cluster-wide controllers and setup for global settings and shared behavior. · `pkg/controller/global`
- [VM control](https://github.com/harvester/harvester/tree/master/pkg/controller/master/virtualmachine): virtual machine reconcile · Virtual machine reconciliation, instance handling, network adjustments, and migration-related logic. · `pkg/controller/master/virtualmachine`
- [Image control](https://github.com/harvester/harvester/tree/master/pkg/controller/master/image): image lifecycle · Image download, upload, and backing-image controllers. · `pkg/controller/master/image`
- [Backup control](https://github.com/harvester/harvester/tree/master/pkg/controller/master/backup): backup lifecycle · VM backup, restore, schedule, and remote-backup controllers. · `pkg/controller/master/backup`
- [Node control](https://github.com/harvester/harvester/tree/master/pkg/controller/master/node): node lifecycle · Node maintenance, drain/promote, CPU, and node state reconciliation. · `pkg/controller/master/node`
- [Upgrade control](https://github.com/harvester/harvester/tree/master/pkg/controller/master/upgrade): upgrade orchestration · 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](https://github.com/harvester/harvester/tree/master/pkg/server): http boundary · External HTTP and routing layer exposing Harvester APIs. · `pkg/server`
- [REST API](https://github.com/harvester/harvester/tree/master/pkg/api): resource API · Resource formatters, handlers, schemas, and stores for Harvester-facing objects. · `pkg/api`
- [VM API](https://github.com/harvester/harvester/tree/master/pkg/api/vm): vm resource API · API surface for virtual machines and related templates. · `pkg/api/vm`
- [Volume API](https://github.com/harvester/harvester/tree/master/pkg/api/volume): storage API · API surface for volumes and volume snapshots. · `pkg/api/volume`
- [Image API](https://github.com/harvester/harvester/tree/master/pkg/api/image): image API · API surface for VM images and download/upload workflows. · `pkg/api/image`
- [Harvester CRDs](https://github.com/harvester/harvester/blob/master/pkg/apis/harvesterhci.io/v1beta1): custom resources · 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](https://github.com/harvester/harvester/blob/master/pkg/generated/clientset/versioned/typed/kubevirt.io/v1): virtualization api · External virtualization API group used for VMs, VIs, and migrations. · `pkg/generated/clientset/versioned/typed/kubevirt.io/v1`
- [Longhorn](https://github.com/harvester/harvester/blob/master/pkg/generated/clientset/versioned/typed/longhorn.io/v1beta2): storage api · External storage API group for volumes, snapshots, and backups. · `pkg/generated/clientset/versioned/typed/longhorn.io/v1beta2`
- [CDI](https://github.com/harvester/harvester/blob/master/pkg/generated/clientset/versioned/typed/cdi.kubevirt.io/v1beta1): import api · Containerized Data Importer APIs for upload and data import flows. · `pkg/generated/clientset/versioned/typed/cdi.kubevirt.io/v1beta1`
- [Network APIs](https://github.com/harvester/harvester/tree/master/pkg/generated/clientset/versioned): network api groups · 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](https://github.com/harvester/harvester/tree/master/pkg/webhook): admission service · Separate validating and mutating admission service for Harvester and Kubernetes objects. · `pkg/webhook`
- [Webhook bin](https://github.com/harvester/harvester/tree/master/cmd/webhook): webhook entrypoint · Standalone webhook binary entrypoint. · `cmd/webhook`
- [Upgrade helper](https://github.com/harvester/harvester/tree/master/cmd/upgradehelper): upgrade entrypoint · Standalone helper binary for upgrade-time operations. · `cmd/upgradehelper`
- [Deploy charts](https://github.com/harvester/harvester/tree/master/deploy/charts): helm packaging · Helm charts and embedded dependency charts for cluster installation and component packaging. · `deploy/charts`

## Connections

- 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.
