# gardener/pvc-autoscaler architecture

> Architecture diagram of the GitHub repository gardener/pvc-autoscaler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gardener/pvc-autoscaler
- Repository: https://github.com/gardener/pvc-autoscaler

## Overview

##### Main Components

a. Core Components:
- Kubernetes API Server (external component)
- PVC Autoscaler Controller Manager
- Prometheus Metrics Source
- Webhook Server
- Certificate Manager (cert-manager)

b. Custom Resources:
- PersistentVolumeClaimAutoscaler CRD
- PersistentVolumeClaim (managed resource)
- PersistentVolume (managed resource)

##### Component Relationships

- Controller Manager watching PVCAutoscaler resources (reconciliation loop)
- Controller querying Prometheus for metrics
- Webhook validation flow for PVCAutoscaler resources
- Volume resize operations flow

##### Implementation Details to Highlight

- Metrics collection system (internal/metrics)
- Periodic checking mechanism (internal/periodic)
- Controller reconciliation loop (internal/controller)
- Webhook validation (api/autoscaling/v1alpha1)

##### Resource watching flow
API Server -> Controller Manager -> PVCAutoscaler -> PVC
##### Metrics collection flow
PV -> Prometheus -> Controller Manager
##### Scaling decision flow
Controller Manager -> PVC resize operation

##### Additional Elements

Include:
- Version information
- Key configuration parameters (threshold, increaseBy, maxCapacity)
- RBAC connections

Remember to include:
- Clear component boundaries
- Kubernetes cluster boundary
- Namespace separations
- Configuration flows

This design should reflect the controller's primary purpose of automating PVC scaling while showing its integration with Kubernetes native resources and external monitoring systems.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Kubernetes Control Plane"
        API["Kubernetes API Server"]
        CM["PVC Autoscaler Controller Manager"]:::controller
        WH["Webhook Server"]:::webhook
        CERT["Certificate Manager"]:::security
    end

    subgraph "Monitoring"
        PROM["Prometheus Metrics Source"]:::monitoring
        MC["Metrics Collection System"]:::monitoring
    end

    subgraph "Custom Resources"
        CRD["PVCAutoscaler CRD"]:::resource
        PVC["PersistentVolumeClaim"]:::resource
        PV["PersistentVolume"]:::resource
    end

    subgraph "Configuration"
        RBAC["RBAC Configuration"]:::config
        PERIODIC["Periodic Checker"]:::component
        SAMPLES["Sample Configurations"]:::config
    end

    API --> CM
    API --> WH
    CERT --> WH
    CM --> PROM
    CM --> MC
    MC --> PROM
    PROM --> PV
    CM --> CRD
    CRD --> PVC
    PVC --> PV
    PERIODIC --> CM
    RBAC --> CM
    WH --> CRD

    classDef controller fill:#3498db
    classDef webhook fill:#2ecc71
    classDef security fill:#9b59b6
    classDef monitoring fill:#f1c40f
    classDef resource fill:#e67e22
    classDef config fill:#95a5a6
    classDef component fill:#1abc9c

    click CM "https://github.com/gardener/pvc-autoscaler/blob/master/internal/controller/autoscaling/persistentvolumeclaimautoscaler_controller.go"
    click WH "https://github.com/gardener/pvc-autoscaler/blob/master/api/autoscaling/v1alpha1/persistentvolumeclaimautoscaler_webhook.go"
    click CERT "https://github.com/gardener/pvc-autoscaler/blob/master/config/certmanager/certificate.yaml"
    click PROM "https://github.com/gardener/pvc-autoscaler/blob/master/internal/metrics/source/prometheus/prometheus.go"
    click CRD "https://github.com/gardener/pvc-autoscaler/blob/master/api/autoscaling/v1alpha1/persistentvolumeclaimautoscaler_types.go"
    click MC "https://github.com/gardener/pvc-autoscaler/blob/master/internal/metrics/metrics.go"
    click RBAC "https://github.com/gardener/pvc-autoscaler/blob/master/config/rbac/role.yaml"
    click PERIODIC "https://github.com/gardener/pvc-autoscaler/blob/master/internal/periodic/periodic.go"
    click SAMPLES "https://github.com/gardener/pvc-autoscaler/blob/master/config/samples/autoscaling_v1alpha1_persistentvolumeclaimautoscaler.yaml"
```
