# rancher/fleet architecture

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

- Interactive diagram: https://gitdiagram.com/rancher/fleet
- Repository: https://github.com/rancher/fleet

## Overview

##### Main Components (Core Architecture)

a. Control Plane Components:
- Fleet Controller (in /cmd/fleetcontroller)
- Git Operations Controller (in /internal/cmd/controller/gitops)
- Helm Operations Controller (in /internal/cmd/controller/helmops)
- Image Scanner Controller (in /internal/cmd/controller/imagescan)

b. Agent Components:
- Fleet Agent (in /cmd/fleetagent)
- Bundle Deployment Controller
- Drift Detection System

##### Specific Elements

a. Source Management:
- Git repositories
- Helm charts
- Raw Kubernetes manifests
- Kustomize configurations

b. Processing Pipeline:
- Bundle creation
- Resource transformation
- Helm chart generation
- Deployment management

c. Cluster Management:
- Multi-cluster registration
- Agent communication
- Status reporting
- Drift detection

##### Component Relationships

**[Git Sources] → [Fleet Controller] → [Bundle Processing] → [Fleet Agents] → [Target Clusters]**
- ↑                   ↓                    ↓                  ↓
**[Helm Charts]    [Image Scanner]    [Helm Operations]    [Drift Detection]**
- ↑                   ↓                    ↓                  ↓
**[Kustomize]     [Status Tracking] → [Resource Manager] → [Deployment Status]**

##### Important Subsystems to Detail

a. GitOps Pipeline:
- Repository watching
- Change detection
- Bundle generation
- Deployment orchestration

b. Cluster Management:
- Registration system
- Agent communication
- Health monitoring
- Configuration management

c. Security Layer:
- Authentication
- Authorization
- Secret management
- Secure communication

##### Operational Flows

Following key processes:
##### Status collection and reporting

- Handle multiple clusters at scale
- Support various deployment sources
- Maintain consistency across clusters
- Provide visibility and control
- Enable GitOps workflows

- Component types
- State indicators
- Relationship types

This system design should capture Fleet's sophisticated architecture while making it clear how it achieves GitOps at scale across multiple clusters.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Source Management"
        Git[("Git Repositories")]
        Helm[("Helm Charts")]
        K8s[("K8s Manifests")]
        Kust[("Kustomize")]
    end

    subgraph "Control Plane"
        FC["Fleet Controller"]:::core
        GOC["Git Operations Controller"]:::controller
        HOC["Helm Operations Controller"]:::controller
        ISC["Image Scanner Controller"]:::controller
        BC["Bundle Controller"]:::controller
        BDC["Bundle Deployment Controller"]:::controller
        CC["Cluster Controller"]:::controller
        CGC["Cluster Group Controller"]:::controller
        SC["Status Controller"]:::controller
    end

    subgraph "Agent Layer"
        FA["Fleet Agent"]:::agent
        DD["Drift Detection"]:::agent
    end

    subgraph "Security"
        Auth["Authentication"]:::security
        WH["Webhook Handler"]:::security
    end

    subgraph "Cluster Management"
        RS["Registration System"]:::management
        SR["Status Reporting"]:::management
    end

    subgraph "Target Clusters"
        K8C1["Kubernetes Cluster 1"]:::cluster
        K8C2["Kubernetes Cluster 2"]:::cluster
        K8C3["Kubernetes Cluster 3"]:::cluster
    end

    Git --> GOC
    Helm --> HOC
    K8s --> FC
    Kust --> FC

    FC --> BC
    BC --> BDC
    BDC --> FA

    GOC --> BC
    HOC --> BC
    ISC --> BC

    FA --> DD
    FA --> K8C1
    FA --> K8C2
    FA --> K8C3

    CC --> RS
    CGC --> RS
    RS --> FA

    FA --> SR
    SR --> SC

    Auth --> FA
    WH --> FA

    %% Click Events
    click FC "https://github.com/rancher/fleet/blob/main/cmd/fleetcontroller/main.go"
    click GOC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/gitops/operator.go"
    click HOC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/helmops/operator.go"
    click ISC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/imagescan/tagscan_job.go"
    click FA "https://github.com/rancher/fleet/blob/main/cmd/fleetagent/main.go"
    click BC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/reconciler/bundle_controller.go"
    click BDC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/reconciler/bundledeployment_controller.go"
    click DD "https://github.com/rancher/fleet/blob/main/internal/cmd/agent/deployer/driftdetect/driftdetect.go"
    click GOC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/gitops/reconciler/gitjob.go"
    click HOC "https://github.com/rancher/fleet/blob/main/charts/fleet/templates/deployment_helmops.yaml"
    click CC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/reconciler/cluster_controller.go"
    click CGC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/reconciler/clustergroup_controller.go"
    click RS "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/agentmanagement/controllers/clusterregistration/controller.go"
    click SC "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/gitops/reconciler/status_controller.go"
    click SR "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/status/status.go"
    click Auth "https://github.com/rancher/fleet/blob/main/internal/cmd/controller/agentmanagement/secret/util.go"
    click WH "https://github.com/rancher/fleet/blob/main/pkg/webhook/webhook.go"

    %% Styling
    classDef core fill:#2374AB
    classDef controller fill:#419D78
    classDef agent fill:#E09F3E
    classDef security fill:#9B2226
    classDef management fill:#94A89A
    classDef cluster fill:#748CAB

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Controllers"]:::controller
        L3["Agent Components"]:::agent
        L4["Security"]:::security
        L5["Management"]:::management
        L6["Clusters"]:::cluster
    end
```
