Skip to content

Add support for IPv6 #2190

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 28 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5afe069
add support for ipv6
salonichf5 Jul 2, 2024
1fe7bb1
Update apis/v1alpha1/nginxproxy_types.go
salonichf5 Jul 8, 2024
caafe33
updates based on reviews
salonichf5 Jul 9, 2024
6c96e94
edit kind cluster creation with dual stack
salonichf5 Jul 9, 2024
0a5ead0
fix fieldalignment
salonichf5 Jul 9, 2024
8a930d7
updates based on reviews
salonichf5 Jul 10, 2024
2f03c33
update unit test
salonichf5 Jul 10, 2024
a19793c
update endpoint verification based on NGINX IP Family
salonichf5 Jul 11, 2024
5600726
update resolver
salonichf5 Jul 11, 2024
ec86322
update nginx proxy validator for ipFamily
salonichf5 Jul 11, 2024
5f6f583
add conditions to service
salonichf5 Jul 12, 2024
5b38ff9
improve verify IPFamily
salonichf5 Jul 12, 2024
b3dcc2c
Update internal/mode/static/state/resolver/resolver_test.go
salonichf5 Jul 12, 2024
c804274
Update internal/mode/static/nginx/config/upstreams_test.go
salonichf5 Jul 12, 2024
a578387
Update internal/mode/static/nginx/config/servers.go
salonichf5 Jul 12, 2024
624fd81
Update internal/mode/static/state/dataplane/configuration_test.go
salonichf5 Jul 12, 2024
de05457
Update internal/mode/static/state/graph/backend_refs.go
salonichf5 Jul 12, 2024
fe42fa5
Update internal/mode/static/state/graph/backend_refs.go
salonichf5 Jul 12, 2024
82584b2
Update internal/mode/static/state/graph/backend_refs.go
salonichf5 Jul 12, 2024
931c613
Update internal/mode/static/state/graph/backend_refs_test.go
salonichf5 Jul 12, 2024
2d1938c
Update internal/mode/static/state/graph/backend_refs_test.go
salonichf5 Jul 12, 2024
efe7fa1
address comments
salonichf5 Jul 12, 2024
4175da4
update compat doc and troubleshooting guide
salonichf5 Jul 14, 2024
e3c1b57
update doc
salonichf5 Jul 15, 2024
2ea4db6
update troubleshooting guide
salonichf5 Jul 15, 2024
b52b90d
update based on reviews
salonichf5 Jul 15, 2024
9ef4868
move service name creation out of function
salonichf5 Jul 16, 2024
e802e82
address comments
salonichf5 Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
salonichf5 committed Jul 17, 2024
commit efe7fa1e4e3f87c2f6fd8277f77300397190a453
2 changes: 0 additions & 2 deletions config/cluster/kind-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ nodes:
- role: control-plane
networking:
ipFamily: dual
# ipFamily: ipv6
# ipFamily: ipv4
apiServerAddress: 127.0.0.1
1 change: 0 additions & 1 deletion internal/mode/static/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var grpcBaseHeaders = []http.Header{
}

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

serverConfig := http.ServerConfig{
Expand Down
321 changes: 183 additions & 138 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,162 @@ import (
)

func TestExecuteServers(t *testing.T) {
tests := []struct {
msg string
expectedHTTPConfig map[string]int
expectedHTTPMatchVars string
expectedIncludedFileConfigs map[string]string
config dataplane.Configuration
}{
{
msg: "http and ssl servers with IPv4 IP family",
config: dataplane.Configuration{
HTTPServers: []dataplane.VirtualServer{
conf := dataplane.Configuration{
HTTPServers: []dataplane.VirtualServer{
{
IsDefault: true,
Port: 8080,
},
{
Hostname: "example.com",
Port: 8080,
},
{
Hostname: "cafe.example.com",
Port: 8080,
Additions: []dataplane.Addition{
{
IsDefault: true,
Port: 8080,
Bytes: []byte("addition-1"),
Identifier: "addition-1",
},
},
},
},
SSLServers: []dataplane.VirtualServer{
{
IsDefault: true,
Port: 8443,
},
{
Hostname: "example.com",
SSL: &dataplane.SSL{
KeyPairID: "test-keypair",
},
Port: 8443,
},
{
Hostname: "cafe.example.com",
SSL: &dataplane.SSL{
KeyPairID: "test-keypair",
},
Port: 8443,
PathRules: []dataplane.PathRule{
{
Hostname: "example.com",
Port: 8080,
Path: "/",
PathType: dataplane.PathTypePrefix,
MatchRules: []dataplane.MatchRule{
{
Match: dataplane.Match{},
BackendGroup: dataplane.BackendGroup{
Source: types.NamespacedName{Namespace: "test", Name: "route1"},
RuleIdx: 0,
Backends: []dataplane.Backend{
{
UpstreamName: "test_foo_443",
Valid: true,
Weight: 1,
VerifyTLS: &dataplane.VerifyTLS{
CertBundleID: "test-foo",
Hostname: "test-foo.example.com",
},
},
},
},
},
},
},
},
SSLServers: []dataplane.VirtualServer{
Additions: []dataplane.Addition{
{
IsDefault: true,
Port: 8443,
Bytes: []byte("addition-1"),
Identifier: "addition-1", // duplicate
},
{
Hostname: "example.com",
SSL: &dataplane.SSL{
KeyPairID: "test-keypair",
},
Port: 8443,
Bytes: []byte("addition-2"),
Identifier: "addition-2",
},
},
},
},
}

expSubStrings := map[string]int{
"listen 8080 default_server;": 1,
"listen 8080;": 2,
"listen 8443 ssl;": 2,
"listen 8443 ssl default_server;": 1,
"server_name example.com;": 2,
"server_name cafe.example.com;": 2,
"ssl_certificate /etc/nginx/secrets/test-keypair.pem;": 2,
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 2,
"proxy_ssl_server_name on;": 1,
}

type assertion func(g *WithT, data string)

expectedResults := map[string]assertion{
httpConfigFile: func(g *WithT, data string) {
for expSubStr, expCount := range expSubStrings {
g.Expect(strings.Count(data, expSubStr)).To(Equal(expCount))
}
},
httpMatchVarsFile: func(g *WithT, data string) {
g.Expect(data).To(Equal("{}"))
},
includesFolder + "/addition-1.conf": func(g *WithT, data string) {
g.Expect(data).To(Equal("addition-1"))
},
includesFolder + "/addition-2.conf": func(g *WithT, data string) {
g.Expect(data).To(Equal("addition-2"))
},
}
g := NewWithT(t)

results := executeServers(conf)
g.Expect(results).To(HaveLen(len(expectedResults)))

for _, res := range results {
g.Expect(expectedResults).To(HaveKey(res.dest), "executeServers returned unexpected result destination")

assertData := expectedResults[res.dest]
assertData(g, string(res.data))
}
}

func TestExecuteServersForIPFamily(t *testing.T) {
httpServers := []dataplane.VirtualServer{
{
IsDefault: true,
Port: 8080,
},
{
Hostname: "example.com",
Port: 8080,
},
}
sslServers := []dataplane.VirtualServer{
{
IsDefault: true,
Port: 8443,
},
{
Hostname: "example.com",
SSL: &dataplane.SSL{
KeyPairID: "test-keypair",
},
Port: 8443,
},
}
tests := []struct {
msg string
expectedHTTPConfig map[string]int
config dataplane.Configuration
}{
{
msg: "http and ssl servers with IPv4 IP family",
config: dataplane.Configuration{
HTTPServers: httpServers,
SSLServers: sslServers,
BaseHTTPConfig: dataplane.BaseHTTPConfig{
IPFamily: dataplane.IPv4,
},
Expand All @@ -62,142 +185,64 @@ func TestExecuteServers(t *testing.T) {
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 1,
"ssl_reject_handshake on;": 1,
},
expectedHTTPMatchVars: "{}",
},
{
msg: "http and ssl servers with dual IP family",
msg: "http and ssl servers with IPv6 IP family",
config: dataplane.Configuration{
HTTPServers: []dataplane.VirtualServer{
{
IsDefault: true,
Port: 8080,
},
{
Hostname: "example.com",
Port: 8080,
},
{
Hostname: "cafe.example.com",
Port: 8080,
Additions: []dataplane.Addition{
{
Bytes: []byte("addition-1"),
Identifier: "addition-1",
},
},
},
},
SSLServers: []dataplane.VirtualServer{
{
IsDefault: true,
Port: 8443,
},
{
Hostname: "example.com",
SSL: &dataplane.SSL{
KeyPairID: "test-keypair",
},
Port: 8443,
},
{
Hostname: "cafe.example.com",
SSL: &dataplane.SSL{
KeyPairID: "test-keypair",
},
Port: 8443,
PathRules: []dataplane.PathRule{
{
Path: "/",
PathType: dataplane.PathTypePrefix,
MatchRules: []dataplane.MatchRule{
{
Match: dataplane.Match{},
BackendGroup: dataplane.BackendGroup{
Source: types.NamespacedName{Namespace: "test", Name: "route1"},
RuleIdx: 0,
Backends: []dataplane.Backend{
{
UpstreamName: "test_foo_443",
Valid: true,
Weight: 1,
VerifyTLS: &dataplane.VerifyTLS{
CertBundleID: "test-foo",
Hostname: "test-foo.example.com",
},
},
},
},
},
},
},
},
Additions: []dataplane.Addition{
{
Bytes: []byte("addition-1"),
Identifier: "addition-1", // duplicate
},
{
Bytes: []byte("addition-2"),
Identifier: "addition-2",
},
},
},
HTTPServers: httpServers,
SSLServers: sslServers,
BaseHTTPConfig: dataplane.BaseHTTPConfig{
IPFamily: dataplane.IPv6,
},
},
expectedHTTPConfig: map[string]int{
"listen [::]:8080 default_server;": 1,
"listen [::]:8080;": 1,
"listen [::]:8443 ssl default_server;": 1,
"listen [::]:8443 ssl;": 1,
"server_name example.com;": 2,
"ssl_certificate /etc/nginx/secrets/test-keypair.pem;": 1,
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 1,
"ssl_reject_handshake on;": 1,
},
},
{
msg: "http and ssl servers with Dual IP family",
config: dataplane.Configuration{
HTTPServers: httpServers,
SSLServers: sslServers,
BaseHTTPConfig: dataplane.BaseHTTPConfig{
IPFamily: dataplane.Dual,
},
},
expectedHTTPConfig: map[string]int{
"listen 8080 default_server;": 1,
"listen [::]:8080 default_server;": 1,
"listen 8080;": 2,
"listen [::]:8080;": 2,
"listen 8443 ssl;": 2,
"listen [::]:8443 ssl;": 2,
"listen 8080;": 1,
"listen 8443 ssl default_server;": 1,
"listen [::]:8443 ssl default_server;": 1,
"listen 8443 ssl;": 1,
"server_name example.com;": 2,
"server_name cafe.example.com;": 2,
"ssl_certificate /etc/nginx/secrets/test-keypair.pem;": 2,
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 2,
"proxy_ssl_server_name on;": 1,
},
expectedHTTPMatchVars: "{}",
expectedIncludedFileConfigs: map[string]string{
includesFolder + "/addition-1.conf": "addition-1",
includesFolder + "/addition-2.conf": "addition-2",
"ssl_certificate /etc/nginx/secrets/test-keypair.pem;": 1,
"ssl_certificate_key /etc/nginx/secrets/test-keypair.pem;": 1,
"ssl_reject_handshake on;": 1,
"listen [::]:8080 default_server;": 1,
"listen [::]:8080;": 1,
"listen [::]:8443 ssl default_server;": 1,
"listen [::]:8443 ssl;": 1,
},
},
}

type assertion func(g *WithT, data string)
for _, test := range tests {
t.Run(test.msg, func(t *testing.T) {
g := NewWithT(t)
results := executeServers(test.config)
expectedResults := map[string]assertion{
httpConfigFile: func(g *WithT, data string) {
for expSubStr, expCount := range test.expectedHTTPConfig {
g.Expect(strings.Count(data, expSubStr)).To(Equal(expCount))
}
},
httpMatchVarsFile: func(g *WithT, data string) {
g.Expect(data).To(Equal(test.expectedHTTPMatchVars))
},
}

for file, assertData := range test.expectedIncludedFileConfigs {
expectedResults[file] = func(g *WithT, data string) {
g.Expect(data).To(Equal(assertData))
}
}

g.Expect(results).To(HaveLen(len(expectedResults)))
g.Expect(results).To(HaveLen(2))
serverConf := string(results[0].data)
httpMatchConf := string(results[1].data)
g.Expect(httpMatchConf).To(Equal("{}"))

for _, res := range results {
g.Expect(expectedResults).To(HaveKey(res.dest), "executeServers returned unexpected result destination")
assertData := expectedResults[res.dest]
assertData(g, string(res.data))
for expSubStr, expCount := range test.expectedHTTPConfig {
g.Expect(strings.Count(serverConf, expSubStr)).To(Equal(expCount))
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/nginx/config/upstreams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestCreateUpstreams(t *testing.T) {
Endpoints: []resolver.Endpoint{},
},
{
Name: "up4",
Name: "up4-ipv6",
Endpoints: []resolver.Endpoint{
{
Address: "fd00:10:244:1::7",
Expand Down
Loading