Fix formatted logs

Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
This commit is contained in:
Maartje Eyskens 2020-08-04 12:51:16 +02:00
parent 86dee5ed41
commit 5d4869b20e
12 changed files with 41 additions and 37 deletions

View File

@ -89,7 +89,7 @@ servers and webhook servers.`,
defer cancel()
o.log = logf.FromContext(ctx).WithValues("ca-injector")
o.log.V(logf.InfoLevel).Info("starting ca-injector %s (revision %s)", util.AppVersion, util.AppGitCommit)
logf.V(logf.InfoLevel).Infof("starting ca-injector %s (revision %s)", util.AppVersion, util.AppGitCommit)
o.RunInjectorController(stopCh)
},
}

View File

@ -202,7 +202,7 @@ func asVersionedObject(infos []*resource.Info, forceList bool, specifiedOutputVe
if len(actualVersion.Version) > 0 {
defaultVersionInfo = fmt.Sprintf("Defaulting to %q", actualVersion.Version)
}
logf.Log.V(logf.WarnLevel).Info("info: the output version specified is invalid. %s\n", defaultVersionInfo)
logf.V(logf.WarnLevel).Infof("info: the output version specified is invalid. %s\n", defaultVersionInfo)
}
return object, nil

View File

@ -78,7 +78,7 @@ func SetIssuerCondition(i cmapi.GenericIssuer, conditionType cmapi.IssuerConditi
if cond.Status == status {
newCondition.LastTransitionTime = cond.LastTransitionTime
} else {
logf.Log.V(logf.InfoLevel).Info("Found status change for Issuer %q condition %q: %q -> %q; setting lastTransitionTime to %v", i.GetObjectMeta().Name, conditionType, cond.Status, status, nowTime.Time)
logf.V(logf.InfoLevel).Infof("Found status change for Issuer %q condition %q: %q -> %q; setting lastTransitionTime to %v", i.GetObjectMeta().Name, conditionType, cond.Status, status, nowTime.Time)
}
// Overwrite the existing condition
@ -89,7 +89,7 @@ func SetIssuerCondition(i cmapi.GenericIssuer, conditionType cmapi.IssuerConditi
// If we've not found an existing condition of this type, we simply insert
// the new condition into the slice.
i.GetStatus().Conditions = append(i.GetStatus().Conditions, newCondition)
logf.Log.V(logf.InfoLevel).Info("Setting lastTransitionTime for Issuer %q condition %q to %v", i.GetObjectMeta().Name, conditionType, nowTime.Time)
logf.V(logf.InfoLevel).Infof("Setting lastTransitionTime for Issuer %q condition %q to %v", i.GetObjectMeta().Name, conditionType, nowTime.Time)
}
// CertificateHasCondition will return true if the given Certificate has a
@ -159,7 +159,7 @@ func SetCertificateCondition(crt *cmapi.Certificate, conditionType cmapi.Certifi
if cond.Status == status {
newCondition.LastTransitionTime = cond.LastTransitionTime
} else {
logf.Log.V(logf.InfoLevel).Info("Found status change for Certificate %q condition %q: %q -> %q; setting lastTransitionTime to %v", crt.Name, conditionType, cond.Status, status, nowTime.Time)
logf.V(logf.InfoLevel).Infof("Found status change for Certificate %q condition %q: %q -> %q; setting lastTransitionTime to %v", crt.Name, conditionType, cond.Status, status, nowTime.Time)
}
// Overwrite the existing condition
@ -170,7 +170,7 @@ func SetCertificateCondition(crt *cmapi.Certificate, conditionType cmapi.Certifi
// If we've not found an existing condition of this type, we simply insert
// the new condition into the slice.
crt.Status.Conditions = append(crt.Status.Conditions, newCondition)
logf.Log.V(logf.InfoLevel).Info("Setting lastTransitionTime for Certificate %q condition %q to %v", crt.Name, conditionType, nowTime.Time)
logf.V(logf.InfoLevel).Infof("Setting lastTransitionTime for Certificate %q condition %q to %v", crt.Name, conditionType, nowTime.Time)
}
// RemoteCertificateCondition will remove any condition with this condition type
@ -219,7 +219,7 @@ func SetCertificateRequestCondition(cr *cmapi.CertificateRequest, conditionType
if cond.Status == status {
newCondition.LastTransitionTime = cond.LastTransitionTime
} else {
logf.Log.V(logf.InfoLevel).Info("Found status change for CertificateRequest %q condition %q: %q -> %q; setting lastTransitionTime to %v", cr.Name, conditionType, cond.Status, status, nowTime.Time)
logf.V(logf.InfoLevel).Infof("Found status change for CertificateRequest %q condition %q: %q -> %q; setting lastTransitionTime to %v", cr.Name, conditionType, cond.Status, status, nowTime.Time)
}
// Overwrite the existing condition
@ -230,7 +230,7 @@ func SetCertificateRequestCondition(cr *cmapi.CertificateRequest, conditionType
// If we've not found an existing condition of this type, we simply insert
// the new condition into the slice.
cr.Status.Conditions = append(cr.Status.Conditions, newCondition)
logf.Log.V(logf.InfoLevel).Info("Setting lastTransitionTime for CertificateRequest %q condition %q to %v", cr.Name, conditionType, nowTime.Time)
logf.V(logf.InfoLevel).Infof("Setting lastTransitionTime for CertificateRequest %q condition %q to %v", cr.Name, conditionType, nowTime.Time)
}
// CertificateRequestHasCondition will return true if the given

View File

@ -45,7 +45,7 @@ func (c *controller) Sync(ctx context.Context, ing *extv1beta1.Ingress) error {
ctx = logf.NewContext(ctx, log)
if !shouldSync(ing, c.defaults.autoCertificateAnnotations) {
log.V(logf.DebugLevel).Info("not syncing ingress resource as it does not contain a %q or %q annotation",
logf.V(logf.DebugLevel).Infof("not syncing ingress resource as it does not contain a %q or %q annotation",
cmapi.IngressIssuerNameAnnotationKey, cmapi.IngressClusterIssuerNameAnnotationKey)
return nil
}

View File

@ -119,7 +119,7 @@ func (a *DNSProvider) setTxtRecord(fqdn string, dns01Record *dns01Record) error
return errors.Wrapf(err, "failed to save zone data for %q", hostedDomain)
}
a.log.V(logf.DebugLevel).Info("Updated Akamai TXT record for %q on %q using SOA serial of %d", recordName, hostedDomain, newSerial)
logf.V(logf.DebugLevel).Infof("Updated Akamai TXT record for %q on %q using SOA serial of %d", recordName, hostedDomain, newSerial)
return nil
}

View File

@ -107,7 +107,7 @@ func (c *DNSProvider) Present(domain, fqdn, value string) error {
func (c *DNSProvider) CleanUp(domain, fqdn, value string) error {
z, err := c.getHostedZoneName(fqdn)
if err != nil {
c.log.V(logf.WarnLevel).Info("Error getting hosted zone name for: %s, %v", fqdn, err)
c.log.V(logf.WarnLevel).Info("Error getting hosted zone name for:", fqdn, err)
return err
}
@ -136,7 +136,7 @@ func (c *DNSProvider) createRecord(fqdn, value string, ttl int) error {
z, err := c.getHostedZoneName(fqdn)
if err != nil {
c.log.V(logf.WarnLevel).Info("Error getting hosted zone name for: %s, %v", fqdn, err)
c.log.V(logf.WarnLevel).Info("Error getting hosted zone name for:", fqdn, err)
return err
}
@ -149,7 +149,7 @@ func (c *DNSProvider) createRecord(fqdn, value string, ttl int) error {
*rparams, "", "")
if err != nil {
c.log.V(logf.WarnLevel).Info("Error creating TXT: %s, %v", z, err)
c.log.V(logf.WarnLevel).Info("Error creating TXT:", z, err)
return err
}
return nil

View File

@ -240,7 +240,7 @@ func (c *DNSProvider) getHostedZone(domain string) (string, error) {
}
}
c.log.V(logf.DebugLevel).Info("No matching public GoogleCloud managed-zone for domain %s, falling back to a private managed-zone", authZone)
c.log.V(logf.DebugLevel).Info("No matching public GoogleCloud managed-zone for domain, falling back to a private managed-zone", authZone)
// fall back to first available zone, if none public
return zones.ManagedZones[0].Name, nil
}

View File

@ -84,16 +84,16 @@ func NewDNSProviderCredentials(nameserver, tsigAlgorithm, tsigKeyName, tsigSecre
}
d.tsigAlgorithm = tsigAlgorithm
logf.Log.V(logf.DebugLevel).Info("DNSProvider nameserver: %s\n", d.nameserver)
logf.Log.V(logf.DebugLevel).Info(" tsigAlgorithm: %s\n", d.tsigAlgorithm)
logf.Log.V(logf.DebugLevel).Info(" tsigKeyName: %s\n", d.tsigKeyName)
logf.V(logf.DebugLevel).Infof("DNSProvider nameserver: %s\n", d.nameserver)
logf.V(logf.DebugLevel).Infof(" tsigAlgorithm: %s\n", d.tsigAlgorithm)
logf.V(logf.DebugLevel).Infof(" tsigKeyName: %s\n", d.tsigKeyName)
keyLen := len(d.tsigSecret)
mask := make([]rune, keyLen/2)
for i := range mask {
mask[i] = '*'
}
masked := d.tsigSecret[0:keyLen/4] + string(mask) + d.tsigSecret[keyLen/4*3:keyLen]
logf.Log.V(logf.DebugLevel).Info(" tsigSecret: %s\n", masked)
logf.V(logf.DebugLevel).Infof(" tsigSecret: %s\n", masked)
return d, nil
}

View File

@ -89,7 +89,7 @@ func (d *sessionProvider) GetSession() (*session.Session, error) {
}
if d.Role != "" {
d.log.V(logf.DebugLevel).Info("assuming role: %s", d.Role)
d.log.V(logf.DebugLevel).Info("assuming role:", d.Role)
stsSvc := d.StsProvider(sess)
result, err := stsSvc.AssumeRole(&sts.AssumeRoleInput{
RoleArn: aws.String(d.Role),
@ -199,7 +199,7 @@ func (r *DNSProvider) changeRecord(action, fqdn, value string, ttl int) error {
if err != nil {
if awserr, ok := err.(awserr.Error); ok {
if action == route53.ChangeActionDelete && awserr.Code() == route53.ErrCodeInvalidChangeBatch {
r.log.V(logf.DebugLevel).Info("ignoring InvalidChangeBatch error: %v", err)
r.log.V(logf.DebugLevel).Info("ignoring InvalidChangeBatch error:", err)
// If we try to delete something and get a 'InvalidChangeBatch' that
// means it's already deleted, no need to consider it an error.
return nil

View File

@ -71,7 +71,7 @@ func updateDomainWithCName(r *dns.Msg, fqdn string) string {
for _, rr := range r.Answer {
if cn, ok := rr.(*dns.CNAME); ok {
if cn.Hdr.Name == fqdn {
logf.Log.V(logf.DebugLevel).Info("Updating FQDN: %s with its CNAME: %s", fqdn, cn.Target)
logf.V(logf.DebugLevel).Infof("Updating FQDN: %s with its CNAME: %s", fqdn, cn.Target)
fqdn = cn.Target
break
}
@ -121,7 +121,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)
}
logf.Log.V(logf.DebugLevel).Info("Looking up TXT records for %q", fqdn)
logf.V(logf.DebugLevel).Infof("Looking up TXT records for %q", fqdn)
var found bool
for _, rr := range r.Answer {
if txt, ok := rr.(*dns.TXT); ok {
@ -159,7 +159,7 @@ func DNSQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) (
if (in != nil && in.Truncated) ||
(err != nil && strings.HasPrefix(err.Error(), "read udp") && strings.HasSuffix(err.Error(), "i/o timeout")) {
logf.Log.V(logf.DebugLevel).Info("UDP dns lookup failed, retrying with TCP: %v", err)
logf.V(logf.DebugLevel).Infof("UDP dns lookup failed, retrying with TCP: %v", err)
tcp := &dns.Client{Net: "tcp", Timeout: DNSTimeout}
// If the TCP request succeeds, the err will reset to nil
in, _, err = tcp.Exchange(m, ns)
@ -275,7 +275,7 @@ func matchCAA(caas []*dns.CAA, issuerIDs map[string]bool, iswildcard bool) bool
func lookupNameservers(fqdn string, nameservers []string) ([]string, error) {
var authoritativeNss []string
logf.Log.V(logf.DebugLevel).Info("Searching fqdn %q using seed nameservers [%s]", fqdn, strings.Join(nameservers, ", "))
logf.V(logf.DebugLevel).Infof("Searching fqdn %q using seed nameservers [%s]", fqdn, strings.Join(nameservers, ", "))
zone, err := FindZoneByFqdn(fqdn, nameservers)
if err != nil {
return nil, fmt.Errorf("Could not determine the zone for %q: %v", fqdn, err)
@ -293,7 +293,7 @@ func lookupNameservers(fqdn string, nameservers []string) ([]string, error) {
}
if len(authoritativeNss) > 0 {
logf.Log.V(logf.DebugLevel).Info("Returning authoritative nameservers [%s]", strings.Join(authoritativeNss, ", "))
logf.V(logf.DebugLevel).Infof("Returning authoritative nameservers [%s]", strings.Join(authoritativeNss, ", "))
return authoritativeNss, nil
}
return nil, fmt.Errorf("Could not determine authoritative nameservers for %q", fqdn)
@ -306,7 +306,7 @@ func FindZoneByFqdn(fqdn string, nameservers []string) (string, error) {
// Do we have it cached?
if zone, ok := fqdnToZone[fqdn]; ok {
fqdnToZoneLock.RUnlock()
logf.Log.V(logf.DebugLevel).Info("Returning cached zone record %q for fqdn %q", zone, fqdn)
logf.V(logf.DebugLevel).Infof("Returning cached zone record %q for fqdn %q", zone, fqdn)
return zone, nil
}
fqdnToZoneLock.RUnlock()
@ -342,7 +342,7 @@ func FindZoneByFqdn(fqdn string, nameservers []string) (string, error) {
zone := soa.Hdr.Name
fqdnToZone[fqdn] = zone
logf.Log.V(logf.DebugLevel).Info("Returning discovered zone record %q for fqdn %q", zone, fqdn)
logf.V(logf.DebugLevel).Infof("Returning discovered zone record %q for fqdn %q", zone, fqdn)
return zone, nil
}
}

View File

@ -44,7 +44,7 @@ const (
func (v *Vault) Setup(ctx context.Context) error {
if v.issuer.GetSpec().Vault == nil {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageVaultConfigRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageVaultConfigRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageVaultConfigRequired)
return nil
}
@ -52,7 +52,7 @@ func (v *Vault) Setup(ctx context.Context) error {
// check if Vault server info is specified.
if v.issuer.GetSpec().Vault.Server == "" ||
v.issuer.GetSpec().Vault.Path == "" {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageServerAndPathRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageServerAndPathRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageServerAndPathRequired)
return nil
}
@ -63,7 +63,7 @@ func (v *Vault) Setup(ctx context.Context) error {
// check if at least one auth method is specified.
if tokenAuth == nil && appRoleAuth == nil && kubeAuth == nil {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldsRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldsRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageAuthFieldsRequired)
return nil
}
@ -72,28 +72,28 @@ func (v *Vault) Setup(ctx context.Context) error {
if (tokenAuth != nil && appRoleAuth != nil) ||
(tokenAuth != nil && kubeAuth != nil) ||
(appRoleAuth != nil && kubeAuth != nil) {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageAuthFieldRequired)
return nil
}
// check if all mandatory Vault Token fields are set.
if tokenAuth != nil && len(tokenAuth.Name) == 0 {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageAuthFieldRequired)
return nil
}
// check if all mandatory Vault appRole fields are set.
if appRoleAuth != nil && (len(appRoleAuth.RoleId) == 0 || len(appRoleAuth.SecretRef.Name) == 0) {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageAuthFieldRequired)
return nil
}
// check if all mandatory Vault Kubernetes fields are set.
if kubeAuth != nil && (len(kubeAuth.SecretRef.Name) == 0 || len(kubeAuth.Role) == 0) {
logf.Log.V(logf.WarnLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageAuthFieldRequired)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageAuthFieldRequired)
return nil
}
@ -101,7 +101,7 @@ func (v *Vault) Setup(ctx context.Context) error {
client, err := vaultinternal.New(v.resourceNamespace, v.secretsLister, v.issuer)
if err != nil {
s := messageVaultClientInitFailed + err.Error()
logf.Log.V(logf.DebugLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, s)
logf.V(logf.DebugLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, s)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, s)
return err
}
@ -109,13 +109,13 @@ func (v *Vault) Setup(ctx context.Context) error {
health, err := client.Sys().Health()
if err != nil {
s := messageVaultHealthCheckFailed + err.Error()
logf.Log.V(logf.DebugLevel).Info("%s: %s", v.issuer.GetObjectMeta().Name, s)
logf.V(logf.DebugLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, s)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, s)
return err
}
if !health.Initialized || health.Sealed {
logf.Log.V(logf.DebugLevel).Info("%s: %s: health: %v", v.issuer.GetObjectMeta().Name, messageVaultStatusVerificationFailed, health)
logf.V(logf.DebugLevel).Infof("%s: %s: health: %v", v.issuer.GetObjectMeta().Name, messageVaultStatusVerificationFailed, health)
apiutil.SetIssuerCondition(v.issuer, v1alpha2.IssuerConditionReady, cmmeta.ConditionFalse, errorVault, messageVaultStatusVerificationFailed)
return fmt.Errorf(messageVaultStatusVerificationFailed)
}

View File

@ -155,3 +155,7 @@ func NewContext(ctx context.Context, l logr.Logger, names ...string) context.Con
}
return context.WithValue(ctx, contextKey, l)
}
func V(level int) klog.Verbose {
return klog.V(klog.Level(level))
}