mirror of
https://github.com/minio/minio.git
synced 2025-11-07 21:02:58 -05:00
fix: upon DNS refresh() failure use previous values (#17561)
DNS refresh() in-case of MinIO can safely re-use the previous values on bare-metal setups, since bare-metal arrangements do not change DNS in any manner commonly. This PR simplifies that, we only ever need DNS caching on bare-metal setups. - On containerized setups do not enable DNS caching at all, as it may have adverse effects on the overall effectiveness of k8s DNS systems. k8s DNS systems are dynamic and expect applications to avoid managing DNS caching themselves, instead provide a cleaner container native caching implementations that must be used. - update IsDocker() detection, including podman runtime - move to minio/dnscache fork for a simpler package
This commit is contained in:
@@ -21,13 +21,17 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/rs/dnscache"
|
||||
)
|
||||
|
||||
// DialContextWithDNSCache is a helper function which returns `net.DialContext` function.
|
||||
// It randomly fetches an IP from the DNS cache and dials it by the given dial
|
||||
// function. It dials one by one and returns first connected `net.Conn`.
|
||||
// LookupHost is a function to make custom lookupHost for optional cached DNS requests
|
||||
type LookupHost func(ctx context.Context, host string) (addrs []string, err error)
|
||||
|
||||
// DialContextWithLookupHost is a helper function which returns `net.DialContext` function.
|
||||
// It randomly fetches an IP via custom LookupHost function and dials it by the given dial
|
||||
// function. LookupHost may implement an internal DNS caching implementation, lookupHost
|
||||
// input if nil then net.DefaultResolver.LookupHost is used.
|
||||
//
|
||||
// It dials one by one and returns first connected `net.Conn`.
|
||||
// If it fails to dial all IPs from cache it returns first error. If no baseDialFunc
|
||||
// is given, it sets default dial function.
|
||||
//
|
||||
@@ -35,7 +39,11 @@ import (
|
||||
//
|
||||
// In this function, it uses functions from `rand` package. To make it really random,
|
||||
// you MUST call `rand.Seed` and change the value from the default in your application
|
||||
func DialContextWithDNSCache(resolver *dnscache.Resolver, baseDialCtx DialContext) DialContext {
|
||||
func DialContextWithLookupHost(lookupHost LookupHost, baseDialCtx DialContext) DialContext {
|
||||
if lookupHost == nil {
|
||||
lookupHost = net.DefaultResolver.LookupHost
|
||||
}
|
||||
|
||||
if baseDialCtx == nil {
|
||||
// This is same as which `http.DefaultTransport` uses.
|
||||
baseDialCtx = (&net.Dialer{
|
||||
@@ -43,6 +51,7 @@ func DialContextWithDNSCache(resolver *dnscache.Resolver, baseDialCtx DialContex
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext
|
||||
}
|
||||
|
||||
return func(ctx context.Context, network, addr string) (conn net.Conn, err error) {
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
@@ -54,7 +63,7 @@ func DialContextWithDNSCache(resolver *dnscache.Resolver, baseDialCtx DialContex
|
||||
return baseDialCtx(ctx, "tcp", addr)
|
||||
}
|
||||
|
||||
ips, err := resolver.LookupHost(ctx, host)
|
||||
ips, err := lookupHost(ctx, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user