Skip to content

[template]: Add hostPort/serverName templating#53

Open
pseudomuto wants to merge 1 commit into
mainfrom
host_templating
Open

[template]: Add hostPort/serverName templating#53
pseudomuto wants to merge 1 commit into
mainfrom
host_templating

Conversation

@pseudomuto

Copy link
Copy Markdown
Collaborator

Upstream definitions (RFC #32) template their hostPort and serverName with request-derived values so one upstream can serve many namespaces, e.g. "{{ .RemoteNamespace }}.acme-cloud.tmprl.cloud:7233". This adds internal/template, a thin wrapper over text/template that compiles a template once and renders it against a per-request context.

Templates are bound to the context they render against. ParseRouting renders against a RoutingContext (local namespace and metadata), used while routing rules pick an upstream; ParseUpstream adds RemoteNamespace, which is only known after an upstream is selected since translation is per-upstream. Binding the type means a routing template that references RemoteNamespace fails at parse time rather than silently rendering empty.

Parsing validates by rendering against a probe context, so an unknown field (a typo) is caught at config-load. Absent metadata keys render empty rather than erroring, since the available keys are only known at request time. Must wraps a Parse call for package-level vars and tests.

@pseudomuto pseudomuto requested a review from a team as a code owner June 30, 2026 19:20
@pseudomuto pseudomuto requested a review from Copilot June 30, 2026 19:20
@codecov-commenter

codecov-commenter commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.91%. Comparing base (ad23f91) to head (a190449).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   85.12%   85.91%   +0.79%     
==========================================
  Files          33       34       +1     
  Lines        1042     1065      +23     
==========================================
+ Hits          887      915      +28     
+ Misses        131      128       -3     
+ Partials       24       22       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a small internal templating helper to support request-scoped rendering of upstream hostPort / serverName fields (and routing-time templating) while keeping templates bound to the specific context available at each phase.

Changes:

  • Introduces internal/template with typed RoutingContext and UpstreamContext plus a generic compiled Template[T].
  • Adds parse-time validation by probing templates during ParseRouting / ParseUpstream, and provides a Must helper for tests/package-level vars.
  • Adds unit tests and package documentation describing the supported fields and scoping rules.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/template/template.go Implements typed template parsing/rendering and probe-based validation.
internal/template/template_test.go Adds coverage for upstream vs routing context rendering and validation behavior.
internal/template/doc.go Documents template usage, contexts, and scoping expectations.

Comment thread internal/template/template.go
Comment thread internal/template/template.go
Comment thread internal/template/doc.go
Upstream definitions (RFC #32) template their hostPort and serverName with
request-derived values so one upstream can serve many namespaces, e.g.
"{{ .RemoteNamespace }}.acme-cloud.tmprl.cloud:7233". This adds internal/template,
a thin wrapper over text/template that compiles a template once and renders it
against a per-request context.

Templates are bound to the context they render against. ParseRouting renders
against a RoutingContext (local namespace and metadata), used while routing
rules pick an upstream; ParseUpstream adds RemoteNamespace, which is only known
after an upstream is selected since translation is per-upstream. Binding the
type means a routing template that references RemoteNamespace fails at parse
time rather than silently rendering empty.

Parsing validates by rendering against a probe context, so an unknown field
(a typo) is caught at config-load. Absent metadata keys render empty rather
than erroring, since the available keys are only known at request time. Must
wraps a Parse call for package-level vars and tests.
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.

3 participants