Commit 46bab65a authored by Geoff Simmons's avatar Geoff Simmons

Rename varnish.VarnishAdmError[s] as AdmError[s].

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