Commit 28a583d0 authored by Geoff Simmons's avatar Geoff Simmons

Rename varnish.VarnishController as varnish.Controller.

Silences a golint "stutter" warning.
parent 46bab65a
...@@ -211,7 +211,7 @@ func main() { ...@@ -211,7 +211,7 @@ func main() {
func handleTermination( func handleTermination(
log *logrus.Logger, log *logrus.Logger,
ingc *controller.IngressController, ingc *controller.IngressController,
vc *varnish.VarnishController) { vc *varnish.Controller) {
signalChan := make(chan os.Signal, 1) signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT) signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT)
......
...@@ -100,11 +100,11 @@ type Listers struct { ...@@ -100,11 +100,11 @@ type Listers struct {
} }
// IngressController watches Kubernetes API and reconfigures Varnish // IngressController watches Kubernetes API and reconfigures Varnish
// via VarnishController when needed. // via varnish.Controller when needed.
type IngressController struct { type IngressController struct {
log *logrus.Logger log *logrus.Logger
client kubernetes.Interface client kubernetes.Interface
vController *varnish.VarnishController vController *varnish.Controller
informers *infrmrs informers *infrmrs
listers *Listers listers *Listers
nsQs *NamespaceQueues nsQs *NamespaceQueues
...@@ -125,7 +125,7 @@ func NewIngressController( ...@@ -125,7 +125,7 @@ func NewIngressController(
log *logrus.Logger, log *logrus.Logger,
ingClass string, ingClass string,
kubeClient kubernetes.Interface, kubeClient kubernetes.Interface,
vc *varnish.VarnishController, vc *varnish.Controller,
infFactory informers.SharedInformerFactory, infFactory informers.SharedInformerFactory,
vcrInfFactory vcr_informers.SharedInformerFactory, vcrInfFactory vcr_informers.SharedInformerFactory,
) (*IngressController, error) { ) (*IngressController, error) {
......
...@@ -66,7 +66,7 @@ type NamespaceWorker struct { ...@@ -66,7 +66,7 @@ type NamespaceWorker struct {
namespace string namespace string
ingClass string ingClass string
log *logrus.Logger log *logrus.Logger
vController *varnish.VarnishController vController *varnish.Controller
queue workqueue.RateLimitingInterface queue workqueue.RateLimitingInterface
listers *Listers listers *Listers
ing ext_listers.IngressNamespaceLister ing ext_listers.IngressNamespaceLister
...@@ -270,7 +270,7 @@ type NamespaceQueues struct { ...@@ -270,7 +270,7 @@ type NamespaceQueues struct {
DoneChan chan struct{} DoneChan chan struct{}
ingClass string ingClass string
log *logrus.Logger log *logrus.Logger
vController *varnish.VarnishController vController *varnish.Controller
workers map[string]*NamespaceWorker workers map[string]*NamespaceWorker
listers *Listers listers *Listers
client kubernetes.Interface client kubernetes.Interface
...@@ -289,7 +289,7 @@ type NamespaceQueues struct { ...@@ -289,7 +289,7 @@ type NamespaceQueues struct {
func NewNamespaceQueues( func NewNamespaceQueues(
log *logrus.Logger, log *logrus.Logger,
ingClass string, ingClass string,
vController *varnish.VarnishController, vController *varnish.Controller,
listers *Listers, listers *Listers,
client kubernetes.Interface, client kubernetes.Interface,
recorder record.EventRecorder) *NamespaceQueues { recorder record.EventRecorder) *NamespaceQueues {
......
...@@ -50,31 +50,25 @@ const ( ...@@ -50,31 +50,25 @@ const (
monitorGood = "MonitorGood" monitorGood = "MonitorGood"
) )
func (vc *VarnishController) infoEvt(svc, reason, msgFmt string, func (vc *Controller) infoEvt(svc, reason, msgFmt string, args ...interface{}) {
args ...interface{}) {
vc.log.Infof(msgFmt, args...) vc.log.Infof(msgFmt, args...)
vc.svcEvt.SvcInfoEvent(svc, reason, msgFmt, args...) vc.svcEvt.SvcInfoEvent(svc, reason, msgFmt, args...)
monResultCtr.WithLabelValues(svc, "info", reason).Inc() monResultCtr.WithLabelValues(svc, "info", reason).Inc()
} }
func (vc *VarnishController) warnEvt(svc, reason, msgFmt string, func (vc *Controller) warnEvt(svc, reason, msgFmt string, args ...interface{}) {
args ...interface{}) {
vc.log.Warnf(msgFmt, args...) vc.log.Warnf(msgFmt, args...)
vc.svcEvt.SvcWarnEvent(svc, reason, msgFmt, args...) vc.svcEvt.SvcWarnEvent(svc, reason, msgFmt, args...)
monResultCtr.WithLabelValues(svc, "warning", reason).Inc() monResultCtr.WithLabelValues(svc, "warning", reason).Inc()
} }
func (vc *VarnishController) errorEvt(svc, reason, msgFmt string, func (vc *Controller) errorEvt(svc, reason, msgFmt string, args ...interface{}) {
args ...interface{}) {
vc.log.Errorf(msgFmt, args...) vc.log.Errorf(msgFmt, args...)
vc.svcEvt.SvcWarnEvent(svc, reason, msgFmt, args...) vc.svcEvt.SvcWarnEvent(svc, reason, msgFmt, args...)
monResultCtr.WithLabelValues(svc, "error", reason).Inc() monResultCtr.WithLabelValues(svc, "error", reason).Inc()
} }
func (vc *VarnishController) checkInst(svc string, inst *varnishInst) bool { func (vc *Controller) checkInst(svc string, inst *varnishInst) bool {
metrics := getInstanceMetrics(inst.addr) metrics := getInstanceMetrics(inst.addr)
metrics.monitorChecks.Inc() metrics.monitorChecks.Inc()
...@@ -167,7 +161,7 @@ func (vc *VarnishController) checkInst(svc string, inst *varnishInst) bool { ...@@ -167,7 +161,7 @@ func (vc *VarnishController) checkInst(svc string, inst *varnishInst) bool {
return true return true
} }
func (vc *VarnishController) monitor(monitorIntvl time.Duration) { func (vc *Controller) monitor(monitorIntvl time.Duration) {
if monitorIntvl <= 0 { if monitorIntvl <= 0 {
vc.log.Infof("Varnish monitor interval=%v, monitor not running", vc.log.Infof("Varnish monitor interval=%v, monitor not running",
monitorIntvl) monitorIntvl)
......
...@@ -143,10 +143,10 @@ type varnishSvc struct { ...@@ -143,10 +143,10 @@ type varnishSvc struct {
cfgLoaded bool cfgLoaded bool
} }
// VarnishController encapsulates information about each Varnish // Controller encapsulates information about each Varnish
// cluster deployed as Ingress implementations in the cluster, and // cluster deployed as Ingress implementations in the cluster, and
// their current states. // their current states.
type VarnishController struct { type Controller struct {
log *logrus.Logger log *logrus.Logger
svcEvt interfaces.SvcEventGenerator svcEvt interfaces.SvcEventGenerator
svcs map[string]*varnishSvc svcs map[string]*varnishSvc
...@@ -155,7 +155,7 @@ type VarnishController struct { ...@@ -155,7 +155,7 @@ type VarnishController struct {
monIntvl time.Duration monIntvl time.Duration
} }
// NewVarnishController returns an instance of VarnishController. // NewVarnishController returns an instance of Controller.
// //
// log: logger object initialized at startup // log: logger object initialized at startup
// tmplDir: directory containing templates for VCL generation // tmplDir: directory containing templates for VCL generation
...@@ -163,10 +163,8 @@ type VarnishController struct { ...@@ -163,10 +163,8 @@ type VarnishController struct {
// If tmplDir is the empty string, use the environment variable // If tmplDir is the empty string, use the environment variable
// TEMPLATE_DIR. If the env variable does not exist, use the current // TEMPLATE_DIR. If the env variable does not exist, use the current
// working directory. // working directory.
func NewVarnishController( func NewVarnishController(log *logrus.Logger, tmplDir string,
log *logrus.Logger, monIntvl time.Duration) (*Controller, error) {
tmplDir string,
monIntvl time.Duration) (*VarnishController, error) {
if tmplDir == "" { if tmplDir == "" {
tmplEnv, exists := os.LookupEnv("TEMPLATE_DIR") tmplEnv, exists := os.LookupEnv("TEMPLATE_DIR")
...@@ -178,7 +176,7 @@ func NewVarnishController( ...@@ -178,7 +176,7 @@ func NewVarnishController(
return nil, err return nil, err
} }
initMetrics() initMetrics()
return &VarnishController{ return &Controller{
svcs: make(map[string]*varnishSvc), svcs: make(map[string]*varnishSvc),
secrets: make(map[string]*[]byte), secrets: make(map[string]*[]byte),
log: log, log: log,
...@@ -190,19 +188,19 @@ func NewVarnishController( ...@@ -190,19 +188,19 @@ func NewVarnishController(
// EvtGenerator sets the object that implements interface // EvtGenerator sets the object that implements interface
// SvcEventGenerator, and will be used by the monitor goroutine to // SvcEventGenerator, and will be used by the monitor goroutine to
// generate Events for Varnish Services. // generate Events for Varnish Services.
func (vc *VarnishController) EvtGenerator(svcEvt interfaces.SvcEventGenerator) { func (vc *Controller) EvtGenerator(svcEvt interfaces.SvcEventGenerator) {
vc.svcEvt = svcEvt vc.svcEvt = svcEvt
} }
// Start initiates the Varnish controller and starts the monitor // Start initiates the Varnish controller and starts the monitor
// goroutine. // goroutine.
func (vc *VarnishController) Start() { func (vc *Controller) Start() {
fmt.Printf("Varnish controller logging at level: %s\n", vc.log.Level) fmt.Printf("Varnish controller logging at level: %s\n", vc.log.Level)
go vc.monitor(vc.monIntvl) go vc.monitor(vc.monIntvl)
} }
func (vc *VarnishController) updateVarnishInstance(inst *varnishInst, func (vc *Controller) updateVarnishInstance(inst *varnishInst, cfgName string,
cfgName string, vclSrc string, metrics *instanceMetrics) error { vclSrc string, metrics *instanceMetrics) error {
vc.log.Infof("Update Varnish instance at %s", inst.addr) vc.log.Infof("Update Varnish instance at %s", inst.addr)
vc.log.Tracef("Varnish instance %s: %+v", inst.addr, *inst) vc.log.Tracef("Varnish instance %s: %+v", inst.addr, *inst)
...@@ -296,7 +294,7 @@ func (vc *VarnishController) updateVarnishInstance(inst *varnishInst, ...@@ -296,7 +294,7 @@ func (vc *VarnishController) updateVarnishInstance(inst *varnishInst,
return nil return nil
} }
func (vc *VarnishController) updateVarnishSvc(name string) error { func (vc *Controller) updateVarnishSvc(name string) error {
svc, exists := vc.svcs[name] svc, exists := vc.svcs[name]
if !exists || svc == nil { if !exists || svc == nil {
return fmt.Errorf("No known Varnish Service %s", name) return fmt.Errorf("No known Varnish Service %s", name)
...@@ -348,8 +346,8 @@ func (vc *VarnishController) updateVarnishSvc(name string) error { ...@@ -348,8 +346,8 @@ func (vc *VarnishController) updateVarnishSvc(name string) error {
// Label cfg as lbl at Varnish instance inst. If mayClose is true, then // Label cfg as lbl at Varnish instance inst. If mayClose is true, then
// losing the admin connection is not an error (Varnish may be // losing the admin connection is not an error (Varnish may be
// shutting down). // shutting down).
func (vc *VarnishController) setCfgLabel(inst *varnishInst, func (vc *Controller) setCfgLabel(inst *varnishInst, cfg, lbl string,
cfg, lbl string, mayClose bool) error { mayClose bool) error {
if inst.admSecret == nil { if inst.admSecret == nil {
return AdmError{ return AdmError{
...@@ -395,7 +393,7 @@ func (vc *VarnishController) setCfgLabel(inst *varnishInst, ...@@ -395,7 +393,7 @@ 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 *Controller) removeVarnishInstances(insts []*varnishInst) error {
var errs AdmErrors var errs AdmErrors
for _, inst := range insts { for _, inst := range insts {
...@@ -415,8 +413,8 @@ func (vc *VarnishController) removeVarnishInstances(insts []*varnishInst) error ...@@ -415,8 +413,8 @@ func (vc *VarnishController) removeVarnishInstances(insts []*varnishInst) error
return errs return errs
} }
func (vc *VarnishController) updateVarnishSvcAddrs(key string, func (vc *Controller) updateVarnishSvcAddrs(key string, addrs []vcl.Address,
addrs []vcl.Address, secrPtr *[]byte, loadVCL bool) error { secrPtr *[]byte, loadVCL bool) error {
var errs AdmErrors var errs AdmErrors
var newInsts, remInsts, keepInsts []*varnishInst var newInsts, remInsts, keepInsts []*varnishInst
...@@ -502,8 +500,8 @@ func (vc *VarnishController) updateVarnishSvcAddrs(key string, ...@@ -502,8 +500,8 @@ func (vc *VarnishController) updateVarnishSvcAddrs(key string,
// Service // Service
// loadVCL: true if the VCL config for the Service should be // loadVCL: true if the VCL config for the Service should be
// reloaded // reloaded
func (vc *VarnishController) AddOrUpdateVarnishSvc(key string, func (vc *Controller) AddOrUpdateVarnishSvc(key string, addrs []vcl.Address,
addrs []vcl.Address, secrName string, loadVCL bool) error { secrName string, loadVCL bool) error {
var secrPtr *[]byte var secrPtr *[]byte
svc, svcExists := vc.svcs[key] svc, svcExists := vc.svcs[key]
...@@ -549,7 +547,7 @@ func (vc *VarnishController) AddOrUpdateVarnishSvc(key string, ...@@ -549,7 +547,7 @@ func (vc *VarnishController) AddOrUpdateVarnishSvc(key string,
// Service identified by the namespace/name key. The Varnish instance // Service identified by the namespace/name key. The Varnish instance
// is set to the unready state, and no further action is taken (other // is set to the unready state, and no further action is taken (other
// resources in the cluster may shut down the Varnish instances). // resources in the cluster may shut down the Varnish instances).
func (vc *VarnishController) DeleteVarnishSvc(key string) error { func (vc *Controller) DeleteVarnishSvc(key string) error {
svc, ok := vc.svcs[key] svc, ok := vc.svcs[key]
if !ok { if !ok {
return nil return nil
...@@ -562,7 +560,7 @@ func (vc *VarnishController) DeleteVarnishSvc(key string) error { ...@@ -562,7 +560,7 @@ func (vc *VarnishController) DeleteVarnishSvc(key string) error {
return err return err
} }
func (vc *VarnishController) updateBeGauges() { func (vc *Controller) updateBeGauges() {
nBeSvcs := 0 nBeSvcs := 0
nBeEndps := 0 nBeEndps := 0
for _, svc := range vc.svcs { for _, svc := range vc.svcs {
...@@ -585,7 +583,7 @@ func (vc *VarnishController) updateBeGauges() { ...@@ -585,7 +583,7 @@ func (vc *VarnishController) updateBeGauges() {
// ingsMeta: Ingress meta-data // ingsMeta: Ingress meta-data
// vcfgMeta: VarnishConfig meta-data // vcfgMeta: VarnishConfig meta-data
// bcfgMeta: BackendConfig meta-data // bcfgMeta: BackendConfig meta-data
func (vc *VarnishController) Update(svcKey string, spec vcl.Spec, func (vc *Controller) Update(svcKey string, spec vcl.Spec,
ingsMeta map[string]Meta, vcfgMeta Meta, ingsMeta map[string]Meta, vcfgMeta Meta,
bcfgMeta map[string]Meta) error { bcfgMeta map[string]Meta) error {
...@@ -617,7 +615,7 @@ func (vc *VarnishController) Update(svcKey string, spec vcl.Spec, ...@@ -617,7 +615,7 @@ func (vc *VarnishController) Update(svcKey string, spec vcl.Spec,
// Ingresses remain that are to be implemented by a Varnish Service. // Ingresses remain that are to be implemented by a Varnish Service.
// The Service is set to the not ready state, by relabelling VCL so // The Service is set to the not ready state, by relabelling VCL so
// that readiness checks are not answered with status 200. // that readiness checks are not answered with status 200.
func (vc *VarnishController) SetNotReady(svcKey string) error { func (vc *Controller) SetNotReady(svcKey string) error {
svc, ok := vc.svcs[svcKey] svc, ok := vc.svcs[svcKey]
if !ok { if !ok {
return fmt.Errorf("Set Varnish Service not ready: %s unknown", return fmt.Errorf("Set Varnish Service not ready: %s unknown",
...@@ -652,7 +650,7 @@ func (vc *VarnishController) SetNotReady(svcKey string) error { ...@@ -652,7 +650,7 @@ func (vc *VarnishController) SetNotReady(svcKey string) error {
// ingsMeta: Ingress meta-data // ingsMeta: Ingress meta-data
// vcfgMeta: VarnishConfig meta-data // vcfgMeta: VarnishConfig meta-data
// bcfgMeta: BackendConfig meta-data // bcfgMeta: BackendConfig meta-data
func (vc *VarnishController) HasConfig(svcKey string, spec vcl.Spec, func (vc *Controller) HasConfig(svcKey string, spec vcl.Spec,
ingsMeta map[string]Meta, vcfgMeta Meta, ingsMeta map[string]Meta, vcfgMeta Meta,
bcfgMeta map[string]Meta) bool { bcfgMeta map[string]Meta) bool {
...@@ -699,7 +697,7 @@ func (vc *VarnishController) HasConfig(svcKey string, spec vcl.Spec, ...@@ -699,7 +697,7 @@ func (vc *VarnishController) HasConfig(svcKey string, spec vcl.Spec,
// SetAdmSecret stores the Secret data identified by the // SetAdmSecret stores the Secret data identified by the
// namespace/name key. // namespace/name key.
func (vc *VarnishController) SetAdmSecret(key string, secret []byte) { func (vc *Controller) SetAdmSecret(key string, secret []byte) {
secr, exists := vc.secrets[key] secr, exists := vc.secrets[key]
if !exists { if !exists {
secretSlice := make([]byte, len(secret)) secretSlice := make([]byte, len(secret))
...@@ -713,7 +711,7 @@ func (vc *VarnishController) SetAdmSecret(key string, secret []byte) { ...@@ -713,7 +711,7 @@ func (vc *VarnishController) SetAdmSecret(key string, secret []byte) {
// UpdateSvcForSecret associates the Secret identified by the // UpdateSvcForSecret associates the Secret identified by the
// namespace/name secretKey with the Varnish Service identified by the // namespace/name secretKey with the Varnish Service identified by the
// namespace/name svcKey. The Service is newly synced if necessary. // namespace/name svcKey. The Service is newly synced if necessary.
func (vc *VarnishController) UpdateSvcForSecret(svcKey, secretKey string) error { func (vc *Controller) UpdateSvcForSecret(svcKey, secretKey string) error {
secret, exists := vc.secrets[secretKey] secret, exists := vc.secrets[secretKey]
if !exists { if !exists {
secretKey = "" secretKey = ""
...@@ -746,7 +744,7 @@ func (vc *VarnishController) UpdateSvcForSecret(svcKey, secretKey string) error ...@@ -746,7 +744,7 @@ func (vc *VarnishController) UpdateSvcForSecret(svcKey, secretKey string) error
// DeleteAdmSecret removes the secret identified by the namespace/name // DeleteAdmSecret removes the secret identified by the namespace/name
// key. // key.
func (vc *VarnishController) DeleteAdmSecret(name string) { func (vc *Controller) DeleteAdmSecret(name string) {
_, exists := vc.secrets[name] _, exists := vc.secrets[name]
if exists { if exists {
delete(vc.secrets, name) delete(vc.secrets, name)
...@@ -755,7 +753,7 @@ func (vc *VarnishController) DeleteAdmSecret(name string) { ...@@ -755,7 +753,7 @@ func (vc *VarnishController) DeleteAdmSecret(name string) {
} }
// Quit stops the Varnish controller. // Quit stops the Varnish controller.
func (vc *VarnishController) Quit() { func (vc *Controller) Quit() {
vc.log.Info("Wait for admin interactions with Varnish instances to " + vc.log.Info("Wait for admin interactions with Varnish instances to " +
"finish") "finish")
vc.wg.Wait() vc.wg.Wait()
......
...@@ -210,7 +210,7 @@ func TestHasConfig(t *testing.T) { ...@@ -210,7 +210,7 @@ func TestHasConfig(t *testing.T) {
spec: &spec, spec: &spec,
cfgLoaded: true, cfgLoaded: true,
} }
vc := VarnishController{ vc := Controller{
svcs: map[string]*varnishSvc{"default/cafe-ingress": &vSvc}, svcs: map[string]*varnishSvc{"default/cafe-ingress": &vSvc},
} }
svcKey := "default/cafe-ingress" svcKey := "default/cafe-ingress"
......
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