Skip to content

feat: Kubernetes ConfigMap watcher — event-driven config reload - #109

Merged
nfvelten merged 1 commit into
masterfrom
feat/k8s-configmap-watcher
Apr 6, 2026
Merged

feat: Kubernetes ConfigMap watcher — event-driven config reload#109
nfvelten merged 1 commit into
masterfrom
feat/k8s-configmap-watcher

Conversation

@nfvelten

@nfvelten nfvelten commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a kubernetes feature (on by default) that watches a named ConfigMap via the K8s API and hot-reloads Arbitus config on every Apply event — replacing the 30-second file polling loop with an event-driven reload
  • Extracts shared reload logic into src/reload.rs (build_live_config, reload_from_yaml) used by both the file hot-reload loop and the new ConfigMap watcher
  • Adds Config::from_yaml_str for parsing config from in-memory YAML (used by the watcher)
  • Helm: kubernetesWatcher.enabled: true provisions the Role + RoleBinding and injects the kubernetes: config block automatically

Usage

# values.yaml
kubernetesWatcher:
  enabled: true
  # configMapName defaults to the release fullname
  # namespace defaults to the pod's own namespace
  key: "gateway.yml"

Or directly in gateway.yml:

kubernetes:
  configmap_name: my-arbitus-config
  namespace: ai-agents   # optional, auto-detected from SA token
  key: gateway.yml

Test plan

  • cargo fmt --check passes
  • cargo clippy -- -D warnings passes
  • cargo test --lib — 419 tests pass
  • Deploy to a K8s cluster with kubernetesWatcher.enabled: true, update the ConfigMap, verify the gateway reloads within seconds without a restart

Closes #132

…es #132)

Watch a named ConfigMap via the K8s API and hot-reload Arbitus config on
every Apply event, replacing the 30-second file polling loop with an
event-driven reload.

- Add `src/kubernetes.rs` (behind the `kubernetes` feature, on by default):
  subscribes to a ConfigMap with kube-runtime watcher, calls `reload::reload_from_yaml`
  on Apply/InitApply events
- Add `src/reload.rs`: shared reload helpers (`build_live_config`, `reload_from_yaml`)
  used by both the file-based hot-reload loop and the ConfigMap watcher
- Add `Config::from_yaml_str` — parse config from an in-memory YAML string
  with env-var interpolation, overrides, and validation
- Add `KubernetesConfig` to `Config` (`kubernetes.configmap_name`, `.namespace`,
  `.key`); namespace defaults to the pod's own namespace via the SA token projection
- Refactor `do_reload` in `arbitus.rs` to delegate to `reload::reload_from_yaml`
- Add `kube 0.98` + `k8s-openapi 0.24/v1_31` as optional deps behind the
  `kubernetes` feature (default = on)
- Helm: add `kubernetesWatcher` values section; when enabled, inject the
  `kubernetes:` config block into `gateway.yml` and create Role + RoleBinding
  (get/list/watch on the target ConfigMap by resourceName)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nfvelten
nfvelten force-pushed the feat/k8s-configmap-watcher branch from c0885ca to 4f2af61 Compare April 6, 2026 19:50
@nfvelten
nfvelten merged commit 7062330 into master Apr 6, 2026
3 checks passed
@nfvelten
nfvelten deleted the feat/k8s-configmap-watcher branch April 6, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant