-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NGINX configuration for UpstreamSettingsPolicy (#2877)
Translate data plane intermediary UpstreamSettingsPolicy configuration into NGINX configuration. Problem: I want the data plane configuration generated from my UpstreamSettingsPolicy to be translated into NGINX Configuration. Solution: Translate the data plane UpstreamSettingsPolicy configuration into NGINX configuration. Testing: Unit tests.
- Loading branch information
Showing
12 changed files
with
1,398 additions
and
274 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 | ||
} | ||
|
||
// 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.