From 0d44d8937e5a2112b1993595cd456bfd82e8a07d Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 9 Apr 2024 18:43:10 +0200 Subject: [PATCH] Fixed messages --- deploy/sthome-webhook/Chart.yaml | 4 ++-- deploy/sthome-webhook/values.yaml | 2 +- go.mod | 6 +++-- pkg/util/wait.go | 38 +++++++++++++++---------------- version.txt | 6 ++--- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/deploy/sthome-webhook/Chart.yaml b/deploy/sthome-webhook/Chart.yaml index 3f8258a..1aac4ea 100644 --- a/deploy/sthome-webhook/Chart.yaml +++ b/deploy/sthome-webhook/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 -appVersion: v0.0.5-alpha.23 +appVersion: v0.0.5-alpha.24 description: Cert-Manager webhook for sthome name: sthome-webhook -version: 0.0.5-alpha.23 +version: 0.0.5-alpha.24 diff --git a/deploy/sthome-webhook/values.yaml b/deploy/sthome-webhook/values.yaml index 4cd7f20..18a009c 100644 --- a/deploy/sthome-webhook/values.yaml +++ b/deploy/sthome-webhook/values.yaml @@ -31,7 +31,7 @@ clusterIssuer: image: repository: stuurmcp/cert-manager-webhook-sthome #repository: wstat.sthome.net:5000/cert-manager-webhook-sthome - tag: 0.0.5-alpha.23 + tag: 0.0.5-alpha.24 #pullPolicy should be IfNotPresent. Set to Always for testing purposes pullPolicy: IfNotPresent diff --git a/go.mod b/go.mod index e7bfc61..39302df 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,10 @@ require ( require k8s.io/klog/v2 v2.110.1 -require k8s.io/apimachinery v0.29.0 +require ( + github.com/miekg/dns v1.1.58 + k8s.io/apimachinery v0.29.0 +) require ( cloud.google.com/go/compute v1.23.3 // indirect @@ -83,7 +86,6 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect - github.com/miekg/dns v1.1.58 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect diff --git a/pkg/util/wait.go b/pkg/util/wait.go index 8dd1f80..364073b 100644 --- a/pkg/util/wait.go +++ b/pkg/util/wait.go @@ -20,8 +20,8 @@ import ( "time" "github.com/miekg/dns" - - logf "github.com/cert-manager/cert-manager/pkg/logs" + klog "k8s.io/klog/v2" + //logf "github.com/cert-manager/cert-manager/pkg/logs" ) type preCheckDNSFunc func(fqdn, value string, nameservers []string, @@ -91,13 +91,13 @@ func followCNAMEs(fqdn string, nameservers []string, fqdnChain ...string) (strin if !ok || cn.Hdr.Name != fqdn { continue } - logf.V(logf.DebugLevel).Infof("Updating FQDN: %s with its CNAME: %s", fqdn, cn.Target) + klog.Infof("Updating FQDN: %s with its CNAME: %s", fqdn, cn.Target) // Check if we were here before to prevent loops in the chain of CNAME records. for _, fqdnInChain := range fqdnChain { if cn.Target != fqdnInChain { continue } - return "", fmt.Errorf("Found recursive CNAME record to %q when looking up %q", cn.Target, fqdn) + return "", fmt.Errorf("found recursive CNAME record to %q when looking up %q", cn.Target, fqdn) } return followCNAMEs(cn.Target, nameservers, append(fqdnChain, fqdn)...) } @@ -142,7 +142,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.V(logf.DebugLevel).Infof("Looking up TXT records for %q", fqdn) + klog.Infof("Looking up TXT records for %q", fqdn) var found bool for _, rr := range r.Answer { if txt, ok := rr.(*dns.TXT); ok { @@ -157,7 +157,7 @@ func checkAuthoritativeNss(fqdn, value string, nameservers []string) (bool, erro return false, nil } } - logf.V(logf.DebugLevel).Infof("Selfchecking using the DNS Lookup method was successful") + klog.Infof("Selfchecking using the DNS Lookup method was successful") return true, nil } @@ -199,7 +199,7 @@ func DNSQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) ( // Try TCP if UDP fails if (in != nil && in.Truncated) || (err != nil && strings.HasPrefix(err.Error(), "read udp") && strings.HasSuffix(err.Error(), "i/o timeout")) { - logf.V(logf.DebugLevel).Infof("UDP dns lookup failed, retrying with TCP: %v", err) + klog.Infof("UDP dns lookup failed, retrying with TCP: %v", err) // If the TCP request succeeds, the err will reset to nil in, _, err = tcp.Exchange(m, ns) } @@ -293,14 +293,14 @@ func ValidateCAA(domain string, issuerID []string, iswildcard bool, nameservers var authNS []string authNS, err = lookupNameservers(queryDomain, nameservers) if err != nil { - return fmt.Errorf("Could not validate CAA record: %s", err) + return fmt.Errorf("could not validate CAA record: %s", err) } for i, ans := range authNS { authNS[i] = net.JoinHostPort(ans, "53") } msg, err = DNSQuery(queryDomain, dns.TypeCAA, authNS, false) if err != nil { - return fmt.Errorf("Could not validate CAA record: %s", err) + return fmt.Errorf("could not validate CAA record: %s", err) } // domain may not exist, which is fine. It will fail HTTP01 checks // but DNS01 checks will create a proper domain @@ -308,7 +308,7 @@ func ValidateCAA(domain string, issuerID []string, iswildcard bool, nameservers break } if msg.Rcode != dns.RcodeSuccess { - return fmt.Errorf("Could not validate CAA: Unexpected response code '%s' for %s", + return fmt.Errorf("could not validate CAA: Unexpected response code '%s' for %s", dns.RcodeToString[msg.Rcode], domain) } oldQuery := queryDomain @@ -376,10 +376,10 @@ func matchCAA(caas []*dns.CAA, issuerIDs map[string]bool, iswildcard bool) bool func lookupNameservers(fqdn string, nameservers []string) ([]string, error) { var authoritativeNss []string - logf.V(logf.DebugLevel).Infof("Searching fqdn %q using seed nameservers [%s]", fqdn, strings.Join(nameservers, ", ")) + klog.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) + return nil, fmt.Errorf("could not determine the zone for %q: %v", fqdn, err) } r, err := DNSQuery(zone, dns.TypeNS, nameservers, true) @@ -394,10 +394,10 @@ func lookupNameservers(fqdn string, nameservers []string) ([]string, error) { } if len(authoritativeNss) > 0 { - logf.V(logf.DebugLevel).Infof("Returning authoritative nameservers [%s]", strings.Join(authoritativeNss, ", ")) + klog.Infof("Returning authoritative nameservers [%s]", strings.Join(authoritativeNss, ", ")) return authoritativeNss, nil } - return nil, fmt.Errorf("Could not determine authoritative nameservers for %q", fqdn) + return nil, fmt.Errorf("could not determine authoritative nameservers for %q", fqdn) } // FindZoneByFqdn determines the zone apex for the given fqdn by recursing up the @@ -407,7 +407,7 @@ func FindZoneByFqdn(fqdn string, nameservers []string) (string, error) { // Do we have it cached? if zone, ok := fqdnToZone[fqdn]; ok { fqdnToZoneLock.RUnlock() - logf.V(logf.DebugLevel).Infof("Returning cached zone record %q for fqdn %q", zone, fqdn) + klog.Infof("Returning cached zone record %q for fqdn %q", zone, fqdn) return zone, nil } fqdnToZoneLock.RUnlock() @@ -444,7 +444,7 @@ func FindZoneByFqdn(fqdn string, nameservers []string) (string, error) { // Any non-successful response code, other than NXDOMAIN, is treated as an error // and interrupts the search. if in.Rcode != dns.RcodeSuccess { - return "", fmt.Errorf("When querying the SOA record for the domain '%s' using nameservers %v, rcode was expected to be 'NOERROR' or 'NXDOMAIN', but got '%s'", + return "", fmt.Errorf("when querying the SOA record for the domain '%s' using nameservers %v, rcode was expected to be 'NOERROR' or 'NXDOMAIN', but got '%s'", domain, nameservers, dns.RcodeToString[in.Rcode]) } @@ -461,13 +461,13 @@ func FindZoneByFqdn(fqdn string, nameservers []string) (string, error) { zone := soa.Hdr.Name fqdnToZone[fqdn] = zone - logf.V(logf.DebugLevel).Infof("Returning discovered zone record %q for fqdn %q", zone, fqdn) + klog.Infof("Returning discovered zone record %q for fqdn %q", zone, fqdn) return zone, nil } } } - return "", fmt.Errorf("Could not find the SOA record in the DNS tree for the domain '%s' using nameservers %v", fqdn, nameservers) + return "", fmt.Errorf("could not find the SOA record in the DNS tree for the domain '%s' using nameservers %v", fqdn, nameservers) } // dnsMsgContainsCNAME checks for a CNAME answer in msg @@ -505,7 +505,7 @@ func WaitFor(timeout, interval time.Duration, f func() (bool, error)) error { for { select { case <-timeup: - return fmt.Errorf("Time limit exceeded. Last error: %s", lastErr) + return fmt.Errorf("time limit exceeded. Last error: %s", lastErr) default: } diff --git a/version.txt b/version.txt index 211be36..aa938c9 100644 --- a/version.txt +++ b/version.txt @@ -1,3 +1,3 @@ -0.0.5-alpha.23 -20240409-1736 -23 \ No newline at end of file +0.0.5-alpha.24 +20240409-1838 +24 \ No newline at end of file