Skip to content

Commit

Permalink
Fixes #419: Allow configuration of haproxy option persist
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Wöckinger committed Nov 17, 2022
1 parent 3065f65 commit 4d65c7f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions images/router/haproxy/conf/haproxy-config.template
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ backend openshift_default
backend {{ genBackendNamePrefix $cfg.TLSTermination }}:{{ $cfgIdx }}
mode http
option redispatch
{{- if isTrue (index $cfg.Annotations "haproxy.router.openshift.io/persist") }}
option persist
{{- end }}
{{- with $setHeaders := firstMatch $setForwardedHeadersPattern (index $cfg.Annotations $setForwardedHeadersAnnotation) $setForwardedHeadersDefaultValue }}
{{- if eq $setHeaders "append" }}
option forwardfor
Expand Down
32 changes: 32 additions & 0 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,26 @@ func TestConfigTemplate(t *testing.T) {
},
},
},
"Forced persistence on down servers": {
mustCreateWithConfig{
mustCreate: mustCreate{
name: "p",
host: "pexample.com",
path: "",
time: start,
annotations: map[string]string{
"haproxy.router.openshift.io/persist": "true",
},
tlsTermination: routev1.TLSTerminationEdge,
},
mustMatchConfig: mustMatchConfig{
section: "backend",
sectionName: edgeBackendName(h.namespace, "p"),
attribute: "option",
value: "persist",
},
},
},
"Simple HSTS header": {
mustCreateWithConfig{
mustCreate: mustCreate{
Expand Down Expand Up @@ -514,6 +534,18 @@ type mustMatchConfig struct {
}

func (m mustMatchConfig) Match(parser haproxyconfparser.Parser) error {
if m.attribute == "option" {
cfg := fmt.Sprintf("%s", parser)
start :=strings.Index(cfg, m.sectionName)
backends := cfg[start:]
end := strings.Index(backends, "backend")
backend := backends[:end]
if strings.Contains(backend, "option " + m.value) {
return nil
}
return fmt.Errorf("unable to find option [%s]", m.value)
}

data, err := parser.Get(haproxyconfparser.Section(m.section), m.sectionName, m.attribute)
if err != nil {
if m.notFound {
Expand Down

0 comments on commit 4d65c7f

Please sign in to comment.