Skip to content

Commit b0d347c

Browse files
author
OpenShift Bot
authored
Merge pull request #9671 from JacobTanenbaum/RouterTimeouts
Merged by openshift-bot
2 parents 7f8f3f2 + c1db34b commit b0d347c

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

images/router/haproxy/conf/haproxy-config.template

+16
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ backend be_edge_http_{{$cfgIdx}}
226226
{{ else }}
227227
balance leastconn
228228
{{ end }}
229+
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}}
230+
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
231+
timeout server {{$value}}
232+
{{ end }}
233+
{{ end }}
229234
timeout check 5000ms
230235
http-request set-header X-Forwarded-Host %[req.hdr(host)]
231236
http-request set-header X-Forwarded-Port %[dst_port]
@@ -259,6 +264,11 @@ backend be_tcp_{{$cfgIdx}}
259264
{{ else }}
260265
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source" }}
261266
{{ end }}
267+
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}}
268+
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
269+
timeout server {{$value}}
270+
{{ end }}
271+
{{ end }}
262272
hash-type consistent
263273
timeout check 5000ms
264274
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}
@@ -282,6 +292,12 @@ backend be_secure_{{$cfgIdx}}
282292
{{ else }}
283293
balance leastconn
284294
{{ end }}
295+
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}}
296+
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
297+
timeout server {{$value}}
298+
{{ end }}
299+
{{ end }}
300+
285301
timeout check 5000ms
286302
cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly secure
287303
{{ range $serviceUnitName, $weight := $cfg.ServiceUnitNames }}

pkg/router/template/plugin.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ func env(name, defaultValue string) string {
9797
func NewTemplatePlugin(cfg TemplatePluginConfig) (*TemplatePlugin, error) {
9898
templateBaseName := filepath.Base(cfg.TemplatePath)
9999
globalFuncs := template.FuncMap{
100-
"endpointsForAlias": endpointsForAlias,
101-
"env": env,
102-
"matchString": matchString,
103-
"isInteger": isInteger,
104-
"matchValues": matchValues,
100+
"endpointsForAlias": endpointsForAlias, //returns the list of valid endpoints
101+
"env": env, //tries to get an environment variable if it can't return a default
102+
"matchPattern": matchPattern, //anchors provided regular expression and evaluates against given string
103+
"isInteger": isInteger, //determines if a given variable is an integer
104+
"matchValues": matchValues, //compares a given string to a list of allowed strings
105105
}
106106
masterTemplate, err := template.New("config").Funcs(globalFuncs).ParseFiles(cfg.TemplatePath)
107107
if err != nil {

pkg/router/template/router.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ func matchValues(s string, allowedValues ...string) bool {
187187
return false
188188
}
189189

190-
func matchString(pattern, s string) bool {
191-
glog.V(4).Infof("Matchstring called with %s and %s", pattern, s)
192-
status, err := regexp.MatchString(pattern, s)
190+
func matchPattern(pattern, s string) bool {
191+
glog.V(4).Infof("matchPattern called with %s and %s", pattern, s)
192+
status, err := regexp.MatchString("^("+pattern+")$", s)
193193
if err == nil {
194-
glog.V(4).Infof("Matchstring returning status: %v", status)
194+
glog.V(4).Infof("matchPattern returning status: %v", status)
195195
return status
196196
}
197-
glog.Errorf("Error with regex pattern in call to matchString: %v", err)
197+
glog.Errorf("Error with regex pattern in call to matchPattern: %v", err)
198198
return false
199199
}
200200

0 commit comments

Comments
 (0)