Skip to content

fix: remove redundant route.Hosts to prevent false diffs in ADC sync#2743

Merged
nic-6443 merged 3 commits intoapache:masterfrom
nic-6443:fix/remove-redundant-route-hosts
Apr 13, 2026
Merged

fix: remove redundant route.Hosts to prevent false diffs in ADC sync#2743
nic-6443 merged 3 commits intoapache:masterfrom
nic-6443:fix/remove-redundant-route-hosts

Conversation

@nic-6443
Copy link
Copy Markdown
Member

@nic-6443 nic-6443 commented Apr 10, 2026

Problem

The translator sets hosts on both Route and Service for ApisixRoute resources. Since APISIX routes inherit hosts from their parent service, the route-level hosts is redundant.

For backends that don't support route-level hosts, this causes a false diff every sync cycle: the local state has route.hosts but the remote state never does, triggering unnecessary PUT requests and audit log bloat.

Root Cause

In buildRoute() (internal/adc/translator/apisixroute.go), route.Hosts was set to rule.Match.Hosts. However, buildService() already sets service.Hosts to the same value. Since routes inherit hosts from their parent service, the route-level hosts is redundant and can cause false diffs during config sync.

Fix

Remove route.Hosts = rule.Match.Hosts from buildRoute(). service.Hosts remains as the canonical location for host matching.

CI Fix

Also fixes ADC binary extraction in CI workflows: the ghcr.io/api7/adc:dev Docker image now bundles main.cjs instead of main.js at the container root. Updated apisix-e2e-test.yml and benchmark-test.yml.

Testing

Added unit tests:

  • TestBuildRoute_HostsNotSet: verifies route.Hosts is not set after buildRoute
  • TestBuildService_HostsSet: verifies service.Hosts is correctly set

The translator was setting hosts on both Route and Service for ApisixRoute
resources. Since APISIX routes inherit hosts from their parent service,
the route-level hosts is redundant.

For backends that don't support route-level hosts, this causes a false
diff every sync cycle: the local state has route.hosts but the remote
state never does, triggering unnecessary PUT requests and audit log bloat.

Remove route.Hosts assignment; service.Hosts remains as the canonical
location for host matching.
Copilot AI review requested due to automatic review settings April 10, 2026 02:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes redundant hosts assignment at the route level for ApisixRoute translation to avoid persistent false diffs during ADC sync (especially for backends that don’t support route-level hosts).

Changes:

  • Stop setting route.Hosts from rule.Match.Hosts in buildRoute(), relying on service.Hosts as the canonical host matcher.
  • Add unit tests to verify route.Hosts is unset and service.Hosts remains correctly set.

Reviewed changes

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

File Description
internal/adc/translator/apisixroute.go Removes redundant route.Hosts assignment so host matching is represented only at the service level.
internal/adc/translator/apisixroute_test.go Adds tests asserting route.Hosts is not populated and service.Hosts is populated from rule.Match.Hosts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nic-6443
Copy link
Copy Markdown
Member Author

CI Status: lint ✅, unit tests ✅, misspell ✅, CRD docs ✅, license check ✅

The e2e test failures are a pre-existing infrastructure issue — the ADC dev Docker image (ghcr.io/api7/adc:dev) no longer has main.js at the container root, causing the "Extract adc binary" step to fail with Could not find the file main.js in container adc-temp. This is unrelated to the changes in this PR.

The ghcr.io/api7/adc:dev Docker image now bundles main.cjs instead
of main.js at the container root. Update all workflow files that
extract the ADC binary via docker cp.
@nic-6443
Copy link
Copy Markdown
Member Author

Pushed CI fix: updated main.jsmain.cjs in apisix-e2e-test.yml and benchmark-test.yml to match the updated ghcr.io/api7/adc:dev Docker image layout. The e2e tests should now pass the ADC binary extraction step.

@nic-6443
Copy link
Copy Markdown
Member Author

CI Status update: All APISIX E2E Tests ✅ (7/7 jobs passed), all conformance tests ✅, lint ✅, unit tests ✅, CodeQL ✅, license ✅.

The only failure is e2e-test (apisix-standalone) in the Benchmark Test workflow — APISIX returns 500 Internal Server Error on ListServices during test scaffold setup. This is an infrastructure issue (APISIX standalone not properly initialized), unrelated to the route.Hosts removal in this PR.

In APISIX standalone mode, config application via /apisix/admin/configs
is async (returns 202). Two tests asserted HTTP status immediately after
config push without retry, causing intermittent 404s:

- Basic test: direct assertion on /headers after route update
- WebSocket test: direct dial+sleep assertion after route creation

Replace direct assertions with Eventually retry (20s timeout, 1s interval)
to match the pattern used elsewhere in the test suite.
@nic-6443
Copy link
Copy Markdown
Member Author

Pushed e2e test fix: replaced 2 direct HTTP assertions with Eventually retry in test/e2e/crds/v2/route.go.

Root cause: In APISIX standalone mode, config application via /apisix/admin/configs is async (202 response). The Basic test and WebSocket test asserted HTTP status immediately after config push without retry, causing intermittent 404s when APISIX hadn't applied the new config yet.

Fix: Use Eventually with 20s timeout + 1s polling (same pattern as other assertions in the test suite).

The previous Benchmark test failure (APISIX 500 on ListServices) was an infrastructure issue — APISIX standalone failed to initialize. This should resolve on re-run.

@nic-6443 nic-6443 merged commit 0d225ad into apache:master Apr 13, 2026
26 checks passed
@nic-6443 nic-6443 deleted the fix/remove-redundant-route-hosts branch April 13, 2026 08:32
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.

5 participants