Return 503 by default when no endpoint is available

This commit is contained in:
Max Laverse 2017-10-09 14:16:09 +02:00
parent 1f269d4e4d
commit 1062340b0d
2 changed files with 10 additions and 4 deletions

View file

@ -603,8 +603,8 @@ func (ic *GenericController) getBackendServers(ingresses []*extensions.Ingress)
for _, location := range server.Locations { for _, location := range server.Locations {
if upstream.Name == location.Backend { if upstream.Name == location.Backend {
if len(upstream.Endpoints) == 0 { if len(upstream.Endpoints) == 0 {
glog.V(3).Infof("upstream %v does not have any active endpoints. Using default backend", upstream.Name) glog.V(3).Infof("upstream %v does not have any active endpoints.", upstream.Name)
location.Backend = "upstream-default-backend" location.Backend = ""
// check if the location contains endpoints and a custom default backend // check if the location contains endpoints and a custom default backend
if location.DefaultBackend != nil { if location.DefaultBackend != nil {

View file

@ -592,7 +592,7 @@ stream {
ssl_certificate {{ $server.SSLCertificate }}; ssl_certificate {{ $server.SSLCertificate }};
ssl_certificate_key {{ $server.SSLCertificate }}; ssl_certificate_key {{ $server.SSLCertificate }};
{{ if not (empty $server.SSLFullChainCertificate)}} {{ if not (empty $server.SSLFullChainCertificate)}}
ssl_trusted_certificate {{ $server.SSLFullChainCertificate }}; ssl_trusted_certificate {{ $server.SSLFullChainCertificate }};
ssl_stapling on; ssl_stapling on;
ssl_stapling_verify on; ssl_stapling_verify on;
{{ end }} {{ end }}
@ -616,7 +616,7 @@ stream {
{{ if not (empty $server.ServerSnippet) }} {{ if not (empty $server.ServerSnippet) }}
{{ $server.ServerSnippet }} {{ $server.ServerSnippet }}
{{ end }} {{ end }}
{{ range $location := $server.Locations }} {{ range $location := $server.Locations }}
{{ $path := buildLocation $location }} {{ $path := buildLocation $location }}
{{ $authPath := buildAuthLocation $location }} {{ $authPath := buildAuthLocation $location }}
@ -808,8 +808,14 @@ stream {
proxy_set_header X-Service-Name $service_name; proxy_set_header X-Service-Name $service_name;
{{ end }} {{ end }}
{{ if not (empty $location.Backend) }}
{{ buildProxyPass $server.Hostname $all.Backends $location }} {{ buildProxyPass $server.Hostname $all.Backends $location }}
{{ else }} {{ else }}
# No endpoints available for the request
return 503;
{{ end }}
{{ else }}
# Location denied. Reason: {{ $location.Denied }} # Location denied. Reason: {{ $location.Denied }}
return 503; return 503;
{{ end }} {{ end }}