func FetchResourceRecordUsingCloudflareDNS(reqLogger logr.Logger, name string) (*CloudflareResponse, error) {
	requestUrl := cloudflareDNSOverHttpsEndpoint + "?name=" + name + "&type=TXT"
	reqLogger.Info(fmt.Sprintf("cloudflare dns-over-https Request URL: %v", requestUrl))
	var request, err = http.NewRequest("GET", requestUrl, nil)
	if err != nil {
		reqLogger.Error(err, "error occurred creating new cloudflare dns-over-https request")
		return nil, err
	}
	request.Header.Set("accept", cloudflareRequestContentType)
	netClient := &http.Client{
		Timeout: time.Second * cloudflareRequestTimeout,
	}
	response, err := netClient.Do(request)
	if err != nil {
		reqLogger.Error(err, "error occurred executing request")
		return nil, err
	}
	defer response.Body.Close()
	responseBody, err := ioutil.ReadAll(response.Body)
	if err != nil {
		reqLogger.Error(err, "")
		return nil, err
	}
	reqLogger.Info("response from Cloudflare: " + string(responseBody))
	var cloudflareResponse CloudflareResponse
	err = json.Unmarshal(responseBody, &cloudflareResponse)
	if err != nil {
		reqLogger.Error(err, "there was problem parsing the json response from cloudflare.")
		return nil, err
	}
	return &cloudflareResponse, nil
}
FetchResourceRecordUsingCloudflareDNS contacts cloudflareDnsOverHttpsEndpoint and returns the json response.
package certificaterequest
import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"
	"time"
	"github.com/go-logr/logr"
	"github.com/pkg/errors"
)
type CloudflareQuestion struct {
	Name string `json:"name"`
	Type int    `json:"type"`
}
type CloudflareAnswer struct {
	Name string `json:"name"`
	Type int    `json:"type"`
	TTL  int    `json:"TTL"`
	Data string `json:"data"`
}
type CloudflareResponse struct {
	Status    int                  `json:"Status"`
	TC        bool                 `json:"TC"`
	RC        bool                 `json:"RC"`
	RA        bool                 `json:"RA"`
	AD        bool                 `json:"AD"`
	CD        bool                 `json:"CD"`
	Questions []CloudflareQuestion `json:"Question"`
	Answers   []CloudflareAnswer   `json:"Answer"`
	Authority []CloudflareAnswer   `json:"Authority"`
}
func VerifyDnsResourceRecordUpdate(reqLogger logr.Logger, fqdn string, txtValue string) bool {
	var negativeCacheTTL int
	for attempt := 1; attempt < maxAttemptsForDnsPropagationCheck; attempt++ {
		var err error
		sleepDuration := waitTimePeriodDnsPropagationCheck
		if attempt > 1 && negativeCacheTTL > 0 {
			if negativeCacheTTL > maxNegativeCacheTTL {
				reqLogger.Info("negative cache TTL is too long; giving up")
				return false
			}
			if negativeCacheTTL > sleepDuration {
				sleepDuration = negativeCacheTTL
			}
		}
		reqLogger.Info(fmt.Sprintf("attempt %v to verify resource record %v has been updated with value %v", attempt, fqdn, txtValue))
		reqLogger.Info(fmt.Sprintf("will query DNS in %v seconds", sleepDuration))
		time.Sleep(time.Duration(sleepDuration) * time.Second)
		negativeCacheTTL = 0
		response, err := FetchResourceRecordUsingCloudflareDNS(reqLogger, fqdn)
		if err != nil {
			reqLogger.Error(err, "failed to fetch DNS records")
			continue
		}
		if dnsRCode(response.Status) == dnsRCodeNameError && len(response.Authority) > 0 {
			negativeCacheTTL = response.Authority[0].TTL
			reqLogger.Info(fmt.Sprintf("got a negative cache response with a TTL of %v seconds", negativeCacheTTL))
			negativeCacheTTL += 5
			continue
		}
		if len(response.Answers) == 0 {
			reqLogger.Info("no answers received from cloudflare; likely not propagated")
			continue
		}
		cfName := strings.TrimSuffix(response.Answers[0].Name, ".")
		cfData := strings.Trim(response.Answers[0].Data, "\"")
		if strings.EqualFold(cfName, fqdn) && cfData == txtValue {
			return true
		}
		reqLogger.Info("could not validate DNS propagation for " + fqdn)
	}
	errMsg := fmt.Sprintf("unable to verify that resource record %v has been updated to value %v after %v attempts.", fqdn, txtValue, maxAttemptsForDnsPropagationCheck)
	reqLogger.Error(errors.New(errMsg), errMsg)
	return false
}