Skip to content

Commit

Permalink
Add configure option for Haproxy default timeout. (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadlil authored and tamalsaha committed Jul 12, 2017
1 parent fa53e0d commit 05dd1bd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
60 changes: 58 additions & 2 deletions api/annotations.go
Expand Up @@ -47,12 +47,12 @@ const (
// https://github.com/appscode/voyager/issues/103
// ServiceAnnotations is user provided annotations map that will be
// applied to the service of that LoadBalancer.
// ex: "ingress.appscode.com/service.annotation": {"key": "val"}
// ex: "ingress.appscode.com/annotations-service": {"key": "val"}
ServiceAnnotations = EngressKey + "/" + "annotations-service"

// PodAnnotations is user provided annotations map that will be
// applied to the Pods (Deployment/ DaemonSet) of that LoadBalancer.
// ex: "ingress.appscode.com/service.annotation": {"key": "val"}
// ex: "ingress.appscode.com/annotations-pod": {"key": "val"}
PodAnnotations = EngressKey + "/" + "annotations-pod"

// Preserves source IP for LoadBalancer type ingresses. The actual configuration
Expand Down Expand Up @@ -82,6 +82,21 @@ const (
OriginName = EngressKey + "/" + "origin-name"

EgressPoints = EngressKey + "/" + "egress-points"

// https://github.com/appscode/voyager/issues/280
// Supports all valid timeout option for defaults section of HAProxy
// https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#4.2-timeout%20check
// expects a json encoded map
// ie: "ingress.appscode.com/default-timeout": {"client": "5s"}
//
// If the annotation is not set default values used to config defaults section will be:
//
// timeout connect 50000
// timeout client 50000
// timeout client-fin 50000
// timeout server 50000
// timeout tunnel 50000
DefaultsTimeOut = EngressKey + "/" + "default-timeout"
)

func (r Ingress) OffshootName() string {
Expand Down Expand Up @@ -214,6 +229,47 @@ func (r Ingress) KeepSourceIP() bool {
return v
}

var timeoutDefaults = map[string]string{
// Maximum time to wait for a connection attempt to a server to succeed.
"connect": "50000",

// Maximum inactivity time on the client side.
// Applies when the client is expected to acknowledge or send data.
"client": "50000",

// Inactivity timeout on the client side for half-closed connections.
// Applies when the client is expected to acknowledge or send data
// while one direction is already shut down.
"client-fin": "50000",

// Maximum inactivity time on the server side.
"server": "50000",

// Timeout to use with WebSocket and CONNECT
"tunnel": "50000",
}

func (r Ingress) Timeouts() map[string]string {
ans, _ := getMap(r.Annotations, DefaultsTimeOut)
if ans == nil {
ans = make(map[string]string)
}

// If the timeouts specified in `defaultTimeoutValues` are not set specifically set
// we need to set default timeout values.
// An unspecified timeout results in an infinite timeout, which
// is not recommended. Such a usage is accepted and works but reports a warning
// during startup because it may results in accumulation of expired sessions in
// the system if the system's timeouts are not configured either.
for k, v := range timeoutDefaults {
if _, ok := ans[k]; !ok {
ans[k] = v
}
}

return ans
}

// ref: https://github.com/kubernetes/kubernetes/blob/078238a461a0872a8eacb887fbb3d0085714604c/staging/src/k8s.io/apiserver/pkg/apis/example/v1/types.go#L134
// Deprecated, for newer ones use '{"k1":"v1", "k2", "v2"}' form
// This expects the form k1=v1,k2=v2
Expand Down
7 changes: 7 additions & 0 deletions api/annotations_test.go
Expand Up @@ -36,3 +36,10 @@ func TestGetMap(t *testing.T) {
actual, _ := getMap(in, "k1")
assert.Equal(t, map[string]string{"o1": "v1"}, actual)
}

func TestGetTimeOuts(t *testing.T) {
ing := &Ingress{}
timeouts := ing.Timeouts()

assert.Equal(t, timeouts, timeoutDefaults)
}

0 comments on commit 05dd1bd

Please sign in to comment.