-
Notifications
You must be signed in to change notification settings - Fork 154
Add SnippetsPolicy for Gateway level #4461
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
base: main
Are you sure you want to change the base?
Conversation
|
Hi @fabian4! Thanks for opening this pull request! |
ebe3381 to
8e5feb3
Compare
8e5feb3 to
63897e7
Compare
sjberman
left a comment
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.
Thanks for taking this on! It's not easy work.
| // +kubebuilder:validation:XValidation:message="TargetRef Kind must be Gateway",rule="self.kind == 'Gateway'" | ||
| // +kubebuilder:validation:XValidation:message="TargetRef Group must be gateway.networking.k8s.io",rule="self.group == 'gateway.networking.k8s.io'" | ||
| //nolint:lll | ||
| TargetRef SnippetsPolicyTargetRef `json:"targetRef"` |
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.
Per our SnippetsPolicy design, we should be able to support multiple TargetRefs. We can also just use LocalPolicyTargetReference, no need to alias.
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.
I think we also need to decide if we only want this to target Gateways, or also HTTP/GRPCRoutes. In our initial design, we proposed targeting all of these. However, I'm not convinced yet if we need it at the Route level. This could be enhanced in the future.
Based on the design here, this is a direct policy regardless, so we need the // +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct" label at the top level of the SnippetsPolicy struct.
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.
Allowing SnippetsPolicy to attach directly to Routes may overlap with existing mechanisms such as SnippetsFilter, introducing ambiguity around ownership and precedence. In the Gateway API model, Route behavior is typically defined within the Route, while Gateway-level policies focus on shared concerns. This separation feels clearer, though feedback is welcome.
internal/controller/nginx/config/policies/snippetspolicy/validator.go
Outdated
Show resolved
Hide resolved
e11ed2f to
a155e01
Compare
Problem: Users need a mechanism to inject raw NGINX configuration snippets into the generated configuration to leverage advanced NGINX features or directives that are not yet exposed via the Gateway API or existing NGINX Gateway Fabric policies.
Solution: Implemented the SnippetsPolicy Custom Resource Definition (CRD).
Testing:
Please focus on (optional): The validation logic in internal/controller/nginx/config/policies/snippetspolicy/validator.go, specifically the size limits and context checks.
Closes #4071
Checklist
Before creating a PR, run through this checklist and mark each as complete.
Release notes