From 14cf0d495fbfc6061bf39f5c89f8423a657fec4d Mon Sep 17 00:00:00 2001 From: James Munnelly Date: Mon, 16 Oct 2017 14:50:27 +0100 Subject: [PATCH] Consistent use of glog --- pkg/controller/certificates/controller.go | 15 ++++++--------- pkg/controller/clusterissuers/controller.go | 18 +++++++----------- pkg/controller/issuers/controller.go | 16 ++++++---------- pkg/issuer/acme/dns/dns.go | 11 ++++++----- pkg/issuer/acme/dns/util/wait.go | 6 +++--- pkg/issuer/acme/http/http.go | 6 +++--- 6 files changed, 31 insertions(+), 41 deletions(-) diff --git a/pkg/controller/certificates/controller.go b/pkg/controller/certificates/controller.go index b031629ae..1f7b2471c 100644 --- a/pkg/controller/certificates/controller.go +++ b/pkg/controller/certificates/controller.go @@ -178,43 +178,40 @@ func (c *Controller) Run(workers int, stopCh <-chan struct{}) error { func (c *Controller) worker(stopCh <-chan struct{}) { defer c.workerWg.Done() - glog.V(4).Infof("Starting %s worker", ControllerName) + glog.V(4).Infof("Starting %q worker", ControllerName) for { obj, shutdown := c.queue.Get() if shutdown { break } + var key string err := func(obj interface{}) error { defer c.queue.Done(obj) - var key string var ok bool if key, ok = obj.(string); !ok { - runtime.HandleError(fmt.Errorf("expected string in workqueue but got %T", obj)) return nil } ctx, cancel := context.WithCancel(context.Background()) defer cancel() ctx = util.ContextWithStopCh(ctx, stopCh) - glog.V(6).Infof("%s controller: syncing item '%s'", ControllerName, key) + glog.Infof("%s controller: syncing item '%s'", ControllerName, key) if err := c.syncHandler(ctx, key); err != nil { - glog.V(4).Infof("%s controller: error syncing item '%s': %s", ControllerName, key, err.Error()) return err } - glog.V(4).Infof("%s controller: synced item '%s'", ControllerName, key) c.queue.Forget(obj) return nil }(obj) if err != nil { - glog.V(2).Infof("Requeuing object due to error processing: %s", err.Error()) + glog.Errorf("%s controller: Re-queuing item %q due to error processing: %s", ControllerName, key, err.Error()) c.queue.AddRateLimited(obj) continue } - glog.V(4).Infof("Finished processing work item") + glog.Infof("%s controller: Finished processing work item %q", ControllerName, key) } - glog.V(4).Infof("Exiting %s worker loop", ControllerName) + glog.V(4).Infof("Exiting %q worker loop", ControllerName) } func (c *Controller) processNextWorkItem(ctx context.Context, key string) error { diff --git a/pkg/controller/clusterissuers/controller.go b/pkg/controller/clusterissuers/controller.go index b463a7956..8f06bbf78 100644 --- a/pkg/controller/clusterissuers/controller.go +++ b/pkg/controller/clusterissuers/controller.go @@ -3,7 +3,6 @@ package issuers import ( "context" "fmt" - "log" "sync" "time" @@ -121,43 +120,40 @@ func (c *Controller) Run(workers int, stopCh <-chan struct{}) error { func (c *Controller) worker(stopCh <-chan struct{}) { defer c.workerWg.Done() - log.Printf("starting worker") + glog.V(4).Infof("Starting %q worker", ControllerName) for { obj, shutdown := c.queue.Get() if shutdown { break } + var key string err := func(obj interface{}) error { defer c.queue.Done(obj) - var key string var ok bool if key, ok = obj.(string); !ok { - runtime.HandleError(fmt.Errorf("expected string in workqueue but got %T", obj)) return nil } ctx, cancel := context.WithCancel(context.Background()) defer cancel() ctx = util.ContextWithStopCh(ctx, stopCh) - glog.V(6).Infof("%s controller: syncing item '%s'", ControllerName, key) + glog.Infof("%s controller: syncing item '%s'", ControllerName, key) if err := c.syncHandler(ctx, key); err != nil { - glog.V(4).Infof("%s controller: error syncing item '%s': %s", ControllerName, key, err.Error()) return err } - glog.V(4).Infof("%s controller: synced item '%s'", ControllerName, key) c.queue.Forget(obj) return nil }(obj) if err != nil { - log.Printf("requeuing item due to error processing: %s", err.Error()) + glog.Errorf("%s controller: Re-queuing item %q due to error processing: %s", ControllerName, key, err.Error()) c.queue.AddRateLimited(obj) continue } - log.Printf("finished processing work item") + glog.Infof("%s controller: Finished processing work item %q", ControllerName, key) } - log.Printf("exiting worker loop") + glog.V(4).Infof("Exiting %q worker loop", ControllerName) } func (c *Controller) processNextWorkItem(ctx context.Context, key string) error { @@ -171,7 +167,7 @@ func (c *Controller) processNextWorkItem(ctx context.Context, key string) error if err != nil { if k8sErrors.IsNotFound(err) { - runtime.HandleError(fmt.Errorf("issuer '%s' in work queue no longer exists", key)) + runtime.HandleError(fmt.Errorf("issuer %q in work queue no longer exists", key)) return nil } diff --git a/pkg/controller/issuers/controller.go b/pkg/controller/issuers/controller.go index cda454ab2..7d70f4641 100644 --- a/pkg/controller/issuers/controller.go +++ b/pkg/controller/issuers/controller.go @@ -3,7 +3,6 @@ package issuers import ( "context" "fmt" - "log" "sync" "time" @@ -119,43 +118,40 @@ func (c *Controller) Run(workers int, stopCh <-chan struct{}) error { func (c *Controller) worker(stopCh <-chan struct{}) { defer c.workerWg.Done() - log.Printf("starting worker") + glog.V(4).Infof("Starting %q worker", ControllerName) for { obj, shutdown := c.queue.Get() if shutdown { break } + var key string err := func(obj interface{}) error { defer c.queue.Done(obj) - var key string var ok bool if key, ok = obj.(string); !ok { - runtime.HandleError(fmt.Errorf("expected string in workqueue but got %T", obj)) return nil } ctx, cancel := context.WithCancel(context.Background()) defer cancel() ctx = util.ContextWithStopCh(ctx, stopCh) - glog.V(6).Infof("%s controller: syncing item '%s'", ControllerName, key) + glog.Infof("%s controller: syncing item '%s'", ControllerName, key) if err := c.syncHandler(ctx, key); err != nil { - glog.V(4).Infof("%s controller: error syncing item '%s': %s", ControllerName, key, err.Error()) return err } - glog.V(4).Infof("%s controller: synced item '%s'", ControllerName, key) c.queue.Forget(obj) return nil }(obj) if err != nil { - log.Printf("requeuing item due to error processing: %s", err.Error()) + glog.Errorf("%s controller: Re-queuing item %q due to error processing: %s", ControllerName, key, err.Error()) c.queue.AddRateLimited(obj) continue } - log.Printf("finished processing work item") + glog.Infof("%s controller: Finished processing work item %q", ControllerName, key) } - log.Printf("exiting worker loop") + glog.V(4).Infof("Exiting %q worker loop", ControllerName) } func (c *Controller) processNextWorkItem(ctx context.Context, key string) error { diff --git a/pkg/issuer/acme/dns/dns.go b/pkg/issuer/acme/dns/dns.go index 69bf8452a..8f7854ed8 100644 --- a/pkg/issuer/acme/dns/dns.go +++ b/pkg/issuer/acme/dns/dns.go @@ -3,9 +3,9 @@ package dns import ( "context" "fmt" - "log" "time" + "github.com/golang/glog" "k8s.io/client-go/kubernetes" corev1listers "k8s.io/client-go/listers/core/v1" @@ -38,7 +38,7 @@ func (s *Solver) Present(ctx context.Context, crt *v1alpha1.Certificate, domain, if err != nil { return err } - log.Printf("presenting key: %s", key) + glog.V(4).Infof("Presenting DNS01 challenge for domain %q", domain) return slv.Present(domain, token, key) } @@ -55,7 +55,7 @@ func (s *Solver) Wait(ctx context.Context, crt *v1alpha1.Certificate, domain, to fqdn, value, ttl := util.DNS01Record(domain, key) - log.Printf("[%s] Checking DNS record propagation using %+v", domain, util.RecursiveNameservers) + glog.V(4).Infof("Checking DNS propagation for %q using name servers: %v", domain, util.RecursiveNameservers) timeout, interval := slv.Timeout() ctx, cancel := context.WithTimeout(ctx, timeout) @@ -74,11 +74,12 @@ func (s *Solver) Wait(ctx context.Context, crt *v1alpha1.Certificate, domain, to if r.bool { // TODO: move this to somewhere else // TODO: make this wait for whatever the record *was*, not is now - log.Printf("sleeping for dns record for '%s' ttl %ds before returning from Wait", fqdn, ttl) + glog.V(4).Infof("Waiting DNS record TTL (%ds) to allow propagation for propagation of DNS record for domain %q", ttl, fqdn) time.Sleep(time.Second * time.Duration(ttl)) + glog.V(4).Infof("ACME DNS01 validation record propagated for %q", fqdn) return nil } - log.Printf("[%s] dns record not yet propegated", domain) + glog.V(4).Infof("DNS record for %q not yet propagated", domain) time.Sleep(interval) case <-ctx.Done(): return ctx.Err() diff --git a/pkg/issuer/acme/dns/util/wait.go b/pkg/issuer/acme/dns/util/wait.go index c2c4a8c4e..8272c11ad 100644 --- a/pkg/issuer/acme/dns/util/wait.go +++ b/pkg/issuer/acme/dns/util/wait.go @@ -2,11 +2,11 @@ package util import ( "fmt" - "log" "net" "strings" "time" + "github.com/golang/glog" "github.com/miekg/dns" "golang.org/x/net/publicsuffix" ) @@ -90,7 +90,7 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro return false, fmt.Errorf("NS %s returned %s for %s", ns, dns.RcodeToString[r.Rcode], fqdn) } - log.Printf("looking up txt record for fqdn '%s'", fqdn) + glog.V(6).Infof("Looking up TXT records for %q", fqdn) var found bool for _, rr := range r.Answer { if txt, ok := rr.(*dns.TXT); ok { @@ -102,7 +102,7 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro } if !found { - return false, fmt.Errorf("NS %s did not return the expected TXT record", ns) + return false, fmt.Errorf("nameserver %q did not return the expected TXT record for domain %q", ns, fqdn) } } diff --git a/pkg/issuer/acme/http/http.go b/pkg/issuer/acme/http/http.go index 4ce21e533..ffbd92f34 100644 --- a/pkg/issuer/acme/http/http.go +++ b/pkg/issuer/acme/http/http.go @@ -5,12 +5,12 @@ import ( "errors" "fmt" "io/ioutil" - "log" "net/http" "net/url" "strings" "time" + "github.com/golang/glog" corev1 "k8s.io/api/core/v1" extv1beta1 "k8s.io/api/extensions/v1beta1" k8sErrors "k8s.io/apimachinery/pkg/api/errors" @@ -409,11 +409,11 @@ func (s *Solver) Wait(ctx context.Context, crt *v1alpha1.Certificate, domain, to return out }(): if err != nil { - log.Printf("[%s] Error self checking HTTP01 challenge: %s", domain, err.Error()) + glog.V(4).Infof("ACME HTTP01 self check failed for domain %q, waiting 5s: %v", domain, err) time.Sleep(time.Second * 5) continue } - log.Printf("[%s] HTTP01 challenge self checking passed", domain) + glog.V(4).Infof("ACME HTTP01 self check for %q passed", domain) return nil case <-ctx.Done(): return ctx.Err()