-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add ReferenceGrant support for HTTPRoute #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit introduces functionality to handle the ReferenceGrant resource in the Gateway API. It updates the Gateway controller logic, adds necessary permissions in RBAC manifests, and integrates condition handling for cross-namespace references. Additionally, skipped conformance tests related to ReferenceGrants are reinstated.
This commit introduces support for Gateway API ReferenceGrant CRD, enabling cross-namespace references for HTTPRoutes. It refactors backend reference handling to validate Service references and check ReferenceGrants. Also includes minor code cleanups, added cluster role permissions for ReferenceGrants, and adjustments to e2e manifests.
…nce-grant-for-route
…reference-grant-for-route # Conflicts: # test/conformance/conformance_test.go
Reorganized and simplified the predicate logic for ReferenceGrant handling across gateway and HTTPRoute controllers. Consolidated duplicate code into reusable functions, reducing redundancy and improving maintainability. This centralization ensures consistent behavior and clearer code structure.
…nce-grant-for-route # Conflicts: # internal/controller/gateway_controller.go # internal/controller/utils.go # test/conformance/conformance_test.go
… cross-namespace checks
conformance test reportapiVersion: gateway.networking.k8s.io/v1
date: "2025-05-21T10:49:13Z"
gatewayAPIChannel: standard
gatewayAPIVersion: v1.2.0
implementation:
contact: null
organization: APISIX
project: apisix-ingress-controller
url: https://github.com/apache/apisix-ingress-controller.git
version: v2.0.0
kind: ConformanceReport
mode: default
profiles:
- core:
result: partial
skippedTests:
- HTTPRouteHTTPSListener
statistics:
Failed: 0
Passed: 32
Skipped: 1
name: GATEWAY-HTTP
summary: Core tests partially succeeded with 1 test skips. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a feature to detect and enable cross-namespace ReferenceGrant
support, refactors reference grant checks and condition handling, and updates controllers to watch ReferenceGrant
events.
- Introduce a global
enableReferenceGrant
flag and detect theReferenceGrant
CRD inmanager/run.go
- Refactor utilities to unify reference grant logic (
checkReferenceGrant
, predicates) and simplify condition construction - Update both HTTPRoute and Gateway controllers to watch and reconcile based on
ReferenceGrant
changes - Remove skipped conformance tests for traditional routes, replacing the skip list with a TODO
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
test/conformance/conformance_test.go | Cleared out skipped tests list for traditional routes |
internal/manager/run.go | Added ReferenceGrant CRD detection and SetEnableReferenceGrant |
internal/controller/utils.go | Refactored SetRouteConditionResolvedRefs , added grant predicates |
internal/controller/httproute_controller.go | Wired in cross-namespace grant checks and new predicates |
internal/controller/gateway_controller.go | Replaced custom predicates with shared grant predicate logic |
Comments suppressed due to low confidence (5)
test/conformance/conformance_test.go:27
- With all traditional route skips removed, add or update test cases to cover the new cross-namespace
ReferenceGrant
behaviors or adjust the skip list to reflect expected conformance changes.
var skippedTestsForTraditionalRoutes []string // TODO: HTTPRoute hostname intersection and listener hostname matching
internal/controller/utils.go:16
- The import
"cmp"
has no path and will fail to compile. Please replace it with the correct module path (e.g.,"github.com/google/go-cmp/cmp"
or appropriate Go 1.21 import).
"cmp"
internal/controller/utils.go:961
- The code uses
slices.Contains
but theslices
package is not imported. Addimport "slices"
(Go 1.21) or the appropriate module path.
return slices.Contains(reasons, Reason(re.Reason))
internal/controller/utils.go:273
- When
err
is not aReasonError
, the condition’s Reason remains the defaultResolvedRefs
, which may misrepresent the actual failure. Consider setting a generic reason or mapping other error types to an appropriate Reason.
if errors.As(err, &re) {
internal/manager/run.go:187
- [nitpick] Mixing
setupLog
andlogger
for logging here may be confusing. UsesetupLog.Error
consistently for controller startup logs.
logger.Error(err, "CRD ReferenceGrants is not installed")
test/conformance/conformance_test.go
Outdated
|
||
// TODO: HTTPRoute hostname intersection and listener hostname matching | ||
} | ||
var skippedTestsForTraditionalRoutes []string // TODO: HTTPRoute hostname intersection and listener hostname matching |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
internal/manager/run.go
Outdated
Resource: "referencegrants", | ||
}) | ||
if err != nil { | ||
logger.Error(err, "CRD ReferenceGrants is not installed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not need to print logs, or should it not be error-level logs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
others lgtm.
@@ -101,6 +102,10 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error { | |||
Watches(&v1alpha1.GatewayProxy{}, | |||
handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesForGatewayProxy), | |||
). | |||
Watches(&v1beta1.ReferenceGrant{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we allow not installing RefereGrant?
If not installed, an error will occur here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is allowed to not install ReferenceGrant and an error will occur here if not installed ReferenceGrant.
Let me fix it.
Type of change:
What this PR does / why we need it:
feat: Add ReferenceGrant support for HTTPRoute
Pre-submission checklist: