# rancher/turtles architecture

> Architecture diagram of the GitHub repository rancher/turtles, 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/turtles
- Repository: https://github.com/rancher/turtles

## Overview

##### Main Components

a. Core Components:
- Rancher Turtles Operator
- Rancher Manager
- Cluster API (CAPI) Components
- Kubernetes API Server
- Fleet GitOps Engine

b. Custom Resources:
- CAPIProvider
- ClusterctlConfig
- ETCDMachineSnapshot (experimental)
- ETCDSnapshotRestore (experimental)

**┌─ Control Plane Layer ─────────────────────────────┐**
- ┌─ Rancher Manager ─┐  ┌─ Rancher Turtles ─────┐ │
- Controllers          │ │
- Cluster Mgmt    │◄─┤ - Sync Components     │ │
- User Interface  │  │ - Provider Management  │ │
- ┘  └─────────────────────┬─┘ │

- ┌─ CAPI Operator ────────────────────────────┼──┐│
- Provider Controllers                    │  ││
- Cluster Management                      │  ││
- ┘  ││
- ┘

**┌─ Infrastructure Layer ┼────────────────────────┐**
- ┌─ Provider Layer ────┼─┐                      │
- AWS              │ │                      │
- Azure           ◄┘ │                      │
- GCP                │                      │
- vSphere            │                      │
- ┘                      │
- ┘

##### Key Interactions to Highlight

- Bidirectional communication between Rancher Turtles and Rancher Manager
- Flow of cluster creation/import process
- Provider management and synchronization
- Integration with Fleet GitOps
- ETCD backup/restore flows (experimental feature)

##### Important Details

a. Controller Flows:
- CAPIProvider Controller
- Import Controller
- Configuration Controller
- ETCD Snapshot Controller (experimental)

b. API Resources:
- CRD relationships
- API versions
- Experimental features

##### Specific Implementation Notes

- Version information for major components
- Experimental features with appropriate notation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Control["Control Plane Layer"]
        RT["Rancher Turtles Operator"]:::operator
        RM["Rancher Manager"]:::rancher
        CAPI["Cluster API (CAPI)"]:::capi
        K8S["Kubernetes API Server"]:::k8s
        Fleet["Fleet GitOps Engine"]:::fleet

        subgraph Controllers["Controller Components"]
            CPC["CAPIProvider Controller"]:::controller
            IC["Import Controller"]:::controller
            CC["Configuration Controller"]:::controller
            ESC["ETCD Snapshot Controller"]:::experimental
        end

        subgraph Resources["Custom Resources"]
            CPICRD["CAPIProvider CRD"]:::crd
            CCRD["ClusterctlConfig CRD"]:::crd
            EMSCRD["ETCDMachineSnapshot CRD"]:::experimental
            ESRCRD["ETCDSnapshotRestore CRD"]:::experimental
        end

        subgraph Sync["Provider Sync"]
            PS["Provider Sync Manager"]:::sync
            APS["Azure Provider Sync"]:::sync
            GPS["GCP Provider Sync"]:::sync
        end
    end

    subgraph Infrastructure["Infrastructure Layer"]
        AWS["AWS Provider"]:::provider
        Azure["Azure Provider"]:::provider
        GCP["GCP Provider"]:::provider
        VS["vSphere Provider"]:::provider
    end

    %% Relationships
    RT --> RM
    RT --> CAPI
    RT --> K8S
    RT --> Fleet
    
    Controllers --> Resources
    Controllers --> K8S
    
    PS --> AWS
    PS --> Azure
    PS --> GCP
    PS --> VS
    
    RM --> K8S
    CAPI --> K8S
    
    %% Click Events
    click RT "https://github.com/rancher/turtles/tree/main/internal/controllers/"
    click CPC "https://github.com/rancher/turtles/blob/main/internal/controllers/capiprovider_controller.go"
    click IC "https://github.com/rancher/turtles/blob/main/internal/controllers/import_controller.go"
    click ESC "https://github.com/rancher/turtles/blob/main/exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go"
    click CPICRD "https://github.com/rancher/turtles/blob/main/api/v1alpha1/capiprovider_types.go"
    click CCRD "https://github.com/rancher/turtles/blob/main/api/v1alpha1/clusterctl_config_types.go"
    click EMSCRD "https://github.com/rancher/turtles/blob/main/exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go"
    click ESRCRD "https://github.com/rancher/turtles/blob/main/exp/etcdrestore/api/v1alpha1/etcdsnapshotrestore_types.go"
    click PS "https://github.com/rancher/turtles/blob/main/internal/sync/provider_sync.go"
    click APS "https://github.com/rancher/turtles/blob/main/internal/sync/azure_provider_sync.go"
    click GPS "https://github.com/rancher/turtles/blob/main/internal/sync/gcp_provider_sync.go"
    click Fleet "https://github.com/rancher/turtles/blob/main/charts/rancher-turtles/templates/addon-provider-fleet.yaml"

    %% Styles
    classDef operator fill:#2196F3,stroke:#1565C0,color:white
    classDef rancher fill:#4CAF50,stroke:#388E3C,color:white
    classDef capi fill:#FF9800,stroke:#F57C00,color:white
    classDef k8s fill:#9E9E9E,stroke:#616161,color:white
    classDef fleet fill:#673AB7,stroke:#512DA8,color:white
    classDef controller fill:#90CAF9,stroke:#64B5F6,color:black
    classDef crd fill:#81C784,stroke:#66BB6A,color:black
    classDef experimental fill:#FFB74D,stroke:#FFA726,color:black,stroke-dasharray: 5 5
    classDef sync fill:#CE93D8,stroke:#BA68C8,color:black
    classDef provider fill:#7E57C2,stroke:#5E35B1,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::operator
        L2["Rancher Components"]:::rancher
        L3["CAPI Components"]:::capi
        L4["Kubernetes Components"]:::k8s
        L5["Experimental Features"]:::experimental
        L6["Provider Components"]:::provider
    end
```
