From 6bbba5bbaad13c2b9caa97c16c40ae757b94273f Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 17 Sep 2019 21:25:59 +0200 Subject: [PATCH] linodev4: configurable propagation timeout. (#961) --- cmd/zz_gen_cmd_dnshelp.go | 1 + docs/content/dns/zz_gen_linodev4.md | 1 + providers/dns/linodev4/linodev4.go | 43 ++++++++++++++++------------ providers/dns/linodev4/linodev4.toml | 1 + 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/cmd/zz_gen_cmd_dnshelp.go b/cmd/zz_gen_cmd_dnshelp.go index 7e5c45ee..c249816d 100644 --- a/cmd/zz_gen_cmd_dnshelp.go +++ b/cmd/zz_gen_cmd_dnshelp.go @@ -833,6 +833,7 @@ func displayDNSHelp(name string) error { ew.writeln(`Additional Configuration:`) ew.writeln(` - "LINODE_HTTP_TIMEOUT": API request timeout`) ew.writeln(` - "LINODE_POLLING_INTERVAL": Time between DNS propagation check`) + ew.writeln(` - "LINODE_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`) ew.writeln(` - "LINODE_TTL": The TTL of the TXT record used for the DNS challenge`) ew.writeln() diff --git a/docs/content/dns/zz_gen_linodev4.md b/docs/content/dns/zz_gen_linodev4.md index 7c8d6523..3e71510a 100644 --- a/docs/content/dns/zz_gen_linodev4.md +++ b/docs/content/dns/zz_gen_linodev4.md @@ -41,6 +41,7 @@ More information [here](/lego/dns/#configuration-and-credentials). |--------------------------------|-------------| | `LINODE_HTTP_TIMEOUT` | API request timeout | | `LINODE_POLLING_INTERVAL` | Time between DNS propagation check | +| `LINODE_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation | | `LINODE_TTL` | The TTL of the TXT record used for the DNS challenge | The environment variable names can be suffixed by `_FILE` to reference a file instead of a value. diff --git a/providers/dns/linodev4/linodev4.go b/providers/dns/linodev4/linodev4.go index 0b1ffc95..affcb4c1 100644 --- a/providers/dns/linodev4/linodev4.go +++ b/providers/dns/linodev4/linodev4.go @@ -24,18 +24,20 @@ const ( // Config is used to configure the creation of the DNSProvider type Config struct { - Token string - PollingInterval time.Duration - TTL int - HTTPTimeout time.Duration + Token string + PropagationTimeout time.Duration + PollingInterval time.Duration + TTL int + HTTPTimeout time.Duration } // NewDefaultConfig returns a default configuration for the DNSProvider func NewDefaultConfig() *Config { return &Config{ - PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second), - TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL), - HTTPTimeout: env.GetOrDefaultSecond("LINODE_HTTP_TIMEOUT", 0), + PropagationTimeout: env.GetOrDefaultSecond("LINODE_PROPAGATION_TIMEOUT", 0), + PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second), + TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL), + HTTPTimeout: env.GetOrDefaultSecond("LINODE_HTTP_TIMEOUT", 0), } } @@ -97,19 +99,22 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { // Timeout returns the timeout and interval to use when checking for DNS // propagation. Adjusting here to cope with spikes in propagation times. -func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { - // Since Linode only updates their zone files every X minutes, we need - // to figure out how many minutes we have to wait until we hit the next - // interval of X. We then wait another couple of minutes, just to be - // safe. Hopefully at some point during all of this, the record will - // have propagated throughout Linode's network. - minsRemaining := dnsUpdateFreqMins - (time.Now().Minute() % dnsUpdateFreqMins) +func (d *DNSProvider) Timeout() (time.Duration, time.Duration) { + timeout := d.config.PropagationTimeout + if d.config.PropagationTimeout <= 0 { + // Since Linode only updates their zone files every X minutes, we need + // to figure out how many minutes we have to wait until we hit the next + // interval of X. We then wait another couple of minutes, just to be + // safe. Hopefully at some point during all of this, the record will + // have propagated throughout Linode's network. + minsRemaining := dnsUpdateFreqMins - (time.Now().Minute() % dnsUpdateFreqMins) - timeout = (time.Duration(minsRemaining) * time.Minute) + - (minTTL * time.Second) + - (dnsUpdateFudgeSecs * time.Second) - interval = d.config.PollingInterval - return + timeout = (time.Duration(minsRemaining) * time.Minute) + + (minTTL * time.Second) + + (dnsUpdateFudgeSecs * time.Second) + } + + return timeout, d.config.PollingInterval } // Present creates a TXT record using the specified parameters. diff --git a/providers/dns/linodev4/linodev4.toml b/providers/dns/linodev4/linodev4.toml index 6111c3e4..10865bb3 100644 --- a/providers/dns/linodev4/linodev4.toml +++ b/providers/dns/linodev4/linodev4.toml @@ -11,6 +11,7 @@ Example = '''''' LINODE_TOKEN = "API token" [Configuration.Additional] LINODE_POLLING_INTERVAL = "Time between DNS propagation check" + LINODE_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation" LINODE_TTL = "The TTL of the TXT record used for the DNS challenge" LINODE_HTTP_TIMEOUT = "API request timeout"