# stakater/reloader architecture

> Architecture diagram of the GitHub repository stakater/reloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stakater/reloader
- Repository: https://github.com/stakater/reloader

## Overview

Reloader is a Kubernetes controller that watches configuration resources and triggers workload rollouts when relevant Secrets or ConfigMaps change. Its main path is cluster events through controller queues to reload handlers and Kubernetes workload updates; annotation-based selection, optional CSI support, notifications, HA leadership, and Prometheus metrics are additional capabilities. The README documents supported workload types and controls; unsampled implementation details are represented only at their supported directory paths.

Main entry points: [`internal/pkg/handler`](https://github.com/stakater/reloader/tree/master/internal/pkg/handler) (Reload handlers), [`internal/pkg/cmd/reloader.go`](https://github.com/stakater/reloader/blob/master/internal/pkg/cmd/reloader.go) (Startup and setup), [`internal/pkg/controller/controller.go`](https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go) (Resource controllers), [`internal/pkg/callbacks/rolling_upgrade.go`](https://github.com/stakater/reloader/blob/master/internal/pkg/callbacks/rolling_upgrade.go) (Workload updates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Controller runtime"]
  node_main["Process entry<br/>[main.go]"]
  node_app["Application runner<br/>[app.go]"]
  node_command["Startup and setup<br/>[reloader.go]"]
  node_controller["Resource controllers<br/>[controller.go]"]
  node_queue["Work queue<br/>[controller.go]"]
end

subgraph group_reload["Reload decisions"]
  node_handlers["Reload handlers"]
  node_common["Reload configuration<br/>[common.go]"]
  node_util["Resource hashing<br/>[util.go]"]
  node_crypto["SHA generation<br/>[sha.go]"]
  node_callbacks["Workload updates<br/>[rolling_upgrade.go]"]
end

subgraph group_integrations["Cluster integrations"]
  node_clients["Cluster clients<br/>[client.go]"]
  node_mapper["Resource mapping<br/>[resourcemapper.go]"]
  node_csi["CSI secrets<br/>[controller.go]"]
end

subgraph group_operations["Operations"]
  node_leadership["Leader election<br/>[leadership.go]"]
  node_metrics["Prometheus metrics<br/>[prometheus.go]"]
  node_alerts["Notifications"]
end

node_operator(("Cluster operator"))
node_config[("Secrets and ConfigMaps")]
node_kubeapi[("Kubernetes API")]
node_workloads[("Workloads")]
node_prometheus(("Prometheus"))
node_notify(("Webhook or chat"))

node_operator -->|"updates"| node_config
node_config -->|"stored in"| node_kubeapi
node_main -->|"runs"| node_app
node_app -->|"executes"| node_command
node_command -->|"creates"| node_clients
node_command -->|"starts"| node_controller
node_command -->|"coordinates"| node_leadership
node_kubeapi -->|"sends events"| node_controller
node_controller -->|"enqueues"| node_queue
node_queue -->|"dispatches"| node_handlers
node_handlers -->|"checks rules"| node_common
node_handlers -->|"computes change"| node_util
node_util -->|"hashes data"| node_crypto
node_handlers -->|"maps resources"| node_mapper
node_handlers -->|"requests rollout"| node_callbacks
node_callbacks -->|"uses clients"| node_clients
node_clients -->|"reads and writes"| node_kubeapi
node_callbacks -->|"patches or restarts"| node_workloads
node_controller -->|"records events"| node_metrics
node_handlers -->|"records actions"| node_metrics
node_metrics -->|"exposes metrics"| node_prometheus
node_controller -.->|"handles optional events"| node_csi
node_command -.->|"configures"| node_alerts
node_alerts -.->|"sends notifications"| node_notify

click node_main "https://github.com/stakater/reloader/blob/master/main.go"
click node_app "https://github.com/stakater/reloader/blob/master/internal/pkg/app/app.go"
click node_command "https://github.com/stakater/reloader/blob/master/internal/pkg/cmd/reloader.go"
click node_controller "https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go"
click node_queue "https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go"
click node_handlers "https://github.com/stakater/reloader/tree/master/internal/pkg/handler"
click node_common "https://github.com/stakater/reloader/blob/master/pkg/common/common.go"
click node_util "https://github.com/stakater/reloader/blob/master/internal/pkg/util/util.go"
click node_crypto "https://github.com/stakater/reloader/blob/master/internal/pkg/crypto/sha.go"
click node_callbacks "https://github.com/stakater/reloader/blob/master/internal/pkg/callbacks/rolling_upgrade.go"
click node_clients "https://github.com/stakater/reloader/blob/master/pkg/kube/client.go"
click node_mapper "https://github.com/stakater/reloader/blob/master/pkg/kube/resourcemapper.go"
click node_csi "https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go"
click node_leadership "https://github.com/stakater/reloader/blob/master/internal/pkg/leadership/leadership.go"
click node_metrics "https://github.com/stakater/reloader/blob/master/internal/pkg/metrics/prometheus.go"
click node_alerts "https://github.com/stakater/reloader/tree/master/internal/pkg/alerts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app,node_command,node_controller,node_queue toneBlue
class node_handlers,node_common,node_util,node_crypto,node_callbacks,node_config,node_kubeapi,node_workloads toneAmber
class node_clients,node_mapper,node_csi,node_notify toneMint
class node_leadership,node_metrics,node_alerts toneRose
class node_operator,node_prometheus toneIndigo
```

## Components

### Controller runtime

- [Process entry](https://github.com/stakater/reloader/blob/master/main.go): `main.go`
- [Application runner](https://github.com/stakater/reloader/blob/master/internal/pkg/app/app.go): `internal/pkg/app/app.go`
- [Startup and setup](https://github.com/stakater/reloader/blob/master/internal/pkg/cmd/reloader.go): `internal/pkg/cmd/reloader.go`
- [Resource controllers](https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go): `internal/pkg/controller/controller.go`
- [Work queue](https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go): `internal/pkg/controller/controller.go`

### Reload decisions

- [Reload handlers](https://github.com/stakater/reloader/tree/master/internal/pkg/handler): `internal/pkg/handler`
- [Reload configuration](https://github.com/stakater/reloader/blob/master/pkg/common/common.go): `pkg/common/common.go`
- [Resource hashing](https://github.com/stakater/reloader/blob/master/internal/pkg/util/util.go): `internal/pkg/util/util.go`
- [SHA generation](https://github.com/stakater/reloader/blob/master/internal/pkg/crypto/sha.go): `internal/pkg/crypto/sha.go`
- [Workload updates](https://github.com/stakater/reloader/blob/master/internal/pkg/callbacks/rolling_upgrade.go): `internal/pkg/callbacks/rolling_upgrade.go`

### Cluster integrations

- [Cluster clients](https://github.com/stakater/reloader/blob/master/pkg/kube/client.go): `pkg/kube/client.go`
- [Resource mapping](https://github.com/stakater/reloader/blob/master/pkg/kube/resourcemapper.go): `pkg/kube/resourcemapper.go`
- [CSI secrets](https://github.com/stakater/reloader/blob/master/internal/pkg/controller/controller.go): `internal/pkg/controller/controller.go`

### Operations

- [Leader election](https://github.com/stakater/reloader/blob/master/internal/pkg/leadership/leadership.go): `internal/pkg/leadership/leadership.go`
- [Prometheus metrics](https://github.com/stakater/reloader/blob/master/internal/pkg/metrics/prometheus.go): `internal/pkg/metrics/prometheus.go`
- [Notifications](https://github.com/stakater/reloader/tree/master/internal/pkg/alerts): `internal/pkg/alerts`

### Other components

- **Cluster operator**
- **Secrets and ConfigMaps**
- **Kubernetes API**
- **Workloads**
- **Prometheus**
- **Webhook or chat**

## Connections

- Cluster operator → Secrets and ConfigMaps: updates
- Secrets and ConfigMaps → Kubernetes API: stored in
- Process entry → Application runner: runs
- Application runner → Startup and setup: executes
- Startup and setup → Cluster clients: creates
- Startup and setup → Resource controllers: starts
- Startup and setup → Leader election: coordinates
- Kubernetes API → Resource controllers: sends events
- Resource controllers → Work queue: enqueues
- Work queue → Reload handlers: dispatches
- Reload handlers → Reload configuration: checks rules
- Reload handlers → Resource hashing: computes change
- Resource hashing → SHA generation: hashes data
- Reload handlers → Resource mapping: maps resources
- Reload handlers → Workload updates: requests rollout
- Workload updates → Cluster clients: uses clients
- Cluster clients → Kubernetes API: reads and writes
- Workload updates → Workloads: patches or restarts
- Resource controllers → Prometheus metrics: records events
- Reload handlers → Prometheus metrics: records actions
- Prometheus metrics → Prometheus: exposes metrics
- Resource controllers → CSI secrets: handles optional events
- Startup and setup → Notifications: configures
- Notifications → Webhook or chat: sends notifications
