Skip to content

feat: support upstream health checks in BackendTrafficPolicy#2763

Merged
AlinsRan merged 10 commits into
apache:masterfrom
AlinsRan:feat/backendtrafficpolicy-healthcheck-backport
May 18, 2026
Merged

feat: support upstream health checks in BackendTrafficPolicy#2763
AlinsRan merged 10 commits into
apache:masterfrom
AlinsRan:feat/backendtrafficpolicy-healthcheck-backport

Conversation

@AlinsRan

Copy link
Copy Markdown
Contributor

Summary

This PR adds health check support to BackendTrafficPolicy, allowing users to configure active and passive health checks for upstream backends directly through the BackendTrafficPolicy resource.

Changes

New API types (api/v1alpha1/backendtrafficpolicy_types.go)

  • Added HealthCheck struct with Active and Passive fields to BackendTrafficPolicySpec
  • ActiveHealthCheck: configures HTTP/TCP probes with configurable interval, timeout, thresholds, and TLS settings
  • PassiveHealthCheck: configures passive (observational) health monitoring with configurable thresholds
  • Timeouts field uses BackendTrafficPolicyTimeouts struct (renamed json tag from timeout to timeouts for consistency)

Translation (internal/adc/translator/policies.go)

  • Translates BackendTrafficPolicy.Spec.HealthCheck into APISIX upstream checks configuration
  • Active health check intervals are clamped to a minimum of 1 second (APISIX requirement)
  • Supports both HTTP and TCP active health check types
  • Maps all threshold fields: healthy/unhealthy HTTP statuses, TCP success/failure counts

CRD regeneration

  • Updated config/crd/bases/apisix.apache.org_backendtrafficpolicies.yaml with health check schema
  • Updated deepcopy functions

E2E tests (test/e2e/crds/v1alpha1/backendtrafficpolicy.go)

  • End-to-end tests covering:
    • Active HTTP health check configuration (interval, timeout, thresholds, HTTP path)
    • Active TCP health check configuration
    • Passive health check configuration
    • Health check deletion (verifies checks are removed from upstream)

Example

apiVersion: apisix.apache.org/v1alpha1
kind: BackendTrafficPolicy
metadata:
  name: my-policy
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: my-route
  healthCheck:
    active:
      type: HTTP
      interval: 10s
      timeout: 3s
      httpPath: /healthz
      healthy:
        httpStatuses: [200, 201]
        successes: 3
      unhealthy:
        httpStatuses: [500, 502, 503]
        httpFailures: 3

AlinsRan and others added 10 commits May 14, 2026 04:14
- Fix Timeouts field JSON tag: timeout -> timeouts to match ADC type
- Enforce minimum 1s interval in translateBTPActiveHealthCheck to prevent
  sub-second values from truncating to 0 (matching v2/apisixupstream behavior)
- Scope e2e upstream assertions to httpbin-service-e2e-test by name
- Regenerate CRD manifests and API reference docs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Upstream Name is cleared when embedded in a service object
(httproute translator sets Name="" for single-backend upstreams).
Filtering by name always fails; rely on Checks field instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Reuse apiv2.ActiveHealthCheckMinInterval instead of duplicating the
  constant to avoid divergence
- Assert upstreams list is non-empty before checking post-deletion state
  so the test fails explicitly if no upstreams are found

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The AuthParameter field is declared as *ApisixConsumerAuthParameter
(pointer), but the test was using a non-pointer value literal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AlinsRan AlinsRan merged commit e461eb2 into apache:master May 18, 2026
26 checks passed
@AlinsRan AlinsRan deleted the feat/backendtrafficpolicy-healthcheck-backport branch May 18, 2026 01:01
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