Skip to content

Commit

Permalink
Added support for http2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Schieder committed Nov 15, 2016
1 parent 8e4dfa6 commit 76001b7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/customization/nginx-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ data:
client-max-body-size: "2m" # default is "1m". See http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
server-names-hash-bucket-size: "64" # default value depends on the size of the processor’s cache line. See http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_bucket_size
server-names-hash-max-size: "1024" # default is "512". See http://nginx.org/en/docs/http/ngx_http_core_module.html#server_names_hash_max_size
http2: 'True' # default is "False". Enables http2 in servers with SSL enabled. See https://nginx.org/en/docs/http/ngx_http_v2_module.html
8 changes: 8 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"fmt"
"reflect"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -321,6 +322,13 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
if serverNamesHashMaxSize, exists := cfgm.Data["server-names-hash-max-size"]; exists {
cfg.MainServerNamesHashMaxSize = serverNamesHashMaxSize
}
if HTTP2Str, exists := cfgm.Data["http2"]; exists {
if HTTP2, err := strconv.ParseBool(HTTP2Str); err == nil {
cfg.HTTP2 = HTTP2
} else {
glog.Errorf("In configmap %v/%v 'http2' contains invalid declaration: %v, ignoring", cfgm.Namespace, cfgm.Name, err)
}
}
}
lbc.cnf.UpdateConfig(cfg)

Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Config struct {
ProxyConnectTimeout string
ProxyReadTimeout string
ClientMaxBodySize string
HTTP2 bool
MainServerNamesHashBucketSize string
MainServerNamesHashMaxSize string
}
Expand Down
19 changes: 16 additions & 3 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nginx

import (
"fmt"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -102,7 +103,10 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
glog.Warningf("Host field of ingress rule in %v/%v is empty", ingEx.Ingress.Namespace, ingEx.Ingress.Name)
}

server := Server{Name: serverName}
server := Server{
Name: serverName,
HTTP2: ingCfg.HTTP2,
}

if pemFile, ok := pems[serverName]; ok {
server.SSL = true
Expand Down Expand Up @@ -140,7 +144,10 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
}

if len(ingEx.Ingress.Spec.Rules) == 0 && ingEx.Ingress.Spec.Backend != nil {
server := Server{Name: emptyHost}
server := Server{
Name: emptyHost,
HTTP2: ingCfg.HTTP2,
}

if pemFile, ok := pems[emptyHost]; ok {
server.SSL = true
Expand Down Expand Up @@ -173,7 +180,13 @@ func (cnf *Configurator) createConfig(ingEx *IngressEx) Config {
if clientMaxBodySize, exists := ingEx.Ingress.Annotations["nginx.org/client-max-body-size"]; exists {
ingCfg.ClientMaxBodySize = clientMaxBodySize
}

if HTTP2Str, exists := ingEx.Ingress.Annotations["nginx.org/http2"]; exists {
if HTTP2, err := strconv.ParseBool(HTTP2Str); err == nil {
ingCfg.HTTP2 = HTTP2
} else {
glog.Errorf("In %v/%v nginx.org/http2 contains invalid declaration: %v, ignoring", ingEx.Ingress.Namespace, ingEx.Ingress.Name, err)
}
}
return ingCfg
}

Expand Down
2 changes: 1 addition & 1 deletion nginx-controller/nginx/ingress.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ upstream {{$upstream.Name}} {
server {
listen 80;
{{if $server.SSL}}
listen 443 ssl;
listen 443 ssl{{if $server.HTTP2}} http2{{end}};
ssl_certificate {{$server.SSLCertificate}};
ssl_certificate_key {{$server.SSLCertificateKey}};
{{end}}
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Server struct {
SSL bool
SSLCertificate string
SSLCertificateKey string
HTTP2 bool
}

// Location describes an NGINX location
Expand Down

0 comments on commit 76001b7

Please sign in to comment.