Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion internal/controller/nginx/config/base_http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ var baseHTTPTemplate = gotemplate.Must(gotemplate.New("baseHttp").Parse(baseHTTP

type httpConfig struct {
Includes []shared.Include
HTTP2 bool
NginxReadinessProbePort int32
IPFamily shared.IPFamily
HTTP2 bool
}

func executeBaseHTTPConfig(conf dataplane.Configuration) []executeResult {
Expand All @@ -23,6 +24,7 @@ func executeBaseHTTPConfig(conf dataplane.Configuration) []executeResult {
HTTP2: conf.BaseHTTPConfig.HTTP2,
Includes: includes,
NginxReadinessProbePort: conf.BaseHTTPConfig.NginxReadinessProbePort,
IPFamily: getIPFamily(conf.BaseHTTPConfig),
}

results := make([]executeResult, 0, len(includes)+1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ map $request_uri $request_uri_path {

# NGINX health check server block.
server {
{{- if $.IPFamily.IPv4 }}
listen {{ .NginxReadinessProbePort }};
{{- end }}
{{- if $.IPFamily.IPv6 }}
listen [::]:{{ .NginxReadinessProbePort }};
{{- end }}

location = /readyz {
access_log off;
Expand Down
58 changes: 52 additions & 6 deletions internal/controller/nginx/config/base_http_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,71 @@ func TestExecuteBaseHttp_NginxReadinessProbePort(t *testing.T) {
},
}

customConfig := dataplane.Configuration{
customPortConfig := dataplane.Configuration{
BaseHTTPConfig: dataplane.BaseHTTPConfig{
NginxReadinessProbePort: 9090,
},
}

customIPv4Config := dataplane.Configuration{
BaseHTTPConfig: dataplane.BaseHTTPConfig{
NginxReadinessProbePort: dataplane.DefaultNginxReadinessProbePort,
IPFamily: dataplane.IPv4,
},
}

customIPv6Config := dataplane.Configuration{
BaseHTTPConfig: dataplane.BaseHTTPConfig{
NginxReadinessProbePort: dataplane.DefaultNginxReadinessProbePort,
IPFamily: dataplane.IPv6,
},
}

tests := []struct {
name string
expectedPort string
expectedListen string
conf dataplane.Configuration
name string
expectedPort string
expectedListen string
expectedNoListen string
conf dataplane.Configuration
}{
{
name: "default nginx readiness probe port",
conf: defaultConfig,
expectedPort: "8081",
expectedListen: "listen 8081;",
},
{
name: "default nginx readiness probe port on ipv6",
conf: defaultConfig,
expectedPort: "8081",
expectedListen: "listen [::]:8081;",
},
{
name: "custom nginx readiness probe 9090",
conf: customConfig,
conf: customPortConfig,
expectedPort: "9090",
expectedListen: "listen 9090;",
},
{
name: "custom nginx readiness probe 9090 on ipv6",
conf: customPortConfig,
expectedPort: "9090",
expectedListen: "listen [::]:9090;",
},
{
name: "custom ipv4 nginx readiness probe does not have ipv6 listen",
conf: customIPv4Config,
expectedPort: "8081",
expectedListen: "listen 8081;",
expectedNoListen: "listen [::]:8081;",
},
{
name: "custom ipv6 nginx readiness probe does not have ipv4 listen",
conf: customIPv6Config,
expectedPort: "8081",
expectedListen: "listen [::]:8081;",
expectedNoListen: "listen 8081;",
},
}

for _, test := range tests {
Expand All @@ -156,6 +197,11 @@ func TestExecuteBaseHttp_NginxReadinessProbePort(t *testing.T) {
// check that the listen directive contains the expected port
g.Expect(httpConfig).To(ContainSubstring(test.expectedListen))

// check that an additional listen directive is NOT set
if test.expectedNoListen != "" {
g.Expect(httpConfig).ToNot(ContainSubstring(test.expectedNoListen))
}

// check that the health check server block is present
g.Expect(httpConfig).To(ContainSubstring("server {"))
g.Expect(httpConfig).To(ContainSubstring("access_log off;"))
Expand Down
Loading