Skip to content

Commit

Permalink
Merge pull request #1326 from aledbf/fix-headers
Browse files Browse the repository at this point in the history
Pass headers from the custom error backend
  • Loading branch information
aledbf committed Sep 9, 2017
2 parents 98311a5 + 13f47ad commit 7eb2b81
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 263 deletions.
32 changes: 0 additions & 32 deletions controllers/nginx/pkg/cmd/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
extensions "k8s.io/api/extensions/v1beta1"

"k8s.io/ingress/controllers/nginx/pkg/config"
"k8s.io/ingress/controllers/nginx/pkg/fastcgi"
ngx_template "k8s.io/ingress/controllers/nginx/pkg/template"
"k8s.io/ingress/controllers/nginx/pkg/version"
"k8s.io/ingress/core/pkg/ingress"
Expand All @@ -59,8 +58,6 @@ const (
vtsStatusModule statusModule = "vts"

defUpstreamName = "upstream-default-backend"

fastCGISocket = "/var/run/go-fastcgi.sock"
)

var (
Expand Down Expand Up @@ -93,23 +90,6 @@ func newNGINXController() *NGINXController {
backendDefaults: config.NewDefault().Backend,
}

fcgiListener, err := net.Listen("unix", fastCGISocket)
if err != nil {
glog.Fatalf("%v", err)
}

err = os.Chmod(fastCGISocket, 0777)
if err != nil {
glog.Fatalf("%v", err)
}

go func() {
err = fastcgi.ServeError(fcgiListener)
if err != nil {
glog.Fatalf("%v", err)
}
}()

var onChange func()
onChange = func() {
template, err := ngx_template.NewTemplate(tmplPath, onChange)
Expand Down Expand Up @@ -679,18 +659,6 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) error {
ListenPorts: n.ports,
}

// We need to extract the endpoints to be used in the fastcgi error handler
for _, b := range ingressCfg.Backends {
if b.Name == defUpstreamName {
eps := []string{}
for _, e := range b.Endpoints {
eps = append(eps, fmt.Sprintf("%v:%v", e.Address, e.Port))
}
tc.DefaultBackendEndpoints = strings.Join(eps, ",")
break
}
}

content, err := n.t.Write(tc)

if err != nil {
Expand Down
1 change: 0 additions & 1 deletion controllers/nginx/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ func (cfg Configuration) BuildLogFormatUpstream() string {

// TemplateConfig contains the nginx configuration to render the file nginx.conf
type TemplateConfig struct {
DefaultBackendEndpoints string
ProxySetHeaders map[string]string
AddHeaders map[string]string
MaxOpenFiles int
Expand Down
110 changes: 0 additions & 110 deletions controllers/nginx/pkg/fastcgi/fastcgi.go

This file was deleted.

104 changes: 0 additions & 104 deletions controllers/nginx/pkg/fastcgi/fastcgi_test.go

This file was deleted.

27 changes: 11 additions & 16 deletions controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,10 @@ http {

location / {
{{ if .CustomErrors }}
include /etc/nginx/fastcgi_params;
fastcgi_param HTTP_X_Code 404;
fastcgi_pass unix:/var/run/go-fastcgi.sock;
{{ else }}
set $proxy_upstream_name "upstream-default-backend";
proxy_pass http://upstream-default-backend;
proxy_set_header X-Code 404;
{{ end }}
set $proxy_upstream_name "upstream-default-backend";
proxy_pass http://upstream-default-backend;
}

{{ template "CUSTOM_ERRORS" $all }}
Expand Down Expand Up @@ -474,21 +471,19 @@ stream {

{{/* definition of templates to avoid repetitions */}}
{{ define "CUSTOM_ERRORS" }}
{{ $defaultBackendEndpoints := .DefaultBackendEndpoints }}
{{ $proxySetHeaders := .ProxySetHeaders }}
{{ range $errCode := .Cfg.CustomHTTPErrors }}
location @custom_{{ $errCode }} {
internal;
include /etc/nginx/fastcgi_params;

fastcgi_param HTTP_X_Code {{ $errCode }};
fastcgi_param HTTP_X_Format $http_accept;
fastcgi_param HTTP_X_Original_URI $request_uri;
fastcgi_param HTTP_X_Namespace $namespace;
fastcgi_param HTTP_X_Ingress_Name $ingress_name;
fastcgi_param HTTP_X_Service_Name $service_name;
fastcgi_param HTTP_X_Endpoints "{{ $defaultBackendEndpoints }}";
proxy_set_header X-Code {{ $errCode }};
proxy_set_header X-Format $http_accept;
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Namespace $namespace;
proxy_set_header X-Ingress-Name $ingress_name;
proxy_set_header X-Service-Name $service_name;

fastcgi_pass unix:/var/run/go-fastcgi.sock;
proxy_pass http://upstream-default-backend;
}
{{ end }}
{{ end }}
Expand Down

0 comments on commit 7eb2b81

Please sign in to comment.