# kyma-project/infrastructure-manager architecture

> Architecture diagram of the GitHub repository kyma-project/infrastructure-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kyma-project/infrastructure-manager
- Repository: https://github.com/kyma-project/infrastructure-manager

## Overview

##### Project type and purpose
- This is a Kubernetes “operator” (a controller) built with the Kubebuilder framework in Go.
- Its purpose is to manage CRDs (`GardenerCluster` and `Runtime`) and automatically generate and rotate Secrets containing dynamic kubeconfigs by talking to both the Kubernetes API Server and the external Gardener service.

##### File structure
- Top‐level:
- cmd/main.go — entrypoint for the controller manager binary
- api/v1 — Go types defining the CRDs
- config/ — Kubernetes manifests (CRDs, RBAC roles, manager Deployment, webhooks, metrics) organized via Kustomize
- internal/controller — the reconciliation logic (controllers for kubeconfig and runtime workflows, including an FSM for runtime management)
- pkg/ — reusable packages for interacting with Gardener, building kubeconfigs, extensibility points, provisioning, and reconciliation utilities
- hack/ — auxiliary CLI tools (benchmark, patch-converter, performance tests, runtime-migrator)
- Dockerfile, Makefile — build, test, containerize, deploy automation
- Patterns:
- Operator pattern: watch–reconcile loops
- FSM pattern for complex runtime lifecycle handling
- Kubernetes custom resources + CRD YAML + RBAC + webhook config

##### README for additional insights
- Confirms it’s a Kubebuilder operator that watches `GardenerCluster` CRs to create/rotate Secrets.
- Mentions metrics endpoint for Prometheus.
- Describes time-based and forced rotation triggers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Deployment Layer
    subgraph "CI/CD & Build" 
        direction TB
        Dockerfile["Dockerfile"]:::build
        Makefile["Makefile"]:::build
    end

    subgraph "Configuration Manifests"
        direction TB
        Config["config/"]:::config
    end

    Config -->|“Build Deployment”| Deployment["Manager Deployment"]:::k8s
    Dockerfile -->|“Build Image”| Deployment
    Makefile -->|“CI/CD”| Deployment

    %% Controller Manager Pod
    subgraph "Controller Manager Pod"
        direction TB
        Main["cmd/main.go"]:::controller
        subgraph "Reconciler Controllers"
            direction TB
            KC["Kubeconfig Controller"]:::controller
            RC["Runtime Controller"]:::controller
            MC["Metrics Controller"]:::controller
        end
        Main --> KC
        Main --> RC
        Main --> MC

        subgraph "Runtime FSM"
            direction TB
            FSM["Runtime FSM"]:::controller
        end
        RC --> FSM
    end

    %% Kubernetes API Server
    subgraph "Kubernetes API Server"
        direction TB
        CRDs["CRDs: GardenerCluster, Runtime"]:::k8s
        Secrets["Secrets"]:::k8s
        ConfigMaps["ConfigMaps"]:::k8s
        Events["Events"]:::k8s
    end

    %% External Services
    Gardener["Gardener Service"]:::external
    Prometheus["Prometheus"]:::external

    %% Developer Tools
    subgraph "Developer Utilities"
        direction TB
        Hack["hack/"]:::dev
    end

    %% Connections
    CRDs -->|“Watch CRD”| KC
    CRDs -->|“Watch CRD”| RC
    KC -->|“Get Kubeconfig”| Gardener
    RC -->|“Get Kubeconfig”| Gardener
    Gardener -->|“Return Kubeconfig”| KC
    Gardener -->|“Return Kubeconfig”| RC
    KC -->|“Update Secret”| Secrets
    RC -->|“Update Secret”| Secrets
    MC -->|“/metrics scrape”| Prometheus

    Deployment -->|“Runs”| Main

    %% Click Events
    click Main "https://github.com/kyma-project/infrastructure-manager/blob/main/cmd/main.go"
    click Dockerfile "https://github.com/kyma-project/infrastructure-manager/tree/main/Dockerfile"
    click Makefile "https://github.com/kyma-project/infrastructure-manager/tree/main/Makefile"
    click Config "https://github.com/kyma-project/infrastructure-manager/tree/main/config/"
    click KC "https://github.com/kyma-project/infrastructure-manager/blob/main/internal/controller/kubeconfig/gardener_cluster_controller.go"
    click KC "https://github.com/kyma-project/infrastructure-manager/blob/main/internal/controller/kubeconfig/find_last_sync_time.go"
    click KC "https://github.com/kyma-project/infrastructure-manager/blob/main/internal/controller/kubeconfig/next_requeue.go"
    click RC "https://github.com/kyma-project/infrastructure-manager/blob/main/internal/controller/runtime/runtime_controller.go"
    click FSM "https://github.com/kyma-project/infrastructure-manager/blob/main/internal/controller/runtime/fsm/runtime_fsm.go"
    click FSM "https://github.com/kyma-project/infrastructure-manager/tree/main/internal/controller/runtime/fsm/"
    click MC "https://github.com/kyma-project/infrastructure-manager/blob/main/internal/controller/metrics/metrics.go"
    click Gardener "https://github.com/kyma-project/infrastructure-manager/blob/main/pkg/gardener/client.go"
    click Gardener "https://github.com/kyma-project/infrastructure-manager/blob/main/pkg/gardener/kubeconfig/Provider.go"
    click Gardener "https://github.com/kyma-project/infrastructure-manager/blob/main/pkg/gardener/gardener_error_handler.go"
    click Gardener "https://github.com/kyma-project/infrastructure-manager/tree/main/pkg/gardener/shoot/"
    click Gardener "https://github.com/kyma-project/infrastructure-manager/tree/main/pkg/gardener/shoot/extender/"
    click Gardener "https://github.com/kyma-project/infrastructure-manager/tree/main/pkg/gardener/shoot/hyperscaler/"
    click ConfigMaps "https://github.com/kyma-project/infrastructure-manager/blob/main/pkg/config/config.go"
    click Secrets "https://github.com/kyma-project/infrastructure-manager/tree/main/pkg/provisioning/"
    click Events "https://github.com/kyma-project/infrastructure-manager/blob/main/pkg/reconciler/annotations_utils.go"
    click Hack "https://github.com/kyma-project/infrastructure-manager/tree/main/hack/benchmark/"
    click Hack "https://github.com/kyma-project/infrastructure-manager/tree/main/hack/patch-converter-runner/"
    click Hack "https://github.com/kyma-project/infrastructure-manager/tree/main/hack/performance/"
    click Hack "https://github.com/kyma-project/infrastructure-manager/tree/main/hack/runtime-migrator/"

    %% Styles
    classDef controller fill:#b2f5b6,stroke:#2f855a,color:#22543d
    classDef k8s fill:#bee3f8,stroke:#2b6cb0,color:#2c5282
    classDef external fill:#fbd38d,stroke:#dd6b20,color:#975a16
    classDef dev fill:#e2e8f0,stroke:#a0aec0,color:#4a5568,stroke-dasharray: 5 5
    classDef config fill:#fed7d7,stroke:#c53030,color:#742a2a
    classDef build fill:#c6f6d5,stroke:#38a169,color:#22543d
```
