linodev4: configurable propagation timeout. (#961)

This commit is contained in:
Ludovic Fernandez 2019-09-17 21:25:59 +02:00 committed by GitHub
parent d7d75bea51
commit 6bbba5bbaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 19 deletions

View file

@ -833,6 +833,7 @@ func displayDNSHelp(name string) error {
ew.writeln(`Additional Configuration:`) ew.writeln(`Additional Configuration:`)
ew.writeln(` - "LINODE_HTTP_TIMEOUT": API request timeout`) ew.writeln(` - "LINODE_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "LINODE_POLLING_INTERVAL": Time between DNS propagation check`) 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(` - "LINODE_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln() ew.writeln()

View file

@ -41,6 +41,7 @@ More information [here](/lego/dns/#configuration-and-credentials).
|--------------------------------|-------------| |--------------------------------|-------------|
| `LINODE_HTTP_TIMEOUT` | API request timeout | | `LINODE_HTTP_TIMEOUT` | API request timeout |
| `LINODE_POLLING_INTERVAL` | Time between DNS propagation check | | `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_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. The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.

View file

@ -24,18 +24,20 @@ const (
// Config is used to configure the creation of the DNSProvider // Config is used to configure the creation of the DNSProvider
type Config struct { type Config struct {
Token string Token string
PollingInterval time.Duration PropagationTimeout time.Duration
TTL int PollingInterval time.Duration
HTTPTimeout time.Duration TTL int
HTTPTimeout time.Duration
} }
// NewDefaultConfig returns a default configuration for the DNSProvider // NewDefaultConfig returns a default configuration for the DNSProvider
func NewDefaultConfig() *Config { func NewDefaultConfig() *Config {
return &Config{ return &Config{
PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second), PropagationTimeout: env.GetOrDefaultSecond("LINODE_PROPAGATION_TIMEOUT", 0),
TTL: env.GetOrDefaultInt("LINODE_TTL", minTTL), PollingInterval: env.GetOrDefaultSecond("LINODE_POLLING_INTERVAL", 15*time.Second),
HTTPTimeout: env.GetOrDefaultSecond("LINODE_HTTP_TIMEOUT", 0), 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 // Timeout returns the timeout and interval to use when checking for DNS
// propagation. Adjusting here to cope with spikes in propagation times. // propagation. Adjusting here to cope with spikes in propagation times.
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { func (d *DNSProvider) Timeout() (time.Duration, time.Duration) {
// Since Linode only updates their zone files every X minutes, we need timeout := d.config.PropagationTimeout
// to figure out how many minutes we have to wait until we hit the next if d.config.PropagationTimeout <= 0 {
// interval of X. We then wait another couple of minutes, just to be // Since Linode only updates their zone files every X minutes, we need
// safe. Hopefully at some point during all of this, the record will // to figure out how many minutes we have to wait until we hit the next
// have propagated throughout Linode's network. // interval of X. We then wait another couple of minutes, just to be
minsRemaining := dnsUpdateFreqMins - (time.Now().Minute() % dnsUpdateFreqMins) // 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) + timeout = (time.Duration(minsRemaining) * time.Minute) +
(minTTL * time.Second) + (minTTL * time.Second) +
(dnsUpdateFudgeSecs * time.Second) (dnsUpdateFudgeSecs * time.Second)
interval = d.config.PollingInterval }
return
return timeout, d.config.PollingInterval
} }
// Present creates a TXT record using the specified parameters. // Present creates a TXT record using the specified parameters.

View file

@ -11,6 +11,7 @@ Example = ''''''
LINODE_TOKEN = "API token" LINODE_TOKEN = "API token"
[Configuration.Additional] [Configuration.Additional]
LINODE_POLLING_INTERVAL = "Time between DNS propagation check" 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_TTL = "The TTL of the TXT record used for the DNS challenge"
LINODE_HTTP_TIMEOUT = "API request timeout" LINODE_HTTP_TIMEOUT = "API request timeout"