Autoconf service
Autoconf is a controller-based service that discovers BunkerWeb instances and protected services from an external orchestrator. It turns that observed state into shared configuration records so the scheduler can generate and reload the active proxy configuration.
Service role
Autoconf connects the orchestrator's service description to BunkerWeb's shared database. It does not serve traffic itself. Its main responsibility is to keep the database view of instances, services, settings, and custom configuration aligned with the current orchestrator state.
The service selects one discovery controller at startup:
| Environment state | Discovery source |
|---|---|
| Swarm mode enabled | Docker Swarm services and configs |
| Kubernetes mode with Gateway API enabled | Kubernetes Gateway and Route resources |
| Kubernetes mode enabled | Kubernetes Ingress resources |
| No cluster mode enabled | Docker containers and labels |
The parent page, Configuration orchestration, describes how this service fits into the wider configuration system.
Discovery sources
Docker discovery
Docker mode treats labeled containers as both BunkerWeb instances and protected services. Container labels carry service settings and custom configuration references. The controller watches relevant container lifecycle events and ignores unrelated activity.
Swarm mode uses the same service model but reads from Swarm services and Docker configs. Swarm support is deprecated, so new orchestration work should prefer the Kubernetes or Docker path that matches the deployment model.
References: src/…/DockerController.py• L53-191 src/…/SwarmController.py• L57-183
Kubernetes discovery
Kubernetes mode treats ready BunkerWeb Pods as instances and turns routing resources into protected services. The Ingress controller reads Ingress rules, backend Services, annotations, and TLS Secrets. The Gateway controller reads Gateway API resources and their attached HTTP, gRPC, TCP, UDP, or TLS routes.
The controller filters by namespace, ignored annotations, and Gateway ownership rules when configured. Gateway listeners select compatible route kinds and can supply host names, ports, and TLS Secrets. The controller also watches ConfigMaps and Secrets because those resources can change settings, custom configuration, or certificates without changing the route object.
When Gateway API status support is available, Autoconf reports accepted and programmed state for the Gateway resources it owns. It preserves status entries from other controllers, and it ignores watch events caused only by its own status writes so those writes do not trigger needless configuration work.
References: src/…/KubernetesController.py• L363-498 src/…/KubernetesController.py• L518-569 src/…/GatewayController.py• L381-462 src/…/GatewayController.py• L588-625 src/…/GatewayController.py• L744-1023 src/…/GatewayController.py• L1144-1264
Configuration model
Autoconf keeps one normalized model regardless of the discovery source. An instance describes a BunkerWeb runtime that can receive generated configuration. A service describes a site or stream endpoint and its settings. Custom configurations hold extra files grouped by their configuration type.
The model has four main inputs:
- Instances: discovered BunkerWeb runtimes and their health state.
- Services: protected hosts plus service-scoped settings.
- Custom configurations: supported HTTP, stream, server, ModSecurity, and CRS files.
- Extra settings: Kubernetes ConfigMap settings that pass database validation before they enter the shared configuration.
Settings are validated against the current plugin setting set. Invalid values are ignored instead of being sent to the scheduler. Service settings become global or service-prefixed values according to the setting rules and the discovered service names.
Reconciliation flow
Autoconf waits for a usable starting state, applies the current snapshot, then reconciles later changes. It compares the new snapshot with the last applied snapshot so an event that does not change configuration does not cause a new deployment.
The flow moves from external resources to the database and then to scheduler work:
flowchart LR
A[Orchestrator resources] --> B[Mode-specific controller]
B --> C[Normalized instances, services, and configs]
C --> D[Database]
D --> E[Scheduler change flags]
E --> F[Generated BunkerWeb configuration]
F --> G[Reloaded proxy instances]
Each controller batches nearby events before it reconciles. The Kubernetes path merges route or Ingress records that share a primary host, retries a missing backend Service with bounded backoff, and retries deferred applies when the scheduler was busy or a save failed. Its watches restart after normal timeouts or expired resource versions. A watch that exhausts its retries removes its health marker so the health check can restart the service.
References: src/…/Controller.py• L96-197 src/…/KubernetesController.py• L251-361 src/…/KubernetesController.py• L651-825 src/…/KubernetesController.py• L841-979
Startup behavior
The service wrapper prepares shared data, loads Docker secrets, records the selected integration, and starts the Autoconf process. It forwards stop signals to the child process, waits for it to exit, and removes the health marker during shutdown.
The service first loads secrets and selects its controller. It waits until the database is initialized, no scheduler apply is in flight, at least one BunkerWeb instance exists, and each discovered instance is ready according to the selected controller.
After the wait, Autoconf reads instances, services, and custom configuration. It performs an initial apply even when the orchestrator has not emitted a new event. A successful apply marks Autoconf as loaded in database metadata. The health marker is written only when event processing starts.
If the database is temporarily read-only, Autoconf can keep reading state but does not save new configuration until the connection returns to write mode. A failed initial save leaves the scheduler able to use older configuration, so the failure is logged as a startup warning.
References: src/…/entrypoint.sh• L8-73 src/…/main.py• L21-85 src/…/Controller.py• L96-121 src/…/Controller.py• L173-197 src/…/Config.py• L155-174 src/…/Config.py• L275-302
Shared service integration
Autoconf and the scheduler coordinate through the shared database rather than through a direct process call. Autoconf saves the current configuration, custom files, and instance list. It then marks the related database changes as checked while preserving the change metadata that tells the scheduler what work is needed.
The scheduler reads those metadata flags on its main loop. Instance changes require the broadest regeneration because they can affect plugins, custom files, generated configuration, and the proxy reload. Custom configuration changes regenerate the affected custom files and the final configuration. Plugin setting changes trigger configuration generation and job work.
This relationship is part of the scheduler lifecycle described in Scheduler jobs: Autoconf supplies desired state, while the scheduler turns that state into running BunkerWeb behavior.
References: src/…/Config.py• L220-273 src/…/Database.py• L989-1045 src/…/main.py• L1834-1919 src/…/model.py• L345-374
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the controller output shape aligned with the configuration model for instances, services, custom files, and extra settings.
- Keep each discovery source's event filters aligned with its initial listing rules. Otherwise a resource can be discovered at startup but never trigger a later apply.
- Keep database change flags aligned with the scheduler's generation paths. A saved value without the matching flag can remain inactive.
- Keep Kubernetes ConfigMap, Secret, Service, and Gateway API watches aligned with the resource types used to build settings, backends, TLS data, and status.
- Keep Gateway status ownership and status-only event filtering aligned. Status writes must not overwrite another controller or start a configuration loop.
- Keep per-watch health markers and entrypoint cleanup aligned with the health check. A stale marker can hide a failed watch or report a stopped process as healthy.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Database is not initialized or the scheduler is applying | Autoconf delays discovery or reconciliation | Startup and event paths wait on database metadata before saving |
| No BunkerWeb instance is discovered | Autoconf keeps waiting and does not begin event processing | Controller startup requires at least one ready instance |
| A route refers to a missing Kubernetes backend | That route is omitted from the current service model | Kubernetes records the backend for bounded retry and re-applies when it appears |
| Gateway API status permission is missing | Configuration still works, but Gateway status does not show current ownership or apply state | Status writes are separate from configuration and log the permission failure |
| Database remains read-only | New state is not saved and active configuration can stay stale | Database connection recovery is retried and the failure is logged |
| A Kubernetes watch exhausts its retries | The affected resource changes stop reaching Autoconf | The per-watch health marker is removed so the health check can restart the service |
| The entrypoint receives a stop signal during child startup | The child can be left running or the wrapper can start it after shutdown was requested | The wrapper records the stop request, signals the child, waits for exit, and clears health state |
Key files
| File | Why to read it |
|---|---|
| src/…/main.py | Shows mode selection, startup sequencing, and the transition into event processing. |
| src/…/entrypoint.sh | Shows process startup, integration marking, signal forwarding, and health cleanup. |
| src/…/Controller.py | Defines the shared controller lifecycle and normalized discovery contract. |
| src/…/Config.py | Explains the configuration model, validation, database save, and change signaling. |
| src/…/DockerController.py | Shows label-based discovery for standalone Docker deployments. |
| src/…/KubernetesController.py | Shows Kubernetes discovery, watch recovery, reconciliation, and backend retry behavior. |
| src/…/IngressController.py | Shows how Ingress resources become protected services. |
| src/…/GatewayController.py | Shows how Gateway API routes become protected services and how owned resources receive status state. |
| src/…/Database.py | Defines the shared metadata contract used by Autoconf and the scheduler. |
| src/…/main.py | Shows how Autoconf's database changes become generation and reload work. |
| src/…/healthcheck-autoconf.sh | Defines the health signal used to detect failed discovery watches. |