# fabiante/podbouncer architecture

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

- Interactive diagram: https://gitdiagram.com/fabiante/podbouncer
- Repository: https://github.com/fabiante/podbouncer

## Overview

##### Main Components Identification

a) Kubernetes Cluster Components:
- Kubernetes API Server
- Pod Resources (targets)
- ConfigMap Resource (configuration)
- Namespace boundaries

b) Operator Components:
- Controller Manager
- Pod Controller
- ConfigMap Controller
- Metrics Server

##### Specific Implementation Details

Technical aspects:

a) Controller Logic:
- Pod filtering process (non-running pods)
- Namespace exclusion (kube-system)
- Age-based deletion mechanism

b) Configuration:
- ConfigMap in the podbouncer-system namespace
- MaxPodAge configuration parameter

a) Control Plane:
- Controller Manager
- RBAC components
- Metrics server

b) Operational Layer:
- Pod watching mechanism
- ConfigMap watching mechanism
- Deletion logic

c) Resource Layer:
- Target pods across namespaces
- Configuration ConfigMap
- Namespace boundaries

##### Important Details

To highlight:

- The operator's deployment in podbouncer-system namespace
- The pod states it monitors (Pending, Completed, Failed)
- The configuration loading mechanism
- The metrics endpoint for monitoring
- RBAC permissions and service account connections

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Control Plane"
        KAS[Kubernetes API Server]:::k8s
        CM["Controller Manager"]:::operator
        click CM "https://github.com/fabiante/podbouncer/blob/main/cmd/main.go"
        
        subgraph "Controllers"
            PC["Pod Controller"]:::operator
            click PC "https://github.com/fabiante/podbouncer/blob/main/internal/controller/pod_controller.go"
            CC["ConfigMap Controller"]:::operator
            click CC "https://github.com/fabiante/podbouncer/blob/main/internal/controller/configmap_controller.go"
            Config["Configuration Manager"]:::operator
            click Config "https://github.com/fabiante/podbouncer/blob/main/internal/controller/config.go"
        end
        
        subgraph "Metrics & Monitoring"
            MS["Metrics Server"]:::monitoring
            click MS "https://github.com/fabiante/podbouncer/blob/main/config/default/metrics_service.yaml"
            MP["Metrics Patch"]:::monitoring
            click MP "https://github.com/fabiante/podbouncer/blob/main/config/default/manager_metrics_patch.yaml"
            PM["Prometheus Monitor"]:::monitoring
            click PM "https://github.com/fabiante/podbouncer/blob/main/config/prometheus/monitor.yaml"
        end
        
        subgraph "RBAC"
            Role["Role"]:::rbac
            click Role "https://github.com/fabiante/podbouncer/blob/main/config/rbac/role.yaml"
            RB["Role Binding"]:::rbac
            click RB "https://github.com/fabiante/podbouncer/blob/main/config/rbac/role_binding.yaml"
            SA["Service Account"]:::rbac
            click SA "https://github.com/fabiante/podbouncer/blob/main/config/rbac/service_account.yaml"
            MAR["Metrics Auth Role"]:::rbac
            click MAR "https://github.com/fabiante/podbouncer/blob/main/config/rbac/metrics_auth_role.yaml"
        end
    end
    
    subgraph "Operational Layer"
        MgrConfig["Manager Config"]:::config
        click MgrConfig "https://github.com/fabiante/podbouncer/blob/main/config/manager/manager.yaml"
        NetPolicy["Network Policy"]:::config
        click NetPolicy "https://github.com/fabiante/podbouncer/blob/main/config/network-policy/allow-metrics-traffic.yaml"
        SampleConfig["Sample Config"]:::config
        click SampleConfig "https://github.com/fabiante/podbouncer/blob/main/config/samples/config.yaml"
    end
    
    subgraph "Resource Layer"
        Pods["Target Pods"]:::resource
        ConfigMap["ConfigMap"]:::resource
        NS["Namespaces"]:::resource
    end
    
    subgraph "Testing"
        E2E["E2E Tests"]:::test
        click E2E "https://github.com/fabiante/podbouncer/blob/main/test/e2e/e2e_test.go"
        PCT["Pod Controller Tests"]:::test
        click PCT "https://github.com/fabiante/podbouncer/blob/main/internal/controller/pod_controller_test.go"
        CCT["ConfigMap Controller Tests"]:::test
        click CCT "https://github.com/fabiante/podbouncer/blob/main/internal/controller/configmap_controller_test.go"
    end
    
    %% Relationships
    KAS <--> CM
    CM --> PC
    CM --> CC
    CM --> Config
    PC -.-> Pods
    CC -.-> ConfigMap
    Config --> ConfigMap
    MS --> PM
    MS --> MP
    
    Role --> SA
    RB --> Role
    MAR --> MS
    
    MgrConfig --> CM
    NetPolicy --> MS
    SampleConfig --> ConfigMap
    
    %% Testing relationships
    E2E -.-> CM
    PCT -.-> PC
    CCT -.-> CC
    
    %% Styling
    classDef k8s fill:#326CE5,stroke:#fff,stroke-width:2px,color:#fff
    classDef operator fill:#68B684,stroke:#333,stroke-width:1px
    classDef monitoring fill:#FFB100,stroke:#333,stroke-width:1px
    classDef rbac fill:#FF6B6B,stroke:#333,stroke-width:1px
    classDef config fill:#4ECDC4,stroke:#333,stroke-width:1px
    classDef resource fill:#95A5A6,stroke:#333,stroke-width:1px
    classDef test fill:#9B59B6,stroke:#333,stroke-width:1px
    
    %% Legend
    subgraph Legend
        L1[Kubernetes Component]:::k8s
        L2[Operator Component]:::operator
        L3[Monitoring Component]:::monitoring
        L4[RBAC Component]:::rbac
        L5[Configuration]:::config
        L6[Resource]:::resource
        L7[Test]:::test
    end
```
