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
46bab65a
Commit
46bab65a
authored
Mar 27, 2019
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename varnish.VarnishAdmError[s] as AdmError[s].
Silences a golint "stutter" warning.
parent
ce413e56
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
25 deletions
+25
-25
varnish.go
pkg/varnish/varnish.go
+18
-18
varnish_test.go
pkg/varnish/varnish_test.go
+7
-7
No files found.
pkg/varnish/varnish.go
View file @
46bab65a
...
...
@@ -66,9 +66,9 @@ var (
admTimeout
=
time
.
Second
*
10
)
//
Varnish
AdmError encapsulates an error encountered for an individual
// AdmError encapsulates an error encountered for an individual
// Varnish instance, and satisfies the Error interface.
type
Varnish
AdmError
struct
{
type
AdmError
struct
{
addr
string
err
error
}
...
...
@@ -76,24 +76,24 @@ type VarnishAdmError struct {
// Error returns an error meesage for an error encountered at a
// Varnish instance, identifying the instance by its Endpoint address
// (internal IP) and admin port.
func
(
vadmErr
Varnish
AdmError
)
Error
()
string
{
func
(
vadmErr
AdmError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"%s: %v"
,
vadmErr
.
addr
,
vadmErr
.
err
)
}
//
Varnish
AdmErrors is a collection of errors encountered at Varnish
// AdmErrors is a collection of errors encountered at Varnish
// instances. Most attempts to sync the state of Varnish instances do
// not break off at the first error; the attempt is repeated for each
// instance in a cluster, collecting error information along the way.
// This object contains error information for each instance in a
// cluster that failed to sync. The type satisifies the Error
// interface.
type
VarnishAdmErrors
[]
Varnish
AdmError
type
AdmErrors
[]
AdmError
// Error returns an error message that includes errors for each
// instance in a Varnish cluster that failed a sync operation, where
// each instance is identified by it Endpoint (internal IP) and admin
// port.
func
(
vadmErrs
Varnish
AdmErrors
)
Error
()
string
{
func
(
vadmErrs
AdmErrors
)
Error
()
string
{
var
sb
strings
.
Builder
sb
.
WriteRune
(
'['
)
for
_
,
err
:=
range
vadmErrs
{
...
...
@@ -321,7 +321,7 @@ func (vc *VarnishController) updateVarnishSvc(name string) error {
vc
.
log
.
Infof
(
"Update Varnish instances: load config %s"
,
cfgName
)
vc
.
log
.
Tracef
(
"Config %s source: %s"
,
cfgName
,
vclSrc
)
var
errs
Varnish
AdmErrors
var
errs
AdmErrors
for
_
,
inst
:=
range
svc
.
instances
{
if
inst
==
nil
{
vc
.
log
.
Errorf
(
"Instance object is nil"
)
...
...
@@ -332,7 +332,7 @@ func (vc *VarnishController) updateVarnishSvc(name string) error {
if
e
:=
vc
.
updateVarnishInstance
(
inst
,
cfgName
,
vclSrc
,
metrics
);
e
!=
nil
{
admErr
:=
Varnish
AdmError
{
addr
:
inst
.
addr
,
err
:
e
}
admErr
:=
AdmError
{
addr
:
inst
.
addr
,
err
:
e
}
errs
=
append
(
errs
,
admErr
)
metrics
.
updateErrs
.
Inc
()
continue
...
...
@@ -352,7 +352,7 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst,
cfg
,
lbl
string
,
mayClose
bool
)
error
{
if
inst
.
admSecret
==
nil
{
return
Varnish
AdmError
{
return
AdmError
{
addr
:
inst
.
addr
,
err
:
fmt
.
Errorf
(
"No known admin secret"
),
}
...
...
@@ -374,7 +374,7 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst,
return
nil
}
metrics
.
connectFails
.
Inc
()
return
Varnish
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
return
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
}
defer
adm
.
Close
()
inst
.
Banner
=
adm
.
Banner
...
...
@@ -388,7 +388,7 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst,
inst
.
addr
)
return
nil
}
return
Varnish
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
return
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
}
}
return
nil
...
...
@@ -396,14 +396,14 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst,
// On Delete for a Varnish instance, we set it to the unready state.
func
(
vc
*
VarnishController
)
removeVarnishInstances
(
insts
[]
*
varnishInst
)
error
{
var
errs
Varnish
AdmErrors
var
errs
AdmErrors
for
_
,
inst
:=
range
insts
{
// XXX health check for sharding config should fail
if
err
:=
vc
.
setCfgLabel
(
inst
,
notAvailCfg
,
readinessLabel
,
true
);
err
!=
nil
{
admErr
:=
Varnish
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
admErr
:=
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
errs
=
append
(
errs
,
admErr
)
continue
}
...
...
@@ -418,7 +418,7 @@ func (vc *VarnishController) removeVarnishInstances(insts []*varnishInst) error
func
(
vc
*
VarnishController
)
updateVarnishSvcAddrs
(
key
string
,
addrs
[]
vcl
.
Address
,
secrPtr
*
[]
byte
,
loadVCL
bool
)
error
{
var
errs
Varnish
AdmErrors
var
errs
AdmErrors
var
newInsts
,
remInsts
,
keepInsts
[]
*
varnishInst
svc
,
exists
:=
vc
.
svcs
[
key
]
...
...
@@ -467,7 +467,7 @@ func (vc *VarnishController) updateVarnishSvcAddrs(key string,
if
err
:=
vc
.
setCfgLabel
(
inst
,
notAvailCfg
,
readinessLabel
,
true
);
err
!=
nil
{
admErr
:=
Varnish
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
admErr
:=
AdmError
{
addr
:
inst
.
addr
,
err
:
err
}
errs
=
append
(
errs
,
admErr
)
continue
}
...
...
@@ -479,7 +479,7 @@ func (vc *VarnishController) updateVarnishSvcAddrs(key string,
vc
.
log
.
Tracef
(
"Varnish svc %s: load VCL"
,
key
)
updateErrs
:=
vc
.
updateVarnishSvc
(
key
)
if
updateErrs
!=
nil
{
vadmErrs
,
ok
:=
updateErrs
.
(
Varnish
AdmErrors
)
vadmErrs
,
ok
:=
updateErrs
.
(
AdmErrors
)
if
ok
{
errs
=
append
(
errs
,
vadmErrs
...
)
}
else
{
...
...
@@ -625,12 +625,12 @@ func (vc *VarnishController) SetNotReady(svcKey string) error {
}
svc
.
spec
=
nil
var
errs
Varnish
AdmErrors
var
errs
AdmErrors
for
_
,
inst
:=
range
svc
.
instances
{
if
err
:=
vc
.
setCfgLabel
(
inst
,
notAvailCfg
,
readinessLabel
,
false
);
err
!=
nil
{
admErr
:=
Varnish
AdmError
{
admErr
:=
AdmError
{
addr
:
inst
.
addr
,
err
:
err
,
}
...
...
pkg/varnish/varnish_test.go
View file @
46bab65a
...
...
@@ -36,24 +36,24 @@ import (
"code.uplex.de/uplex-varnish/k8s-ingress/pkg/varnish/vcl"
)
func
Test
Varnish
AdmError
(
t
*
testing
.
T
)
{
vadmErr
:=
Varnish
AdmError
{
func
TestAdmError
(
t
*
testing
.
T
)
{
vadmErr
:=
AdmError
{
addr
:
"123.45.67.89:4711"
,
err
:
fmt
.
Errorf
(
"Error message"
),
}
err
:=
vadmErr
.
Error
()
want
:=
"123.45.67.89:4711: Error message"
if
err
!=
want
{
t
.
Errorf
(
"
Varnish
AdmError.Error() want=%s got=%s"
,
want
,
err
)
t
.
Errorf
(
"AdmError.Error() want=%s got=%s"
,
want
,
err
)
}
vadmErrs
:=
Varnish
AdmErrors
{
vadmErrs
:=
AdmErrors
{
vadmErr
,
Varnish
AdmError
{
AdmError
{
addr
:
"98.76.54.321:815"
,
err
:
fmt
.
Errorf
(
"Error 2"
),
},
Varnish
AdmError
{
AdmError
{
addr
:
"192.0.2.255:80"
,
err
:
fmt
.
Errorf
(
"Error 3"
),
},
...
...
@@ -62,7 +62,7 @@ func TestVarnishAdmError(t *testing.T) {
want
=
"[{123.45.67.89:4711: Error message}{98.76.54.321:815: Error 2}"
+
"{192.0.2.255:80: Error 3}]"
if
err
!=
want
{
t
.
Errorf
(
"
Varnish
AdmErrors.Error() want=%s got=%s"
,
want
,
err
)
t
.
Errorf
(
"AdmErrors.Error() want=%s got=%s"
,
want
,
err
)
}
}
...
...
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