Skip to content

fix(gatewayapi): retry wasm cache startup until its TLS config loads - #10337

Open
SaiPisey2 wants to merge 7 commits into
envoyproxy:mainfrom
SaiPisey2:fix/wasm-cache-retry
Open

SaiPisey2 wants to merge 7 commits into
envoyproxy:mainfrom
SaiPisey2:fix/wasm-cache-retry

Conversation

@SaiPisey2

@SaiPisey2 SaiPisey2 commented Oct 20, 2026 •

Copy link
Copy Markdown

What this PR does / why we need it:

startWasmCache called loadTLSConfig once. If the HMAC secret could not be read at that moment (a transient API error, or the secret not created yet), it logged failed to start wasm cache and returned, so the cache stayed nil and every EnvoyExtensionPolicy with an HTTP or Image Wasm source was rejected with wasm cache is not initialized until the controller restarted.

  • Start now starts the Wasm cache before the translation goroutine, so translation never sees a nil cache.
  • On Kubernetes, loadTLSConfig is retried with backoff (1s doubling to a 5s cap) for up to 30s, which covers a brief API server outage. Each retry logs failed to start wasm cache, retrying. In host mode the HMAC secret and certs are local files, so there is no retry.
  • If the cache still cannot start, Start returns the error. startRunners then stops the runners already started and the controller exits, so a missing or unreadable envoy-oidc-hmac shows up as a restarting pod with the cause in the logs. A shutdown during the retries is not reported as a failure.
  • A provider with no TLS config for the cache (neither Kubernetes nor host) starts without it, as before.

Behaviour changes to be aware of:

  • Installs where the controller can never read envoy-oidc-hmac now crash-loop instead of only rejecting HTTP/Image Wasm policies. For example: the certgen hook is skipped, or (unverified, needs a cluster) watch.type=Namespaces with an explicit namespace list, where the chart grants no secrets read in the controller namespace.
  • A config reload also exits if the secret has become unreadable since startup.
  • Runners start in order, so while Start retries, the xds, infra, admin and metrics runners start up to 30s later. Running proxies keep their config. /healthz is served by the provider, so the startup and liveness probes are not affected.

Tested on kind (with an earlier version of this branch; the unit tests below cover the current one) with the controller built from main and from this branch: delete envoy-oidc-hmac, restart the controller, restore the secret 20s later.

main this PR
policy after the secret is restored Accepted=False, wasm cache is not initialized Accepted=True ~8s later
wasm route 500 until restart 200
plain route 200 200

TestWasmPolicyAcceptedWhenSecretArrivesDuringStart covers the transient case through Runner.Start: the secret appears during the retries and the policy is accepted. TestStartFailsWhenWasmCacheCannotStart covers the permanent case. Both fail on main.

Not changed here: while the cache is not started, a policy with failOpen: true is still rejected, because the wasm cache is not initialized check runs before failOpen is looked at. That was already the case before this PR and could be a follow-up.

Which issue(s) this PR fixes:

Fixes #10267


PR Checklist

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s). See DCO: Sign your work.
  • API agreed first: N/A, no API changes.
  • Required checks pass: make generate gen-check, make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, but gen-check, lint, and coverage MUST pass.)
  • Tests added/updated: New/changed code is covered by appropriate tests. N/A if this PR does not contain code changes.
  • Docs: N/A, no user-facing configuration change.
  • Release notes: For any non-trivial change, added a release-note fragment under release-notes/current/<section>/<pr-number>-<slug>.md (see release-notes/current/README.md for sections and naming). N/A if this PR does not contain non-trivial changes.
  • Generated files committed: N/A, no API, helm chart or module changes.
  • Scope & compatibility: The PR is reasonably scoped (no unrelated changes) and preserves backward compatibility, or any breaking change is called out above and documented in release-notes/current/breaking_changes/.
  • Codex review: Requested a Codex review and addressed all of its comments.
  • Copilot review: Requested a Copilot review and addressed all of its comments.

@SaiPisey2
SaiPisey2 requested a review from a team as a code owner October 20, 2026 14:05
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T01:38:59.188008Z f97857e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cerulean-figolla-1f9435 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f97857e
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6b0f75d5baeed8b1cb010923
😎 Deploy Preview https://deploy-preview-10337--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55654c807d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Fixes envoyproxy#10267

Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>
Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>
Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>
@zirain
zirain force-pushed the fix/wasm-cache-retry branch from b477cfa to 034bb77 Compare October 21, 2026 01:29

@erikdeweerdt erikdeweerdt 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.

Thanks for this, it's the fix we were hoping for. A few points:

  1. Backoff cap. A controller that holds the leader lease starts translating as soon as the API server answers again. Any policy translated before the cache comes up keeps the 500 direct response until the replay. With a 30 s cap, that window can approach 30 s after the Secret becomes readable during a longer outage. Could the cap be a few seconds instead? Or could the retry also run as soon as the provider sees the envoy-oidc-hmac Secret, which it already watches?
  2. Log message. A failed start used to log failed to start wasm cache; it now logs failed to load wasm cache TLS config, retrying. Anyone alerting on the old line loses that signal. Keeping the old wording in the retry message, or noting the change in the release note, would avoid that.
  3. failOpen while retrying. buildWasms still returns wasm cache is not initialized before it looks at failOpen. So a failOpen: true policy still gets the 500 direct response during the retry window, unlike a module fetch failure. Fine as a follow-up, but worth a line in the PR or the release note if it's out of scope.

The replay in retranslateOnWasmCacheReady looks right to me. A snapshot that arrives after the cache is ready is forwarded without a replay, and the deep copy keeps the translator off the original values.

Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>
@SaiPisey2

Copy link
Copy Markdown
Author

@erikdeweerdt thanks for the review. Lowered the cap to 5s and put the old failed to start wasm cache wording back in the retry log (d893547). Reacting to the envoy-oidc-hmac watch would recover faster still, but I kept that out of this PR. failOpen still returns the 500 while the cache is down, same as before this change; I've noted that in the PR and the release note as a follow-up.

@erikdeweerdt

Copy link
Copy Markdown

LGTM; thanks!

@SaiPisey2

Copy link
Copy Markdown
Author

@zirain could you approve the CI workflows when you get a chance? They're waiting on approval for d893547, and @erikdeweerdt has signed off on the changes.

@SaiPisey2

Copy link
Copy Markdown
Author

@zhaohuabing could you approve the CI run and take a look? It has an LGTM from @erikdeweerdt and merges cleanly.

@zirain
zirain requested a review from zhaohuabing November 12, 2026 00:52
zirain
zirain previously approved these changes Nov 12, 2026
Comment thread internal/gatewayapi/runner/runner.go Outdated
// is ready, it replays the latest state so that resources translated without the
// cache, such as EnvoyExtensionPolicies with HTTP or Image Wasm sources, recover
// without waiting for an unrelated resource change.
func (r *Runner) retranslateOnWasmCacheReady(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we just hold off translation until the Wasm cache is ready? It's required infra like the rate limit service.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I tried it. Holding off translation until the cache starts is simpler and drops the replay goroutine. One catch before I push it.

On Kubernetes, if envoy-oidc-hmac can never be read, translation never starts. That happens if the secret is missing (certgen hooks skipped), RBAC denies get on it, or the client config fails. No Gateway status, no xDS for new Envoy pods, and only an error log every 5s. I reproduced it in a unit test: nothing translated after 12s. On main the same case only rejects Wasm HTTP/Image policies, and the provider also treats a missing HMAC secret as non-fatal.

Which would you prefer?

  1. Hold off with no limit, as you suggested, and document that the HMAC secret is now required for any translation.
  2. Hold off for a bounded time (say 30s). After that, translate without the cache and keep retrying, then translate again once the cache starts. This keeps the replay from the current version.

I lean towards 2, but I'm happy to go with 1 if you see the secret as required anyway.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for trying it. Either option fixes the outage we hit:

  • With option 1, proxies that already have config keep serving it while translation waits, so routes behind a fail-closed Wasm policy never get the 500 direct response.
  • With option 2, the same holds for outages shorter than the hold. After a longer one, the 500s last only until the next retry and the replay.

What I'd avoid is option 1's failure mode for installs that use no HTTP or Image Wasm source at all. An unreadable envoy-oidc-hmac doesn't affect them today; with option 1 it would stop all translation, with only a log line to show for it. (We run a startup probe on the Wasm cache port, so for us a cache that never starts becomes a visible restart loop, but the default chart has nothing like that.)

So I'd go with option 2, or with option 1 only when some EnvoyExtensionPolicy uses an HTTP or Image Wasm source, if that's easy to tell at that point. Either way, please keep failed to start wasm cache in the retry log.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's go with option 1. A short API server error is covered by the retry. A long one fails the liveness probe and restarts the pod, which reads the secret again. That leaves an install error as the only way it stays stuck, and that should fail loudly. Please keep failed to start wasm cache in the retry log.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 92b6abc. Translation now waits for the Wasm cache, and the replay goroutine is gone. The retry log still says failed to start wasm cache, retrying. A provider with no TLS config for the cache (neither Kubernetes nor host) skips the wait. The release note says the HMAC secret must be readable before anything is translated. Thanks @erikdeweerdt for the startup-probe context.

@zhaohuabing
zhaohuabing requested a review from a team November 16, 2026 09:24
Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.86%. Comparing base (14b50dc) to head (f97857e).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
internal/gatewayapi/runner/runner.go 98.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10337      +/-   ##
==========================================
+ Coverage   82.82%   82.86%   +0.03%     
==========================================
  Files         279      279              
  Lines       44665    44703      +38     
==========================================
+ Hits        36993    37041      +48     
+ Misses       7671     7661      -10     
  Partials        1        1              

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread internal/gatewayapi/runner/runner.go Outdated
Comment on lines +193 to +201
// The Wasm cache is required to translate EnvoyExtensionPolicies with HTTP
// or Image Wasm sources, so hold off translation until it has started.
// Updates received meanwhile are coalesced by the subscription.
select {
case <-r.wasmCacheDone:
default:
r.Logger.Info("waiting for the wasm cache to start before translating resources")
<-r.wasmCacheDone
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This wait ends only when startWasmCache returns, and with the retry loop it may never return. For example, if the envoy-oidc-hmac secret is missing, EG keeps retrying, nothing gets translated, and the pod still looks healthy. The Wasm cache is infra EG depends on, so I'd rather fail loudly than wait quietly.

How about calling startWasmCache from Start before the translation goroutine starts, with a time-limited retry for brief API server outages, and returning its error? startRunners already exits when a runner's Start returns an error, so the pod would crash-loop with the cause in the logs. That also keeps translation from seeing a nil cache, so wasmCacheDone wouldn't be needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 95e85dc. Start starts the cache before the translation goroutine and returns the error if it can't, so wasmCacheDone is gone. On Kubernetes it retries for up to 30s and logs failed to start wasm cache, retrying. Host mode doesn't retry, since the secret is a local file. That also keeps TestCustomProviderFailedToStart at 0.2s instead of 30s. A shutdown during the retries returns nil, not a startup error.

Two side effects, both in the PR description:

  • Runners start in order, so xds, infra, admin and metrics come up as much as 30s later while it retries. /healthz comes from the provider, so the probes don't notice.
  • Installs where the controller can't read envoy-oidc-hmac now crash-loop. I think that includes watch.type=Namespaces with an explicit list, because the chart grants no secret read in the controller namespace there. I haven't checked it on a cluster. Should the chart add that read?

Signed-off-by: SaiPisey2 <piseysai0202@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95e85dc52c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// The Wasm cache is required to translate EnvoyExtensionPolicies with HTTP or
// Image Wasm sources, so start it before translating anything. If it cannot
// be started, fail so the error shows up as a restarting pod.
if err := r.startWasmCache(ctx); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep pods unready until blocked xDS startup completes

When envoy-oidc-hmac is missing but the Kubernetes provider cache syncs normally, this synchronous wait blocks the sequential runner loop before xdsrunner is started (internal/cmd/server.go:232-256,331-337). The provider has already brought up /readyz, whose only check is cache sync (internal/provider/kubernetes/kubernetes.go:396-398), so the pod can become a ready endpoint for the Service's ports 18000/18002 while neither xDS nor the Wasm listener exists, for as long as the 30-second retry (and on every restart if the secret stays absent). Connections can then be routed to a connection-refusing pod; keep readiness false until this startup step and the downstream listeners complete.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an existing issue: /readyz only checks the informer cache sync, not whether the xDS and Wasm listeners are up. This PR makes the gap longer, but the real fix is to make /readyz report ready only once EG can actually serve proxies. Let's handle that in a follow-up.

@zhaohuabing zhaohuabing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM thanks.

@SaiPisey2

Copy link
Copy Markdown
Author

Thanks @zhaohuabing! The red checks look unrelated to this change. BackendTLSPolicySANValidation and the merge-backends e2e are outside the runner, and Build and Test failed in 3 of the last 5 runs on main. OSV-Scanner passes on main, so it probably just needs a run on the current config. Could someone re-run the failed jobs?

@zhaohuabing

Copy link
Copy Markdown
Member

Thanks @zhaohuabing! The red checks look unrelated to this change. BackendTLSPolicySANValidation and the merge-backends e2e are outside the runner, and Build and Test failed in 3 of the last 5 runs on main. OSV-Scanner passes on main, so it probably just needs a run on the current config. Could someone re-run the failed jobs?

Yes, they're unrelated.

Could you please merge main and fix the conflicts?

@zhaohuabing

Copy link
Copy Markdown
Member

/retest

This branch has not been deployed

No deployments
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.

Transient API error at startup leaves the Wasm cache uninitialized until the controller restarts ("wasm cache is not initialized")

4 participants