From 9a27c4a2f0edbc36e6f1ef7ece7fc14af73f4cd8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 22 Sep 2021 09:16:12 -0700 Subject: [PATCH] do not panic if DNS_WEBHOOK_ENDPOINT is not reachable (#13265) --- internal/config/dns/operator_dns.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/config/dns/operator_dns.go b/internal/config/dns/operator_dns.go index 5b5e0f1b7..1aceffba7 100644 --- a/internal/config/dns/operator_dns.go +++ b/internal/config/dns/operator_dns.go @@ -90,16 +90,19 @@ func (c *OperatorDNS) Put(bucket string) error { if err = c.addAuthHeader(req); err != nil { return newError(bucket, err) } + resp, err := c.httpClient.Do(req) if err != nil { if derr := c.Delete(bucket); derr != nil { return newError(bucket, derr) } + return err } - var errorStringBuilder strings.Builder - io.Copy(&errorStringBuilder, io.LimitReader(resp.Body, resp.ContentLength)) - xhttp.DrainBody(resp.Body) + defer xhttp.DrainBody(resp.Body) + if resp.StatusCode != http.StatusOK { + var errorStringBuilder strings.Builder + io.Copy(&errorStringBuilder, io.LimitReader(resp.Body, resp.ContentLength)) errorString := errorStringBuilder.String() switch resp.StatusCode { case http.StatusConflict: