Skip to content

proxy-syncer bug fix, but for a bug that never actually happens#13958

Merged
davidjumani merged 2 commits into
kgateway-dev:mainfrom
chandler-solo:chandler/perfect500nccopilotcomment
May 5, 2026
Merged

proxy-syncer bug fix, but for a bug that never actually happens#13958
davidjumani merged 2 commits into
kgateway-dev:mainfrom
chandler-solo:chandler/perfect500nccopilotcomment

Conversation

@chandler-solo

Copy link
Copy Markdown
Contributor

Description

Code cleanup only re: a copilot review comment on a backport of #13868 : #13947 (comment)

This bug cannot happen because there's always at least one cluster on k8s, but I prefer the "fixed" code.

Change Type

/kind cleanup

Changelog

NONE

Additional Notes

Code cleanup only.

Signed-off-by: David L. Chandler <[email protected]>
Copilot AI review requested due to automatic review settings April 30, 2026 21:36
@gateway-bot gateway-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none labels Apr 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Cleanup to make snapshotPerClient defensively publish snapshots even when the per-client cluster collection is empty/nil (a path that’s effectively unreachable in normal k8s clusters, but can exist in narrow edge cases), and to pin that behavior with a regression test.

Changes:

  • Treat a nil per-client cluster snapshot entry as “zero clusters” (instead of “not ready yet”) so publishing can proceed when there are no referenced backend clusters.
  • Add a unit test that constructs redirect-only routes (no cluster references) and asserts a snapshot is still published with an empty CDS.

Reviewed changes

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

File Description
pkg/kgateway/proxy_syncer/perclient.go Adjusts readiness gating logic so nil cluster inputs can be treated as empty clusters in edge cases.
pkg/kgateway/proxy_syncer/perclient_test.go Adds a test covering the redirect-only / zero-cluster publish path.

if clustersForUcc == nil {
clustersForUcc = &clustersWithErrors{
clusters: envoycache.Resources{
Items: map[string]envoycachetypes.ResourceWithTTL{},

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

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

When clustersForUcc is nil, the fallback initializes envoycache.Resources with an empty Items map but leaves Version empty. SnapshotCache.SetSnapshot typically validates snapshot consistency and may reject resources with missing versions, which would make this new “publish with zero clusters” path fail at runtime (and the error is currently ignored). Prefer constructing an explicit empty resources set with a non-empty version (e.g., via envoycache.NewResourcesWithTTL("0", nil) or by setting Version explicitly) so the resulting snapshot is always valid.

Suggested change
Items: map[string]envoycachetypes.ResourceWithTTL{},
Version: "0",
Items: map[string]envoycachetypes.ResourceWithTTL{},

Copilot uses AI. Check for mistakes.
"a snapshot must publish even when there are zero per-client clusters and zero referenced clusters")

snap := snapshots.List()[0].snap
g.Expect(snap.Resources[envoycachetypes.Cluster].Items).To(gomega.BeEmpty())

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

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

This new test exercises the “nil clusters => publish empty CDS” path, but it doesn’t assert that the generated Cluster resources have a non-empty Version. Adding an assertion for snap.Resources[envoycachetypes.Cluster].Version would help catch regressions where the snapshot becomes inconsistent and SetSnapshot rejects it.

Suggested change
g.Expect(snap.Resources[envoycachetypes.Cluster].Items).To(gomega.BeEmpty())
g.Expect(snap.Resources[envoycachetypes.Cluster].Items).To(gomega.BeEmpty())
g.Expect(snap.Resources[envoycachetypes.Cluster].Version).NotTo(gomega.BeEmpty())

Copilot uses AI. Check for mistakes.
@davidjumani
davidjumani added this pull request to the merge queue May 5, 2026
Merged via the queue into kgateway-dev:main with commit 3c926bb May 5, 2026
30 checks passed
Bbn08 pushed a commit to Bbn08/kgateway that referenced this pull request May 16, 2026
chandler-solo added a commit to chandler-solo/kgateway that referenced this pull request Jul 10, 2026
chandler-solo added a commit to chandler-solo/kgateway that referenced this pull request Jul 10, 2026
chandler-solo added a commit to chandler-solo/kgateway that referenced this pull request Jul 10, 2026
chandler-solo added a commit to chandler-solo/kgateway that referenced this pull request Jul 10, 2026
…way-dev#13958) in favor of a first-connect grace period (kgateway-dev#14380)

Signed-off-by: David L. Chandler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants