Skip to content

Commit

Permalink
updates based on reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Jul 10, 2024
1 parent 2a4a408 commit afdc237
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion apis/v1alpha1/nginxproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (

// NginxProxySpec defines the desired state of the NginxProxy.
type NginxProxySpec struct {
// IPFamily specifies the IP family to be used by the server.
// IPFamily specifies the IP family to be used by the NGINX.
// Default is "dual", meaning the server will use both IPv4 and IPv6.
//
// +optional
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/gateway.nginx.org_nginxproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
type: boolean
ipFamily:
description: |-
IPFamily specifies the IP family to be used by the server.
IPFamily specifies the IP family to be used by the NGINX.
Default is "dual", meaning the server will use both IPv4 and IPv6.
enum:
- dual
Expand Down
2 changes: 1 addition & 1 deletion deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ spec:
type: boolean
ipFamily:
description: |-
IPFamily specifies the IP family to be used by the server.
IPFamily specifies the IP family to be used by the NGINX.
Default is "dual", meaning the server will use both IPv4 and IPv6.
enum:
- dual
Expand Down
8 changes: 7 additions & 1 deletion internal/mode/static/nginx/config/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Server struct {
GRPC bool
}

// IPFamily holds the IP family configuration for all servers.
// IPFamily holds the IP family configuration to be used by NGINX.
type IPFamily struct {
IPv4 bool
IPv6 bool
Expand Down Expand Up @@ -112,3 +112,9 @@ type ProxySSLVerify struct {
TrustedCertificate string
Name string
}

// ServerConfig holds configuration for an HTTP server and IP family to be used by NGINX.
type ServerConfig struct {
Servers []Server
IPFamily IPFamily
}
7 changes: 1 addition & 6 deletions internal/mode/static/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,11 @@ var grpcBaseHeaders = []http.Header{
},
}

type serverConfig struct {
Servers []http.Server
IPFamily http.IPFamily
}

func executeServers(conf dataplane.Configuration) []executeResult {
ipFamily := getIPFamily(conf.BaseHTTPConfig)
servers, httpMatchPairs := createServers(conf.HTTPServers, conf.SSLServers)

serverConfig := serverConfig{
serverConfig := http.ServerConfig{
Servers: servers,
IPFamily: ipFamily,
}
Expand Down
16 changes: 8 additions & 8 deletions internal/mode/static/nginx/config/servers_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ server {
{{- else }}
server {
{{- if $s.SSL }}
{{- if $.IPFamily.IPv4 }}
{{- if $.IPFamily.IPv4 }}
listen {{ $s.Port }} ssl;
{{- end }}
{{- if $.IPFamily.IPv6 }}
{{- end }}
{{- if $.IPFamily.IPv6 }}
listen [::]:{{ $s.Port }} ssl;
{{- end }}
{{- end }}
ssl_certificate {{ $s.SSL.Certificate }};
ssl_certificate_key {{ $s.SSL.CertificateKey }};
if ($ssl_server_name != $host) {
return 421;
}
{{- else }}
{{- if $.IPFamily.IPv4 }}
{{- if $.IPFamily.IPv4 }}
listen {{ $s.Port }};
{{- end }}
{{- if $.IPFamily.IPv6 }}
{{- end }}
{{- if $.IPFamily.IPv6 }}
listen [::]:{{ $s.Port }};
{{- end }}
{{- end }}
{{- end }}
server_name {{ $s.ServerName }};
Expand Down
33 changes: 33 additions & 0 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2581,3 +2581,36 @@ func TestAdditionFilename(t *testing.T) {
name := createAdditionFileName(dataplane.Addition{Identifier: "my-addition"})
g.Expect(name).To(Equal(includesFolder + "/" + "my-addition.conf"))
}

func TestGetIPFamily(t *testing.T) {
test := []struct {
msg string
baseHTTPConfig dataplane.BaseHTTPConfig
expected http.IPFamily
}{
{
msg: "ipv4",
baseHTTPConfig: dataplane.BaseHTTPConfig{IPFamily: dataplane.IPv4},
expected: http.IPFamily{IPv4: true, IPv6: false},
},
{
msg: "ipv6",
baseHTTPConfig: dataplane.BaseHTTPConfig{IPFamily: dataplane.IPv6},
expected: http.IPFamily{IPv4: false, IPv6: true},
},
{
msg: "dual",
baseHTTPConfig: dataplane.BaseHTTPConfig{IPFamily: dataplane.Dual},
expected: http.IPFamily{IPv4: true, IPv6: true},
},
}

for _, tc := range test {
t.Run(tc.msg, func(t *testing.T) {
g := NewWithT(t)

result := getIPFamily(tc.baseHTTPConfig)
g.Expect(result).To(Equal(tc.expected))
})
}
}
4 changes: 2 additions & 2 deletions site/content/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ IPFamilyType
</td>
<td>
<em>(Optional)</em>
<p>IPFamily specifies the IP family to be used by the server.
<p>IPFamily specifies the IP family to be used by the NGINX.
Default is &ldquo;dual&rdquo;, meaning the server will use both IPv4 and IPv6.</p>
</td>
</tr>
Expand Down Expand Up @@ -930,7 +930,7 @@ IPFamilyType
</td>
<td>
<em>(Optional)</em>
<p>IPFamily specifies the IP family to be used by the server.
<p>IPFamily specifies the IP family to be used by the NGINX.
Default is &ldquo;dual&rdquo;, meaning the server will use both IPv4 and IPv6.</p>
</td>
</tr>
Expand Down

0 comments on commit afdc237

Please sign in to comment.