Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
k8s-ingress
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
uplex-varnish
k8s-ingress
Commits
a5c865d8
Commit
a5c865d8
authored
Jun 12, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
varnish.Controller.HasConfig() checks for changed viking Endpoints.
parent
aa6c23e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
16 deletions
+138
-16
ingress.go
pkg/controller/ingress.go
+3
-3
varnish.go
pkg/varnish/varnish.go
+19
-2
varnish_test.go
pkg/varnish/varnish_test.go
+116
-11
No files found.
pkg/controller/ingress.go
View file @
a5c865d8
...
...
@@ -1011,7 +1011,7 @@ func (worker *NamespaceWorker) addOrUpdateIng(ing *extensions.Ingress) error {
}
}
_
,
offldAddrs
,
err
:=
worker
.
svc2Addrs
(
svc
)
addrs
,
offldAddrs
,
err
:=
worker
.
svc2Addrs
(
svc
)
if
err
!=
nil
{
return
err
}
...
...
@@ -1053,8 +1053,8 @@ func (worker *NamespaceWorker) addOrUpdateIng(ing *extensions.Ingress) error {
worker
.
log
.
Tracef
(
"Check if config is loaded: hash=%s "
+
"ingressMetaData=%+v vcfgMetaData=%+v bcfgMetaData=%+v"
,
vclSpec
.
Canonical
()
.
DeepHash
(),
ingsMeta
,
vcfgMeta
,
bcfgMeta
)
if
worker
.
vController
.
HasConfig
(
svcKey
,
vclSpec
,
ingsMeta
,
vcfg
Meta
,
bcfgMeta
)
{
if
worker
.
vController
.
HasConfig
(
svcKey
,
addrs
,
vclSpec
,
ings
Meta
,
vcfgMeta
,
bcfgMeta
)
{
worker
.
log
.
Infof
(
"Varnish Service %s: config already "
+
"loaded: hash=%s"
,
svcKey
,
vclSpec
.
Canonical
()
.
DeepHash
())
...
...
pkg/varnish/varnish.go
View file @
a5c865d8
...
...
@@ -685,8 +685,8 @@ func (vc *Controller) SetNotReady(svcKey string) error {
// ingsMeta: Ingress meta-data
// vcfgMeta: VarnishConfig meta-data
// bcfgMeta: BackendConfig meta-data
func
(
vc
*
Controller
)
HasConfig
(
svcKey
string
,
spec
vcl
.
Spec
,
ingsMeta
map
[
string
]
Meta
,
vcfgMeta
Meta
,
func
(
vc
*
Controller
)
HasConfig
(
svcKey
string
,
addrs
[]
vcl
.
Address
,
spec
vcl
.
Spec
,
ingsMeta
map
[
string
]
Meta
,
vcfgMeta
Meta
,
bcfgMeta
map
[
string
]
Meta
)
bool
{
svc
,
ok
:=
vc
.
svcs
[
svcKey
]
...
...
@@ -711,6 +711,23 @@ func (vc *Controller) HasConfig(svcKey string, spec vcl.Spec,
if
svc
.
spec
.
bcfg
==
nil
{
return
false
}
if
len
(
addrs
)
!=
len
(
svc
.
instances
)
{
return
false
}
newAddrs
:=
make
(
map
[
string
]
struct
{})
for
_
,
addr
:=
range
addrs
{
a
:=
addr
.
IP
+
":"
+
strconv
.
Itoa
(
int
(
addr
.
Port
))
newAddrs
[
a
]
=
struct
{}{}
}
curAddrs
:=
make
(
map
[
string
]
struct
{})
for
_
,
inst
:=
range
svc
.
instances
{
curAddrs
[
inst
.
addr
]
=
struct
{}{}
}
if
!
reflect
.
DeepEqual
(
newAddrs
,
curAddrs
)
{
return
false
}
if
len
(
bcfgMeta
)
!=
len
(
svc
.
spec
.
bcfg
)
{
return
false
}
...
...
pkg/varnish/varnish_test.go
View file @
a5c865d8
...
...
@@ -30,6 +30,7 @@ package varnish
import
(
"fmt"
"strconv"
"strings"
"testing"
...
...
@@ -199,6 +200,17 @@ var vcfgMeta = Meta{
Ver
:
"37337"
,
}
var
svcAddrs
=
[]
vcl
.
Address
{
vcl
.
Address
{
IP
:
"12.34.56.78"
,
Port
:
6081
,
},
vcl
.
Address
{
IP
:
"87.65.43.21"
,
Port
:
6081
,
},
}
func
TestHasConfig
(
t
*
testing
.
T
)
{
spec
:=
vclSpec
{
spec
:
cafeSpec
,
...
...
@@ -206,8 +218,15 @@ func TestHasConfig(t *testing.T) {
vcfg
:
vcfgMeta
,
bcfg
:
bcfgsMeta
,
}
instances
:=
make
([]
*
varnishInst
,
len
(
svcAddrs
))
for
i
,
addr
:=
range
svcAddrs
{
instances
[
i
]
=
&
varnishInst
{
addr
:
addr
.
IP
+
":"
+
strconv
.
Itoa
(
int
(
addr
.
Port
)),
}
}
vSvc
:=
varnishSvc
{
spec
:
&
spec
,
instances
:
instances
,
cfgLoaded
:
true
,
}
vc
:=
Controller
{
...
...
@@ -215,19 +234,98 @@ func TestHasConfig(t *testing.T) {
}
svcKey
:=
"default/cafe-ingress"
if
!
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
if
!
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
(
"HasConfig() got:false want:true"
)
}
if
vc
.
HasConfig
(
svcKey
,
[]
vcl
.
Address
{},
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
(
"HasConfig(empty address slice) got:true want:false"
)
}
if
vc
.
HasConfig
(
svcKey
,
nil
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
(
"HasConfig(nil address slice) got:true want:false"
)
}
testAddrs
:=
[]
vcl
.
Address
{
vcl
.
Address
{
IP
:
"87.65.43.21"
,
Port
:
6081
,
},
vcl
.
Address
{
IP
:
"12.34.56.78"
,
Port
:
6081
,
},
}
if
!
vc
.
HasConfig
(
svcKey
,
testAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
(
"HasConfig(reordered address slice) got:false "
,
"want:true"
)
}
testAddrs
=
[]
vcl
.
Address
{
vcl
.
Address
{
IP
:
"1.2.3.4"
,
Port
:
6082
,
},
vcl
.
Address
{
IP
:
"8.7.6.5"
,
Port
:
6082
,
},
}
if
vc
.
HasConfig
(
svcKey
,
testAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
f
(
"HasConfig() got:false want:tru
e"
)
t
.
Error
(
"HasConfig(changed addresses) got:true want:fals
e"
)
}
if
vc
.
HasConfig
(
"ns/name"
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
testAddrs
=
[]
vcl
.
Address
{
vcl
.
Address
{
IP
:
"12.34.56.78"
,
Port
:
6081
,
},
}
if
vc
.
HasConfig
(
svcKey
,
testAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
(
"HasConfig(fewer addresses) got:true want:false"
)
}
testAddrs
=
[]
vcl
.
Address
{
vcl
.
Address
{
IP
:
"12.34.56.78"
,
Port
:
6081
,
},
vcl
.
Address
{
IP
:
"87.65.43.21"
,
Port
:
6081
,
},
vcl
.
Address
{
IP
:
"47.11.08.15"
,
Port
:
6081
,
},
}
if
vc
.
HasConfig
(
svcKey
,
testAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Error
(
"HasConfig(more addresses) got:true want:false"
)
}
if
vc
.
HasConfig
(
"ns/name"
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Errorf
(
"HasConfig(unknown Service) got:true want:false"
)
}
vSvc
.
cfgLoaded
=
false
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Errorf
(
"HasConfig(cfgLoaded=false) got:true want:false"
)
}
...
...
@@ -235,7 +333,8 @@ func TestHasConfig(t *testing.T) {
otherVcfg
:=
vcfgMeta
otherVcfg
.
Ver
=
"37338"
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
ingsMeta
,
otherVcfg
,
bcfgsMeta
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
otherVcfg
,
bcfgsMeta
)
{
t
.
Errorf
(
"HasConfig(changed VarnishConfig) got:true want:false"
)
}
...
...
@@ -245,7 +344,8 @@ func TestHasConfig(t *testing.T) {
otherIngs
[
k
]
=
v
}
otherIngs
[
"key"
]
=
Meta
{}
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
otherIngs
,
vcfgMeta
,
bcfgsMeta
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
otherIngs
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Errorf
(
"HasConfig(more Ingresses) got:true want:false"
)
}
...
...
@@ -256,13 +356,15 @@ func TestHasConfig(t *testing.T) {
UID
:
"123e4567-e89b-12d3-a456-426655440000"
,
Ver
:
"123457"
,
}
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
otherIngs
,
vcfgMeta
,
bcfgsMeta
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
otherIngs
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Errorf
(
"HasConfig(changed Ingresses) got:true want:false"
)
}
delete
(
otherIngs
,
"default/cafe"
)
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
otherIngs
,
vcfgMeta
,
bcfgsMeta
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
otherIngs
,
vcfgMeta
,
bcfgsMeta
)
{
t
.
Errorf
(
"HasConfig(fewer Ingresses) got:true want:false"
)
}
...
...
@@ -272,7 +374,8 @@ func TestHasConfig(t *testing.T) {
otherBcfgs
[
k
]
=
v
}
otherBcfgs
[
"key"
]
=
Meta
{}
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
otherBcfgs
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
otherBcfgs
)
{
t
.
Errorf
(
"HasConfig(more BackendConfigs) got:true want:false"
)
}
...
...
@@ -283,13 +386,15 @@ func TestHasConfig(t *testing.T) {
UID
:
"6ba7b810-9dad-11d1-80b4-00c04fd430c8"
,
Ver
:
"010102"
,
}
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
otherBcfgs
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
otherBcfgs
)
{
t
.
Errorf
(
"HasConfig(changed BackendConfigs) got:true want:false"
)
}
delete
(
otherBcfgs
,
"coffee-svc"
)
if
vc
.
HasConfig
(
svcKey
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
otherBcfgs
)
{
if
vc
.
HasConfig
(
svcKey
,
svcAddrs
,
cafeSpecShuf
,
ingsMeta
,
vcfgMeta
,
otherBcfgs
)
{
t
.
Errorf
(
"HasConfig(fewer BackendConfigs) got:true want:false"
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment