Skip to content

Add SnippetsFilter API #2667

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

Merged
merged 8 commits into from
Oct 9, 2024
Merged

Add SnippetsFilter API #2667

merged 8 commits into from
Oct 9, 2024

Conversation

sjberman
Copy link
Collaborator

@sjberman sjberman commented Oct 9, 2024

Problem: As a user of NGF that has a need for an enhancement in the project, I want the ability to customize the NGINX configuration for NGF, So that I can utilize features that have not yet been exposed via configuration, Or so that I can work around a problem that has not yet been solved in NGF, but can be fixed through NGINX configuration.

Solution: Add the new SnippetsFilter CRD to allow for injecting custom nginx configuration to a routing rule. Apply configuration of valid SnippetsFilters referenced in HTTPRoutes and GRPCRoutes to the appropriate contexts in the NGINX config. If the SnippetsFilter referenced is invalid (wrong group or kind), the routing rule is not configured. If the SnippetsFilter cannot be resolved, the routing rule is configured, but the route will return a 500.

#703

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Add SnippetsFilter API to allow users to add custom nginx configuration to a routing rule.

salonichf5 and others added 7 commits October 9, 2024 08:14
Problem: User wants to define a CRD for snippetsFilter to apply custom nginx configurations

Solution: Defined a CRD for snippetsFilter
Problem: SnippetsFilters need to be in graph before we can write status to them.

Solution: Register controller for SnippetsFilter when the flag --snippets-filter is set. Add SnippetsFilter to graph so we can write its status. Validate SnippetsFilter.
Add Status to SnippetsFilter

Problem: Users want to be have information about the status of the snippetFilters.

Solution: Add status details to snippetFilters.
Add controller to snippetsFilter status

Problem: Users want to ensure controller name is added when condition is added to SnippetsFilter.

Solution: Modify the SnippetsFilterStatus to include controller name writing status.
Problem: As a user of NGF, I want my SnippetsFilters configuration
applied to NGF's data plane, so that I can leverage NGINX features
not yet available in NGF.

Solution: Apply configuration of valid SnippetsFilters referenced in
HTTPRoutes and GRPCRoutes to the appropriate contexts in the
NGINX config. If the SnippetsFilter referenced is invalid
(wrong group or kind), the routing rule is not configured.
If the SnippetsFilter cannot be resolved, the routing rule is configured,
but the route will return a 500.
Problem: The main includes were defined twice, causing some issues in reloading nginx.

Solution: Deduplicate the code.
add functional tests for snippetsFilter
@sjberman sjberman requested review from a team as code owners October 9, 2024 16:52
@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request tests Pull requests that update tests helm-chart Relates to helm chart labels Oct 9, 2024
@sjberman sjberman changed the title Feature/snippets filter Add SnippetsFilter API Oct 9, 2024
Copy link
Contributor

github-actions bot commented Oct 9, 2024

Deploy Preview will be available once build job completes!

Name Link
😎 Deploy Preview https://frontdoor-test-docs.nginx.com/previews/nginx-gateway-fabric/2667/

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 95.81006% with 30 lines in your changes missing coverage. Please review.

Project coverage is 88.89%. Comparing base (956c05f) to head (0553372).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/mode/static/state/graph/common_filter.go 93.88% 10 Missing and 1 partial ⚠️
internal/mode/static/manager.go 47.36% 10 Missing ⚠️
internal/mode/static/state/graph/grpcroute.go 93.84% 3 Missing and 1 partial ⚠️
internal/mode/static/state/graph/httproute.go 94.59% 3 Missing and 1 partial ⚠️
cmd/gateway/commands.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2667      +/-   ##
==========================================
- Coverage   95.19%   88.89%   -6.30%     
==========================================
  Files           1      110     +109     
  Lines         229     8556    +8327     
  Branches       50       50              
==========================================
+ Hits          218     7606    +7388     
- Misses         11      892     +881     
- Partials        0       58      +58     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bjee19
Copy link
Contributor

bjee19 commented Oct 9, 2024

@sjberman did you manually test that SnippetsFilters functionality still works properly after rebasing on main?

@sjberman
Copy link
Collaborator Author

sjberman commented Oct 9, 2024

@bjee19 No, the functional tests now exist that should verify that the nginx config is set properly from a snippets filter.

@sjberman sjberman enabled auto-merge (squash) October 9, 2024 18:26
@sjberman sjberman merged commit cfc3b95 into main Oct 9, 2024
48 checks passed
@sjberman sjberman deleted the feature/snippets-filter branch October 9, 2024 21:07
miledxz added a commit to miledxz/nginx-gateway-fabric that referenced this pull request Jan 14, 2025
Problem: As a user of NGF that has a need for an enhancement in the project, I want the ability to customize the NGINX configuration for NGF, So that I can utilize features that have not yet been exposed via configuration, Or so that I can work around a problem that has not yet been solved in NGF, but can be fixed through NGINX configuration.

Solution: Add the new SnippetsFilter CRD to allow for injecting custom nginx configuration to a routing rule. Apply configuration of valid SnippetsFilters referenced in HTTPRoutes and GRPCRoutes to the appropriate contexts in the NGINX config. If the SnippetsFilter referenced is invalid (wrong group or kind), the routing rule is not configured. If the SnippetsFilter cannot be resolved, the routing rule is configured, but the route will return a 500.

---------

Co-authored-by: salonichf5 <[email protected]>
Co-authored-by: Kate Osborn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request helm-chart Relates to helm chart release-notes tests Pull requests that update tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants