Merge pull request #2504 from jrthrawny/proxy-protocol-timeout-for-passthrough-pr

Add Timeout For TLS Passthrough
This commit is contained in:
k8s-ci-robot 2018-06-03 22:54:53 -07:00 committed by GitHub
commit fa9823634c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 1 deletions

View file

@ -21,6 +21,7 @@ import (
"net"
"strconv"
"strings"
"time"
"github.com/golang/glog"
@ -42,6 +43,7 @@ const (
hideHeaders = "hide-headers"
nginxStatusIpv4Whitelist = "nginx-status-ipv4-whitelist"
nginxStatusIpv6Whitelist = "nginx-status-ipv6-whitelist"
proxyHeaderTimeout = "proxy-protocol-header-timeout"
)
var (
@ -125,6 +127,17 @@ func ReadConfig(src map[string]string) config.Configuration {
}
}
// Verify that the configured timeout is parsable as a duration. if not, set the default value
if val, ok := conf[proxyHeaderTimeout]; ok {
delete(conf, proxyHeaderTimeout)
duration, err := time.ParseDuration(val)
if err != nil {
glog.Warningf("proxy-protocol-header-timeout of %v encounted an error while being parsed %v. Switching to use default value instead.", val, err)
} else {
to.ProxyProtocolHeaderTimeout = duration
}
}
streamResponses := 1
if val, ok := conf[proxyStreamResponses]; ok {
delete(conf, proxyStreamResponses)

View file

@ -19,6 +19,7 @@ package template
import (
"reflect"
"testing"
"time"
"github.com/kylelemons/godebug/pretty"
@ -32,6 +33,22 @@ func TestFilterErrors(t *testing.T) {
}
}
func TestProxytTimeoutParsing(t *testing.T) {
testCases := map[string]struct {
input string
expect time.Duration // duration in seconds
}{
"valid duration": {"35s", time.Duration(35) * time.Second},
"invalid duration": {"3zxs", time.Duration(5) * time.Second},
}
for n, tc := range testCases {
cfg := ReadConfig(map[string]string{"proxy-protocol-header-timeout": tc.input})
if cfg.ProxyProtocolHeaderTimeout.Seconds() != tc.expect.Seconds() {
t.Errorf("Testing %v. Expected %v seconds but got %v seconds", n, tc.expect, cfg.ProxyProtocolHeaderTimeout)
}
}
}
func TestMergeConfigMapToStruct(t *testing.T) {
conf := map[string]string{
"custom-http-errors": "300,400,demo",