Skip to content

Commit

Permalink
Merge pull request #1454 from aledbf/global-confg
Browse files Browse the repository at this point in the history
Allow custom global configuration at multiple levels
  • Loading branch information
aledbf committed Oct 1, 2017
2 parents 5fadaf5 + 05b212e commit b20aa7c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions controllers/nginx/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ Default: 9411
**zipkin-service-name:** specifies the service name to use for any traces created
Default: nginx

**http-snippet:** adds custom configuration to the http section of the nginx configuration
Default: ""

**server-snippet:** adds custom configuration to all the servers in the nginx configuration
Default: ""

**location-snippet:** adds custom configuration to all the locations in the nginx configuration
Default: ""


### Default configuration options

The following table shows the options, the default value and a description.
Expand Down
9 changes: 9 additions & 0 deletions controllers/nginx/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ type Configuration struct {
// ZipkinServiceName specifies the service name to use for any traces created
// Default: nginx
ZipkinServiceName string `json:"zipkin-service-name"`

// HTTPSnippet adds custom configuration to the http section of the nginx configuration
HTTPSnippet string `json:"http-snippet"`

// ServerSnippet adds custom configuration to all the servers in the nginx configuration
ServerSnippet string `json:"server-snippet"`

// LocationSnippet adds custom configuration to all the locations in the nginx configuration
LocationSnippet string `json:"location-snippet"`
}

// NewDefault returns the default nginx configuration
Expand Down
14 changes: 14 additions & 0 deletions controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ http {
proxy_pass_header Server;
{{ end }}

{{ if not (empty $cfg.HTTPSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $cfg.HTTPSnippet }};
{{ end }}

{{ range $name, $upstream := $backends }}
{{ if eq $upstream.SessionAffinity.AffinityType "cookie" }}
upstream sticky-{{ $upstream.Name }} {
Expand Down Expand Up @@ -394,6 +399,10 @@ http {
server_name {{ $server.Alias }};
{{ template "SERVER" serverConfig $all $server }}

{{ if not (empty $cfg.ServerSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $cfg.ServerSnippet }};
{{ end }}

{{ template "CUSTOM_ERRORS" $all }}
}
Expand Down Expand Up @@ -808,6 +817,11 @@ stream {
{{/* Add any additional configuration defined */}}
{{ $location.ConfigurationSnippet }}

{{ if not (empty $all.Cfg.LocationSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $all.Cfg.LocationSnippet }};
{{ end }}

{{/* if we are sending the request to a custom default backend, we add the required headers */}}
{{ if (hasPrefix $location.Backend "custom-default-backend-") }}
proxy_set_header X-Code 503;
Expand Down

0 comments on commit b20aa7c

Please sign in to comment.