Skip to content

Commit 431c4ae

Browse files
authored
Return 503 when service has no ready endpoints (#2696)
Return 503 when service has no ready endpoints. Problem: With the new gateway api 1.2 version, it is recommended to return 503 when a HTTPBackendRef refers to a Service that has no ready endpoints. Solution: Return 503 when service has no ready endpoints.
1 parent 9fb1d37 commit 431c4ae

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

internal/mode/static/nginx/config/servers_template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ server {
149149
{{- end }}
150150
{{ end }}
151151
server {
152-
listen unix:/var/run/nginx/nginx-502-server.sock;
152+
listen unix:/var/run/nginx/nginx-503-server.sock;
153153
access_log off;
154154
155-
return 502;
155+
return 503;
156156
}
157157
158158
server {

internal/mode/static/nginx/config/upstreams.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
var upstreamsTemplate = gotemplate.Must(gotemplate.New("upstreams").Parse(upstreamsTemplateText))
1414

1515
const (
16-
// nginx502Server is used as a backend for services that cannot be resolved (have no IP address).
17-
nginx502Server = "unix:/var/run/nginx/nginx-502-server.sock"
16+
// nginx503Server is used as a backend for services that cannot be resolved (have no IP address).
17+
nginx503Server = "unix:/var/run/nginx/nginx-503-server.sock"
1818
// nginx500Server is used as a server for the invalid backend ref upstream.
1919
nginx500Server = "unix:/var/run/nginx/nginx-500-server.sock"
2020
// invalidBackendRef is used as an upstream name for invalid backend references.
@@ -112,7 +112,7 @@ func (g GeneratorImpl) createUpstream(up dataplane.Upstream) http.Upstream {
112112
ZoneSize: zoneSize,
113113
Servers: []http.UpstreamServer{
114114
{
115-
Address: nginx502Server,
115+
Address: nginx503Server,
116116
},
117117
},
118118
}

internal/mode/static/nginx/config/upstreams_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestExecuteUpstreams(t *testing.T) {
5858
"server 10.0.0.0:80;",
5959
"server 11.0.0.0:80;",
6060
"server [2001:db8::1]:80",
61-
"server unix:/var/run/nginx/nginx-502-server.sock;",
61+
"server unix:/var/run/nginx/nginx-503-server.sock;",
6262
}
6363

6464
upstreamResults := gen.executeUpstreams(dataplane.Configuration{Upstreams: stateUpstreams})
@@ -148,7 +148,7 @@ func TestCreateUpstreams(t *testing.T) {
148148
ZoneSize: ossZoneSize,
149149
Servers: []http.UpstreamServer{
150150
{
151-
Address: nginx502Server,
151+
Address: nginx503Server,
152152
},
153153
},
154154
},
@@ -194,7 +194,7 @@ func TestCreateUpstream(t *testing.T) {
194194
ZoneSize: ossZoneSize,
195195
Servers: []http.UpstreamServer{
196196
{
197-
Address: nginx502Server,
197+
Address: nginx503Server,
198198
},
199199
},
200200
},
@@ -210,7 +210,7 @@ func TestCreateUpstream(t *testing.T) {
210210
ZoneSize: ossZoneSize,
211211
Servers: []http.UpstreamServer{
212212
{
213-
Address: nginx502Server,
213+
Address: nginx503Server,
214214
},
215215
},
216216
},

site/content/how-to/monitoring/troubleshooting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ You can see logs for a crashed or killed container by adding the `-p` flag to th
139139
Understanding the NGINX configuration is key for fixing issues because it shows how NGINX handles requests. This helps tweak settings to make sure NGINX behaves the way you want it to for your application. To see your current configuration, you can open a shell in the _nginx_ container by following these [steps](#get-shell-access-to-nginx-container) and run `nginx -T`. To understand the usage of NGINX directives in the configuration file, consult this list of [NGINX directives](https://nginx.org/en/docs/dirindex.html).
140140

141141
In this section, we will see how the configuration gets updated as we configure different Services, Deployments and HTTPRoutes with NGINX Gateway Fabric. In the configuration file, you'll often find several server blocks, each assigned to specific ports and server names. NGINX selects the appropriate server for a request and evaluates the URI against the location directives within that block.
142-
When only a Gateway resource is defined, but no Services or HTTPRoutes are configured, NGINX generates a basic configuration. This includes a default server listening on the ports specified in the Gateway listeners, handling all incoming requests. Additionally, there are blocks to manage errors with status codes 500 or 502.
142+
When only a Gateway resource is defined, but no Services or HTTPRoutes are configured, NGINX generates a basic configuration. This includes a default server listening on the ports specified in the Gateway listeners, handling all incoming requests. Additionally, there are blocks to manage errors with status codes 500 or 503.
143143

144144
This is a default `server` block listening on port 80:
145145

0 commit comments

Comments
 (0)