-
Notifications
You must be signed in to change notification settings - Fork 118
Add NGINX configuration for UpstreamSettingsPolicy #2877
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
bjee19
merged 23 commits into
nginx:feature/upstream-settings-policy
from
bjee19:feat/upstream-policy-nginx
Dec 11, 2024
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
78d1f01
Add NGINX configuration for UpstreamSettingsPolicy
bjee19 d39f4c0
Fix naming conventions, test messages, and add more comments
bjee19 1053ca2
Remove typo
bjee19 5f7eee7
Change funtionality so connection header value is empty when keep ali…
bjee19 a420810
Update generated files
bjee19 b188ef6
Add feedback for upstreams template
bjee19 939e782
Adjust comment in upstreams template
bjee19 032a6bc
Add feedback for naming of variables and fields
bjee19 7c403dd
Add upstreams test case for empty policy
bjee19 3618fbd
Add processor test case for multiple policies
bjee19 042cce5
Refactor generating proxy set headers
bjee19 95d3f8d
Add processor test case for processing non-UpstreamSettingsPolicies
bjee19 03f3c7e
Add another upstream test case
bjee19 c54b874
Fix upstream test case
bjee19 c53c24b
Extract keepalive settings outside of UpstreamSettings
bjee19 02705e0
Turn executeUpstreams into function
bjee19 513351e
Add UpstreamKeepAlive struct for http Upstream
bjee19 a2ace83
Add keepAliveChecker function
bjee19 b8a28a6
Add review feedback
bjee19 c489591
Adjust spacing in upstreams template
bjee19 65a5db6
Add end to end test for unset connection header
bjee19 db05606
Remove UpstreamSettingsProcessor interface and move UpstreamSettings …
bjee19 dd3f170
Refactor small code fix
bjee19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
internal/mode/static/nginx/config/policies/upstreamsettings/processor.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package upstreamsettings | ||
|
||
import ( | ||
ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1" | ||
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/http" | ||
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" | ||
) | ||
|
||
// Processor processes UpstreamSettingsPolicies. | ||
type Processor struct{} | ||
|
||
// UpstreamSettings contains settings from UpstreamSettingsPolicy. | ||
type UpstreamSettings struct { | ||
// ZoneSize is the zone size setting. | ||
ZoneSize string | ||
// KeepAlive contains the keepalive settings. | ||
KeepAlive http.UpstreamKeepAlive | ||
} | ||
|
||
// NewProcessor returns a new Processor. | ||
func NewProcessor() Processor { | ||
return Processor{} | ||
} | ||
|
||
// Process processes policies into an UpstreamSettings object. The policies are already validated and are guaranteed | ||
// to not contain overlapping settings. This method merges all fields in the policies into a single UpstreamSettings | ||
// object. | ||
func (g Processor) Process(pols []policies.Policy) UpstreamSettings { | ||
return processPolicies(pols) | ||
} | ||
|
||
func processPolicies(pols []policies.Policy) UpstreamSettings { | ||
upstreamSettings := UpstreamSettings{} | ||
|
||
for _, pol := range pols { | ||
usp, ok := pol.(*ngfAPI.UpstreamSettingsPolicy) | ||
if !ok { | ||
continue | ||
bjee19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// we can assume that there will be no instance of two or more policies setting the same | ||
// field for the same service | ||
if usp.Spec.ZoneSize != nil { | ||
upstreamSettings.ZoneSize = string(*usp.Spec.ZoneSize) | ||
} | ||
|
||
if usp.Spec.KeepAlive != nil { | ||
if usp.Spec.KeepAlive.Connections != nil { | ||
upstreamSettings.KeepAlive.Connections = *usp.Spec.KeepAlive.Connections | ||
} | ||
|
||
if usp.Spec.KeepAlive.Requests != nil { | ||
upstreamSettings.KeepAlive.Requests = *usp.Spec.KeepAlive.Requests | ||
} | ||
|
||
if usp.Spec.KeepAlive.Time != nil { | ||
upstreamSettings.KeepAlive.Time = string(*usp.Spec.KeepAlive.Time) | ||
} | ||
|
||
if usp.Spec.KeepAlive.Timeout != nil { | ||
upstreamSettings.KeepAlive.Timeout = string(*usp.Spec.KeepAlive.Timeout) | ||
} | ||
} | ||
} | ||
|
||
return upstreamSettings | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.