Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

feat(controller): snapshot autoCreate/autoActivate switches + RBAC fixes - #5

Open
achetronic wants to merge 4 commits into
mainfrom
feat/controller-snapshot-enabler-switch
Open

feat(controller): snapshot autoCreate/autoActivate switches + RBAC fixes#5
achetronic wants to merge 4 commits into
mainfrom
feat/controller-snapshot-enabler-switch

Conversation

@achetronic

Copy link
Copy Markdown
Owner

What

Three changes in one branch:

1. Snapshot enabler switches

Two new boolean config fields in the controller snapshot section:

  • snapshot.autoCreate (default: true) — when false, the controller syncs resources to Vrata live config but never creates snapshots.
  • snapshot.autoActivate (default: true) — when false, snapshots are created but not activated. A human reviews and activates via the API.

The combination autoCreate: false + autoActivate: true is rejected at config validation. Both default to true for full backwards compatibility.

Use cases:

  • true/true — full autopilot (current default)
  • true/false — human approval gate
  • false/* — live config only, external snapshot management

2. RBAC for SuperHTTPRoute

ClusterRole was missing rules for vrata.io apiGroup. Conditional on controller.config.watch.superHttpRoutes.

3. RBAC for leader election Leases

ClusterRole was missing rules for coordination.k8s.io/leases. Conditional on controller.config.leaderElection.enabled.

Tests

All 17 unit tests pass (8 batcher + 9 config).

Magec added 4 commits March 21, 2026 21:18
Add two boolean config fields to the controller's snapshot section that
control whether the batcher creates and activates snapshots automatically:

- snapshot.autoCreate (default: true) — when false, the controller syncs
  resources to Vrata's live config but never creates snapshots. Pending
  changes are cleared without calling POST /snapshots.

- snapshot.autoActivate (default: true) — when false, snapshots are created
  but not activated. Proxies keep serving the previous active snapshot until
  a human activates the new one via the API.

The combination autoCreate=false + autoActivate=true is rejected at config
validation. Both fields default to true for full backwards compatibility.

Changes:
- config.go: AutoCreate/AutoActivate *bool fields on SnapshotConfig with
  helper methods and validation
- batcher.go: flushLocked respects both flags. Three code paths: skip
  snapshot entirely, create without activating, or create+activate (default)
- main.go: passes config values to batcher.New
- config.yaml: new fields with inline documentation
- values.yaml: Helm chart defaults
- configuration.md: docs with field reference table
- batcher_test.go: 3 new unit tests (one per mode)
- config_test.go: 4 new tests (defaults, explicit false, explicit true,
  invalid combo rejection)
- controller_test.go: e2e updated for new batcher signature
- CONTROLLER_DECISIONS.md: decision documented

All 17 unit tests pass (8 batcher + 9 config).
The ClusterRole only had rules for gateway.networking.k8s.io resources.
When controller.config.watch.superHttpRoutes was set to true, the
controller could not list/watch/get SuperHTTPRoute resources from the
vrata.io API group, nor update their status.

Add conditional RBAC rules for vrata.io/superhttproutes and
vrata.io/superhttproutes/status, gated behind the same
.Values.controller.config.watch.superHttpRoutes flag. When
superHttpRoutes is false (default), no extra rules are rendered.
The controller uses coordination.k8s.io/leases for leader election but
the ClusterRole had no rules for it. Enabling leaderElection.enabled
would result in 403 Forbidden when the controller tries to create or
renew its Lease.

Add conditional RBAC rules for coordination.k8s.io/leases (get, create,
update), gated behind .Values.controller.config.leaderElection.enabled.
Three new e2e tests covering the three snapshot mode combinations:

- TestE2E_Controller_SnapshotAutoCreateDisabled: applies an HTTPRoute,
  verifies the route exists in Vrata live config, but no snapshot was
  created (autoCreate=false).

- TestE2E_Controller_SnapshotAutoCreateTrue_AutoActivateFalse: applies
  an HTTPRoute, verifies a snapshot was created but is NOT active
  (autoCreate=true, autoActivate=false).

- TestE2E_Controller_SnapshotAutoCreateTrue_AutoActivateTrue: applies
  an HTTPRoute, verifies a snapshot was created AND activated
  (autoCreate=true, autoActivate=true — default behaviour).

Adds two e2e helpers:
- vrataCleanControllerSnapshots: removes all vrata-controller-* snapshots
- countControllerSnapshots: counts controller snapshots and checks active
achetronic added a commit that referenced this pull request Apr 6, 2026
achetronic added a commit that referenced this pull request Apr 6, 2026
Signed-off-by: Alby Hernández <donfumero@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant