feat(routing): emit BackendTrafficPolicy when routing.streaming is true#123
Closed
viniciusdc wants to merge 1 commit into
Closed
feat(routing): emit BackendTrafficPolicy when routing.streaming is true#123viniciusdc wants to merge 1 commit into
viniciusdc wants to merge 1 commit into
Conversation
Adds an opt-in routing.streaming field on RoutingConfig and a new StreamingReconciler that emits a single Envoy Gateway BackendTrafficPolicy targeting every operator-owned HTTPRoute for the NebariApp (main route always, public route when publicRoutes is set). The policy disables Envoy's default 15s HTTP request timeout and sets the connection idle timeout to 5 minutes — fixed canned values rather than exposing Envoy-typed knobs on the CRD. When routing.streaming is false or absent, the reconciler deletes any policy it previously owned and clears the StreamingReady condition. Foreign-policy detection: if a BackendTrafficPolicy already exists in the namespace under the operator's chosen name without our owner reference, the reconciler refuses to overwrite it and surfaces StreamingReady=False (ForeignPolicyExists) instead. Failure modes (CRD missing, foreign policy, apiserver errors) degrade gracefully via StreamingReady=False without blocking the rest of the reconcile. Adds RBAC for gateway.envoyproxy.io/backendtrafficpolicies, wires the new reconciler into the main controller, and adds unit tests covering the create / update / delete / public-routes / foreign cases. Design rationale: docs/design/streaming-timeouts.md.
Collaborator
Author
|
Closing — design needs more thought. Branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the design in #122 (stacked on top of that PR — base will switch to
mainonce #122 merges). Independent of PR #120 / #121 (multi-port routes); the two feature pairs are orthogonal and can land in either order.RoutingConfig.Streaming bool(default false). When true, the operator emits a single Envoy GatewayBackendTrafficPolicynamed<app>-streamingin the NebariApp's namespace, owner-referenced for GC.publicRoutesis set), so SSE / long-poll / gRPC streams aren't cut by Envoy's 15s defaultrequestTimeout. Fixed canned values:requestTimeout: 0s,connectionIdleTimeout: 300s.StreamingReconcilerininternal/controller/reconcilers/routing/streaming.go, paralleling the existing routing / TLS / auth reconcilers. Wired into the main controller after the public-route reconcile (so the policy'stargetRefsresolve).StreamingReadycondition surfaces state without blocking the rest of the reconcile:True (PolicyReconciled)— policy is in sync.False (ForeignPolicyExists)— aBackendTrafficPolicyalready exists under our chosen name without our owner ref. We refuse to overwrite.False (CRDMissing)— Envoy GatewayBackendTrafficPolicyCRD not installed in the cluster. Rest of reconcile continues; only the streaming guarantee is degraded.False (ReconcileFailed)— apiserver error.streamingis unset/false (no noise on every NebariApp).Files touched
api/v1/nebariapp_types.go— addRoutingConfig.Streaming,ConditionTypeStreamingReady, fourEventReasonBackendTrafficPolicy*constants.internal/controller/reconcilers/routing/streaming.go— new reconciler (253 lines).internal/controller/reconcilers/routing/streaming_test.go— 5 test cases covering disabled / enabled / public-routes / transition-to-disabled / foreign-policy.internal/controller/nebariapp_controller.go— wireStreamingReconciler, addreconcileStreaminghelper to keep the mainReconcileunder gocyclo's 30 ceiling, add kubebuilder RBAC marker forbackendtrafficpolicies.internal/controller/utils/conditions/conditions.go— newRemoveConditionhelper (used when streaming flips back to disabled).internal/controller/utils/constants/constants.go—BackendTrafficPolicySuffix = \"streaming\".internal/controller/utils/naming/naming.go—BackendTrafficPolicyName(...), added toValidateResourceNames.cmd/operator/main.go— instantiate the new reconciler and wire it intoNebariAppReconciler.config/crd/bases/reconcilers.nebari.dev_nebariapps.yaml,config/rbac/role.yaml,docs/api-reference.md.Why a boolean, not Envoy timeout knobs
Documented at length in #122. Short version: contract independence (CRD shouldn't pin to Envoy-typed fields), canned values match every streaming workload anyone has asked for, and widening to a
streamingTimeouts: { requestTimeout, idleTimeout }struct later is additive.Backwards compatibility
routing.streamingis additive, optional, default false.BackendTrafficPolicy(e.g. `openteams-ai/nebari.openteams.ai#12`) migrate by settingrouting.streaming: trueand deleting their hand-rolled YAML. If they hit the operator's chosen name (<app>-streaming) before deleting, the reconciler refuses to overwrite and reportsForeignPolicyExists.Test plan
go build ./...passesgo vet ./...cleanmake lint(golangci-lint) — 0 issues (after extractingreconcileStreaminghelper to keep mainReconcileunder the gocyclo ceiling)make generate-devregenerates CRD, RBAC, and deepcopy cleanlymake docsregeneratesapi-reference.mdcleanlyTestStreamingReconciler_{DisabledCreatesNoPolicy,EnabledCreatesPolicy,EnabledWithPublicRoutesTargetsBoth,TransitionToDisabledDeletesPolicy,RefusesForeignPolicy}— all greenTestControllers(envtest-based) — pre-existing failure onmain(should successfully reconcile the resource), reproduces with no code changes. Not introduced by this PR.streaming: true, and gets cut at 15s whenstreaming: falseRelated