Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure default backend to not change backend ID #681

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/converters/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c *converter) syncDefaultCrt() {
func (c *converter) syncDefaultBackend() {
if c.options.DefaultBackend != "" {
if backend, err := c.addBackend(&c.defaultBackSource, hatypes.DefaultHost, "/", c.options.DefaultBackend, "", map[string]string{}); err == nil {
c.haproxy.Backends().SetDefaultBackend(backend)
c.haproxy.Backends().DefaultBackend = backend
c.tracker.TrackHostname(convtypes.IngressType, c.defaultBackSource.FullName(), hatypes.DefaultHost)
} else {
c.logger.Error("error reading default service: %v", err)
Expand Down
26 changes: 13 additions & 13 deletions pkg/converters/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestSyncSvcPortNotFound(t *testing.T) {
`)

c.compareConfigBack(`
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestSyncSvcNamedPort(t *testing.T) {
endpoints:
- ip: 172.17.1.101
port: 8080
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestSyncDrainSupport(t *testing.T) {
- ip: 172.17.1.103
port: 8080
drain: true
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080
Expand Down Expand Up @@ -764,7 +764,7 @@ func TestSyncBackendReuseDefaultSvc(t *testing.T) {
- hostname: default.example.com
paths:
- path: /app
backend: _default_backend`)
backend: system_default_8080`)

c.compareConfigDefaultFront(`[]`)
c.compareConfigBack(defaultBackendConfig)
Expand Down Expand Up @@ -1141,7 +1141,7 @@ WARN using default certificate due to an error reading secret 'default/tls1' on
- ip: 172.17.0.11
port: 8080
balancealgorithm: leastcon
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080`,
Expand Down Expand Up @@ -1173,7 +1173,7 @@ WARN using default certificate due to an error reading secret 'default/tls1' on
- ip: 172.17.0.12
port: 8080
balancealgorithm: leastcon
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080`,
Expand Down Expand Up @@ -1203,7 +1203,7 @@ WARN using default certificate due to an error reading secret 'default/tls1' on
- ip: 172.17.0.11
port: 8080
balancealgorithm: leastcon
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080`,
Expand All @@ -1221,7 +1221,7 @@ WARN using default certificate due to an error reading secret 'default/tls1' on
endpoints:
- ip: 172.17.0.11
port: 8080
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080`,
Expand All @@ -1246,7 +1246,7 @@ WARN using default certificate due to an error reading secret 'default/tls1' on
endpoints:
- ip: 172.17.0.12
port: 8080
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080`,
Expand Down Expand Up @@ -1363,7 +1363,7 @@ func TestSyncPartialDefaultBackend(t *testing.T) {

c.compareConfigFront(`[]`)
c.compareConfigBack(`
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.90
port: 8080
Expand Down Expand Up @@ -1627,7 +1627,7 @@ func TestSyncAnnBackDefault(t *testing.T) {
- ip: 172.17.0.17
port: 8080
balancealgorithm: roundrobin
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080
Expand Down Expand Up @@ -1688,7 +1688,7 @@ func TestSyncAnnPassthrough(t *testing.T) {
endpoints:
- ip: 172.17.1.101
port: 8443
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080
Expand Down Expand Up @@ -1741,7 +1741,7 @@ paths:
backend: default_echo1_8080`

var defaultBackendConfig = `
- id: _default_backend
- id: system_default_8080
endpoints:
- ip: 172.17.0.99
port: 8080`
Expand Down
2 changes: 1 addition & 1 deletion pkg/haproxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *config) SyncConfig() {
// TODO c.defaultBackend can be nil; create a valid
// _error404 backend, remove `if nil` from host.AddPath()
// and from `for range host.Paths` on map building.
back = c.backends.DefaultBackend()
back = c.backends.DefaultBackend
}
host.AddPath(back, "/", hatypes.MatchBegin)
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/haproxy/dynupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ set server default_app_8080/srv002 weight 1
{
doconfig1: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
b2.AcquireEndpoint("172.17.0.2", 8080, "")
},
doconfig2: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
b1.Dynamic.DynUpdate = true
b1.Dynamic.MinFreeSlots = 1
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
b2.Dynamic.DynUpdate = true
b2.AcquireEndpoint("172.17.0.2", 8080, "")
Expand Down Expand Up @@ -588,7 +588,7 @@ set server default_app_8080/srv002 weight 1`,
{
doconfig1: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
// some of these are unnecessary but the attempt is to have as
// realistic config as possible for a more reliable test
Expand All @@ -604,7 +604,7 @@ set server default_app_8080/srv002 weight 1`,
doconfig2: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
b1.Dynamic.DynUpdate = true
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
b2.Dynamic.DynUpdate = true
// some of these are unnecessary but the attempt is to have as
Expand Down Expand Up @@ -637,7 +637,7 @@ set server default_app_8080/srv002 weight 1
{
doconfig1: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
// some of these are unnecessary but the attempt is to have as
// realistic config as possible for a more reliable test
Expand All @@ -653,7 +653,7 @@ set server default_app_8080/srv002 weight 1
doconfig2: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
b1.Dynamic.DynUpdate = true
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
b2.Dynamic.DynUpdate = true
// some of these are unnecessary but the attempt is to have as
Expand Down Expand Up @@ -683,7 +683,7 @@ set server default_app_8080/srv002 weight 1
{
doconfig1: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
// some of these are unnecessary but the attempt is to have as
// realistic config as possible for a more reliable test
Expand All @@ -699,7 +699,7 @@ set server default_app_8080/srv002 weight 1
doconfig2: func(c *testConfig) {
b1 := c.config.Backends().AcquireBackend("default", "default_backend", "8080")
b1.Dynamic.DynUpdate = true
c.config.Backends().SetDefaultBackend(b1)
c.config.Backends().DefaultBackend = b1
b2 := c.config.Backends().AcquireBackend("default", "app", "8080")
b2.Dynamic.DynUpdate = true
// some of these are unnecessary but the attempt is to have as
Expand Down Expand Up @@ -730,12 +730,12 @@ set server default_app_8080/srv002 weight 1`,
{
doconfig1: func(c *testConfig) {
b := c.config.Backends().AcquireBackend("default", "app", "8080")
c.config.backends.SetDefaultBackend(b)
c.config.backends.DefaultBackend = b
b.AcquireEndpoint("172.17.0.2", 8080, "")
},
doconfig2: func(c *testConfig) {
b := c.config.Backends().AcquireBackend("default", "app", "8080")
c.config.backends.SetDefaultBackend(b)
c.config.backends.DefaultBackend = b
b.Dynamic.DynUpdate = true
b.AcquireEndpoint("172.17.0.3", 8080, "")
},
Expand All @@ -744,10 +744,10 @@ set server default_app_8080/srv002 weight 1`,
},
dynamic: true,
cmd: `
set server _default_backend/srv001 addr 172.17.0.3 port 8080
set server _default_backend/srv001 state ready
set server _default_backend/srv001 weight 1`,
logging: `INFO-V(2) updated endpoint '172.17.0.3:8080' weight '1' state 'ready' on backend/server '_default_backend/srv001'`,
set server default_app_8080/srv001 addr 172.17.0.3 port 8080
set server default_app_8080/srv001 state ready
set server default_app_8080/srv001 weight 1`,
logging: `INFO-V(2) updated endpoint '172.17.0.3:8080' weight '1' state 'ready' on backend/server 'default_app_8080/srv001'`,
},
}
for i, test := range testCases {
Expand Down
32 changes: 16 additions & 16 deletions pkg/haproxy/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ func TestInstanceDefaultHost(t *testing.T) {

def := c.config.Backends().AcquireBackend("default", "default-backend", "8080")
def.Endpoints = []*hatypes.Endpoint{endpointS0}
c.config.Backends().SetDefaultBackend(def)
c.config.Backends().DefaultBackend = def

var h *hatypes.Host
var b *hatypes.Backend
Expand Down Expand Up @@ -1471,7 +1471,7 @@ backend d2_app_8080
acl https-request ssl_fc
http-request redirect scheme https if !https-request
server s1 172.17.0.11:8080 weight 100
backend _default_backend
backend default_default-backend_8080
mode http
server s0 172.17.0.99:8080 weight 100
frontend _front_http
Expand All @@ -1484,7 +1484,7 @@ frontend _front_http
http-request set-var(req.backend) var(req.base),lower,map_beg(/etc/haproxy/maps/_front_http_host__begin.map)
use_backend %[var(req.backend)] if { var(req.backend) -m found }
use_backend d1_app_8080
default_backend _default_backend
default_backend default_default-backend_8080
frontend _front_https
mode http
bind :443 ssl alpn h2,http/1.1 crt-list /etc/haproxy/maps/_front_bind_crt.list ca-ignore-err all crt-ignore-err all
Expand All @@ -1495,7 +1495,7 @@ frontend _front_https
<<https-headers>>
use_backend %[var(req.hostbackend)] if { var(req.hostbackend) -m found }
use_backend d1_app_8080
default_backend _default_backend
default_backend default_default-backend_8080
<<support>>
`)

Expand Down Expand Up @@ -1605,7 +1605,7 @@ func TestInstanceFrontend(t *testing.T) {

def := c.config.Backends().AcquireBackend("default", "default-backend", "8080")
def.Endpoints = []*hatypes.Endpoint{endpointS0}
c.config.Backends().SetDefaultBackend(def)
c.config.Backends().DefaultBackend = def

var h *hatypes.Host
var b *hatypes.Backend
Expand Down Expand Up @@ -1641,7 +1641,7 @@ backend d2_app_8080
acl https-request ssl_fc
http-request redirect scheme https if !https-request
server s1 172.17.0.11:8080 weight 100
backend _default_backend
backend default_default-backend_8080
mode http
server s0 172.17.0.99:8080 weight 100
frontend _front_http
Expand All @@ -1655,7 +1655,7 @@ frontend _front_http
http-request set-var(req.backend) var(req.base),map_dir(/etc/haproxy/maps/_front_http_host__prefix.map)
http-request set-var(req.backend) var(req.base),lower,map_beg(/etc/haproxy/maps/_front_http_host__begin.map) if !{ var(req.backend) -m found }
use_backend %[var(req.backend)] if { var(req.backend) -m found }
default_backend _default_backend
default_backend default_default-backend_8080
frontend _front_https
mode http
bind :443 ssl alpn h2,http/1.1 crt-list /etc/haproxy/maps/_front_bind_crt.list ca-ignore-err all crt-ignore-err all
Expand All @@ -1667,7 +1667,7 @@ frontend _front_https
http-request set-var(txn.namespace) str(-) if !{ var(txn.namespace) -m found }
<<https-headers>>
use_backend %[var(req.hostbackend)] if { var(req.hostbackend) -m found }
default_backend _default_backend
default_backend default_default-backend_8080
<<support>>
`)

Expand Down Expand Up @@ -1705,7 +1705,7 @@ func TestInstanceFrontendCA(t *testing.T) {

def := c.config.Backends().AcquireBackend("default", "default-backend", "8080")
def.Endpoints = []*hatypes.Endpoint{endpointS0}
c.config.Backends().SetDefaultBackend(def)
c.config.Backends().DefaultBackend = def

var h *hatypes.Host
var b *hatypes.Backend
Expand Down Expand Up @@ -1774,7 +1774,7 @@ backend d_app_8080
http-request set-header X-SSL-Client-SHA1 %{+Q}[ssl_c_sha1,hex,lower]
http-request set-header X-SSL-Client-Cert %{+Q}[ssl_c_der,base64]
server s1 172.17.0.11:8080 weight 100
backend _default_backend
backend default_default-backend_8080
mode http
server s0 172.17.0.99:8080 weight 100
frontend _front_http
Expand All @@ -1785,7 +1785,7 @@ frontend _front_http
http-request set-var(req.backend) var(req.base),lower,map_beg(/etc/haproxy/maps/_front_http_host__begin.map)
http-request set-var(req.backend) var(req.base),map_reg(/etc/haproxy/maps/_front_http_host__regex.map) if !{ var(req.backend) -m found }
use_backend %[var(req.backend)] if { var(req.backend) -m found }
default_backend _default_backend
default_backend default_default-backend_8080
frontend _front_https
mode http
bind :443 ssl alpn h2,http/1.1 crt-list /etc/haproxy/maps/_front_bind_crt.list ca-ignore-err all crt-ignore-err all
Expand Down Expand Up @@ -1818,7 +1818,7 @@ frontend _front_https
http-request use-service lua.send-495 if { var(req.tls_invalidcrt_redir) _internal }
use_backend %[var(req.hostbackend)] if { var(req.hostbackend) -m found }
use_backend %[var(req.snibackend)] if { var(req.snibackend) -m found }
default_backend _default_backend
default_backend default_default-backend_8080
<<support>>
`)

Expand Down Expand Up @@ -1881,7 +1881,7 @@ func TestInstanceSomePaths(t *testing.T) {

def := c.config.Backends().AcquireBackend("default", "default-backend", "8080")
def.Endpoints = []*hatypes.Endpoint{endpointS0}
c.config.Backends().SetDefaultBackend(def)
c.config.Backends().DefaultBackend = def

var h *hatypes.Host
var b *hatypes.Backend
Expand Down Expand Up @@ -1930,13 +1930,13 @@ backend d_app3_8080
server s31 172.17.0.131:8080 weight 100
server s32 172.17.0.132:8080 weight 100
server s33 172.17.0.133:8080 weight 100
backend _default_backend
backend default_default-backend_8080
mode http
server s0 172.17.0.99:8080 weight 100
<<frontend-http>>
default_backend _default_backend
default_backend default_default-backend_8080
<<frontend-https>>
default_backend _default_backend
default_backend default_default-backend_8080
<<support>>
`)

Expand Down
Loading