# vivekgarg20/prometheus-operator architecture

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

- Interactive diagram: https://gitdiagram.com/vivekgarg20/prometheus-operator
- Repository: https://github.com/vivekgarg20/prometheus-operator

## Overview

##### Main Components

a. Core Components:
- Prometheus Operator Controller
- Custom Resource Definitions (CRDs)
- Kubernetes API Server
- Webhook Server (for validation)
- Config Reloader
- Client Components (monitoring targets)

b. Custom Resources to Represent:
- Prometheus
- Alertmanager
- ServiceMonitor
- PodMonitor
- PrometheusRule
- ThanosRuler

##### Component Relationships

- Prometheus Operator watching Kubernetes API for CRD changes
- Operator creating/managing Prometheus and Alertmanager instances
- ServiceMonitor/PodMonitor configurations feeding into Prometheus instances
- Config Reloader watching for configuration changes
- Webhook validation flow for PrometheusRules

##### Architectural Pattern Representation

Use the following structure:
**┌─────────────────────────────────────────────────────────────┐**
- Kubernetes Cluster                        │
- ┌─────────────────┐    ┌──────────────────────────────┐   │
- Control Plane   │    │     Prometheus Operator       │   │
- ◄───┤  (Controller + Reconciliation)│   │
- ┘    └──────────────────────────────┘   │
- ▲                           │                      │
- ▼                      │
- ┌─────────────────┐    ┌──────────────────────────────┐   │
- CRDs       │    │  Managed Components          │   │
- Prometheus   │    │  - Prometheus Instances      │   │
- Alertmanager │    │  - Alertmanager Instances   │   │
- ServiceMonitor│    │  - Configuration            │   │
- ┘    └──────────────────────────────┘   │
- ┘

##### Implementation Details

- Reconciliation loop pattern
- RBAC connections
- Configuration management flow
- Monitoring data flow paths
- High availability configurations
- Integration points with Thanos (optional)

##### Specific Elements to Highlight

- Custom Resource Definition handling
- Service discovery mechanism
- Configuration management
- Alert routing
- Monitoring target selection
- High availability features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Kubernetes["Kubernetes Cluster"]
        API["Kubernetes API Server"]:::k8s
        
        subgraph Operator["Prometheus Operator"]
            Controller["Controller & Reconciliation"]:::operator
            Webhook["Webhook Server"]:::operator
            ConfigReloader["Config Reloader"]:::operator
        end
        
        subgraph CRDs["Custom Resource Definitions"]
            Prom["Prometheus CRD"]:::crd
            Alert["Alertmanager CRD"]:::crd
            ServMon["ServiceMonitor CRD"]:::crd
            PodMon["PodMonitor CRD"]:::crd
            PromRule["PrometheusRule CRD"]:::crd
            Thanos["ThanosRuler CRD"]:::crd
        end
        
        subgraph Managed["Managed Components"]
            PromInst["Prometheus Instances"]:::managed
            AlertInst["Alertmanager Instances"]:::managed
            ThanosInst["Thanos Instances"]:::managed
        end
        
        subgraph Resources["Monitoring Resources"]
            Targets["Monitoring Targets"]:::resource
            Rules["Alert Rules"]:::resource
        end
    end
    
    %% Relationships
    API --> Controller
    Controller --> PromInst
    Controller --> AlertInst
    Controller --> ThanosInst
    
    Webhook -.-> API
    ConfigReloader -.-> PromInst
    ConfigReloader -.-> AlertInst
    
    Prom --> Controller
    Alert --> Controller
    ServMon --> Controller
    PodMon --> Controller
    PromRule --> Controller
    Thanos --> Controller
    
    PromInst --> Targets
    Rules --> PromInst
    AlertInst --> Rules
    
    %% Styles
    classDef k8s fill:#326CE5,stroke:#fff,stroke-width:2px,color:#fff
    classDef operator fill:#00A36C,stroke:#fff,stroke-width:2px,color:#fff
    classDef crd fill:#FFA500,stroke:#fff,stroke-width:2px,color:#fff
    classDef managed fill:#9370DB,stroke:#fff,stroke-width:2px,color:#fff
    classDef resource fill:#FF6B6B,stroke:#fff,stroke-width:2px,color:#fff
    
    %% Click Events
    click Controller "https://github.com/vivekgarg20/prometheus-operator/blob/master/pkg/operator/operator.go"
    click Webhook "https://github.com/vivekgarg20/prometheus-operator/blob/master/pkg/admission/admission.go"
    click ConfigReloader "https://github.com/vivekgarg20/prometheus-operator/blob/master/cmd/prometheus-config-reloader/main.go"
    click Prom "https://github.com/vivekgarg20/prometheus-operator/blob/master/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml"
    click Alert "https://github.com/vivekgarg20/prometheus-operator/blob/master/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml"
    click ServMon "https://github.com/vivekgarg20/prometheus-operator/blob/master/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml"
    click PodMon "https://github.com/vivekgarg20/prometheus-operator/blob/master/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml"
    click PromRule "https://github.com/vivekgarg20/prometheus-operator/blob/master/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml"
    click Thanos "https://github.com/vivekgarg20/prometheus-operator/blob/master/example/prometheus-operator-crd/monitoring.coreos.com_thanosrulers.yaml"
    click PromInst "https://github.com/vivekgarg20/prometheus-operator/blob/master/pkg/prometheus/operator.go"
    click AlertInst "https://github.com/vivekgarg20/prometheus-operator/blob/master/pkg/alertmanager/operator.go"
    click ThanosInst "https://github.com/vivekgarg20/prometheus-operator/blob/master/pkg/thanos/operator.go"
```
