From f29993591288ca9456e9bdc743dbb97c573a3644 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Wed, 12 Oct 2022 18:23:18 -0600 Subject: [PATCH] Add nginx 500 and 502 servers --- deploy/manifests/nginx-gateway.yaml | 6 ++++++ internal/nginx/config/template/servers.go | 13 +++++++++++++ internal/nginx/config/upstreams.go | 4 +++- internal/nginx/config/upstreams_test.go | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/deploy/manifests/nginx-gateway.yaml b/deploy/manifests/nginx-gateway.yaml index 3d707f1ff7..a382c46d96 100644 --- a/deploy/manifests/nginx-gateway.yaml +++ b/deploy/manifests/nginx-gateway.yaml @@ -82,6 +82,8 @@ spec: volumes: - name: nginx-config emptyDir: { } + - name: var-lib-nginx + emptyDir: { } - name: njs-modules configMap: name: njs-modules @@ -92,6 +94,8 @@ spec: volumeMounts: - name: nginx-config mountPath: /etc/nginx + - name: var-lib-nginx + mountPath: /var/lib/nginx containers: - image: ghcr.io/nginxinc/nginx-kubernetes-gateway:edge imagePullPolicy: Always @@ -118,5 +122,7 @@ spec: volumeMounts: - name: nginx-config mountPath: /etc/nginx + - name: var-lib-nginx + mountPath: /var/lib/nginx - name: njs-modules mountPath: /usr/lib/nginx/modules/njs diff --git a/internal/nginx/config/template/servers.go b/internal/nginx/config/template/servers.go index a49c13132a..28193a021e 100644 --- a/internal/nginx/config/template/servers.go +++ b/internal/nginx/config/template/servers.go @@ -53,4 +53,17 @@ server { } {{ end }} {{ end }} +server { + listen unix:/var/lib/nginx/nginx-502-server.sock; + access_log off; + + return 502; +} + +server { + listen unix:/var/lib/nginx/nginx-500-server.sock; + access_log off; + + return 500; +} ` diff --git a/internal/nginx/config/upstreams.go b/internal/nginx/config/upstreams.go index 1cc5dcef40..535f17ffec 100644 --- a/internal/nginx/config/upstreams.go +++ b/internal/nginx/config/upstreams.go @@ -11,6 +11,8 @@ import ( const ( // nginx502Server is used as a backend for services that cannot be resolved (have no IP address). nginx502Server = "unix:/var/lib/nginx/nginx-502-server.sock" + // nginx500Server is used as a server for the invalid backend ref upstream. + nginx500Server = "unix:/var/lib/nginx/nginx-500-server.sock" // invalidBackendRef is used as an upstream name for invalid backend references. invalidBackendRef = "invalid-backend-ref" ) @@ -65,7 +67,7 @@ func createInvalidBackendRefUpstream() http.Upstream { Name: invalidBackendRef, Servers: []http.UpstreamServer{ { - Address: nginx502Server, + Address: nginx500Server, }, }, } diff --git a/internal/nginx/config/upstreams_test.go b/internal/nginx/config/upstreams_test.go index e201910c41..8d2f526289 100644 --- a/internal/nginx/config/upstreams_test.go +++ b/internal/nginx/config/upstreams_test.go @@ -128,7 +128,7 @@ func TestCreateUpstreams(t *testing.T) { Name: invalidBackendRef, Servers: []http.UpstreamServer{ { - Address: nginx502Server, + Address: nginx500Server, }, }, },