Skip to content

Commit

Permalink
Merge pull request #1513 from maxlaverse/return_503_by_default
Browse files Browse the repository at this point in the history
Return 503 by default when no endpoint is available
  • Loading branch information
aledbf authored Oct 9, 2017
2 parents 8b94f46 + 1062340 commit ae34a22
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ func (ic *GenericController) getBackendServers(ingresses []*extensions.Ingress)
for _, location := range server.Locations {
if upstream.Name == location.Backend {
if len(upstream.Endpoints) == 0 {
glog.V(3).Infof("upstream %v does not have any active endpoints. Using default backend", upstream.Name)
location.Backend = "upstream-default-backend"
glog.V(3).Infof("upstream %v does not have any active endpoints.", upstream.Name)
location.Backend = ""

// check if the location contains endpoints and a custom default backend
if location.DefaultBackend != nil {
Expand Down
10 changes: 8 additions & 2 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ stream {
ssl_certificate {{ $server.SSLCertificate }};
ssl_certificate_key {{ $server.SSLCertificate }};
{{ if not (empty $server.SSLFullChainCertificate)}}
ssl_trusted_certificate {{ $server.SSLFullChainCertificate }};
ssl_trusted_certificate {{ $server.SSLFullChainCertificate }};
ssl_stapling on;
ssl_stapling_verify on;
{{ end }}
Expand All @@ -616,7 +616,7 @@ stream {
{{ if not (empty $server.ServerSnippet) }}
{{ $server.ServerSnippet }}
{{ end }}

{{ range $location := $server.Locations }}
{{ $path := buildLocation $location }}
{{ $authPath := buildAuthLocation $location }}
Expand Down Expand Up @@ -808,8 +808,14 @@ stream {
proxy_set_header X-Service-Name $service_name;
{{ end }}


{{ if not (empty $location.Backend) }}
{{ buildProxyPass $server.Hostname $all.Backends $location }}
{{ else }}
# No endpoints available for the request
return 503;
{{ end }}
{{ else }}
# Location denied. Reason: {{ $location.Denied }}
return 503;
{{ end }}
Expand Down

0 comments on commit ae34a22

Please sign in to comment.