mirror of
https://github.com/minio/minio.git
synced 2025-03-30 17:23:42 -04:00
bring back minor DNS cache for k8s setups (#19341)
k8s as it stands is flaky in DNS lookups, bring this change back such that we can cache DNS atleast for 30secs TTL.
This commit is contained in:
parent
4b9192034c
commit
dc45a5010d
@ -66,9 +66,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// serverDebugLog will enable debug printing
|
// serverDebugLog will enable debug printing
|
||||||
var serverDebugLog = env.Get("_MINIO_SERVER_DEBUG", config.EnableOff) == config.EnableOn
|
var (
|
||||||
|
serverDebugLog = env.Get("_MINIO_SERVER_DEBUG", config.EnableOff) == config.EnableOn
|
||||||
var currentReleaseTime time.Time
|
currentReleaseTime time.Time
|
||||||
|
orchestrated = IsKubernetes() || IsDocker()
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
@ -494,7 +496,11 @@ func runDNSCache(ctx *cli.Context) {
|
|||||||
dnsTTL := ctx.Duration("dns-cache-ttl")
|
dnsTTL := ctx.Duration("dns-cache-ttl")
|
||||||
// Check if we have configured a custom DNS cache TTL.
|
// Check if we have configured a custom DNS cache TTL.
|
||||||
if dnsTTL <= 0 {
|
if dnsTTL <= 0 {
|
||||||
dnsTTL = 10 * time.Minute
|
if orchestrated {
|
||||||
|
dnsTTL = 30 * time.Second
|
||||||
|
} else {
|
||||||
|
dnsTTL = 10 * time.Minute
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call to refresh will refresh names in cache.
|
// Call to refresh will refresh names in cache.
|
||||||
@ -757,12 +763,7 @@ func serverHandleEnvVars() {
|
|||||||
for _, endpoint := range minioEndpoints {
|
for _, endpoint := range minioEndpoints {
|
||||||
if net.ParseIP(endpoint) == nil {
|
if net.ParseIP(endpoint) == nil {
|
||||||
// Checking if the IP is a DNS entry.
|
// Checking if the IP is a DNS entry.
|
||||||
lookupHost := globalDNSCache.LookupHost
|
addrs, err := globalDNSCache.LookupHost(GlobalContext, endpoint)
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = net.DefaultResolver.LookupHost
|
|
||||||
}
|
|
||||||
|
|
||||||
addrs, err := lookupHost(GlobalContext, endpoint)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.FatalIf(err, "Unable to initialize MinIO server with [%s] invalid entry found in MINIO_PUBLIC_IPS", endpoint)
|
logger.FatalIf(err, "Unable to initialize MinIO server with [%s] invalid entry found in MINIO_PUBLIC_IPS", endpoint)
|
||||||
}
|
}
|
||||||
|
@ -590,8 +590,6 @@ func hostResolveToLocalhost(endpoint Endpoint) bool {
|
|||||||
|
|
||||||
// UpdateIsLocal - resolves the host and discovers the local host.
|
// UpdateIsLocal - resolves the host and discovers the local host.
|
||||||
func (endpoints Endpoints) UpdateIsLocal() error {
|
func (endpoints Endpoints) UpdateIsLocal() error {
|
||||||
orchestrated := IsDocker() || IsKubernetes()
|
|
||||||
|
|
||||||
var epsResolved int
|
var epsResolved int
|
||||||
var foundLocal bool
|
var foundLocal bool
|
||||||
resolvedList := make([]bool, len(endpoints))
|
resolvedList := make([]bool, len(endpoints))
|
||||||
@ -775,8 +773,6 @@ type PoolEndpointList []Endpoints
|
|||||||
|
|
||||||
// UpdateIsLocal - resolves all hosts and discovers which are local
|
// UpdateIsLocal - resolves all hosts and discovers which are local
|
||||||
func (p PoolEndpointList) UpdateIsLocal() error {
|
func (p PoolEndpointList) UpdateIsLocal() error {
|
||||||
orchestrated := IsDocker() || IsKubernetes()
|
|
||||||
|
|
||||||
var epsResolved int
|
var epsResolved int
|
||||||
var epCount int
|
var epCount int
|
||||||
|
|
||||||
@ -1034,7 +1030,6 @@ func CreatePoolEndpoints(serverAddr string, poolsLayout ...poolDisksLayout) ([]E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
orchestrated := IsKubernetes() || IsDocker()
|
|
||||||
reverseProxy := (env.Get("_MINIO_REVERSE_PROXY", "") != "") && ((env.Get("MINIO_CI_CD", "") != "") || (env.Get("CI", "") != ""))
|
reverseProxy := (env.Get("_MINIO_REVERSE_PROXY", "") != "") && ((env.Get("MINIO_CI_CD", "") != "") || (env.Get("CI", "") != ""))
|
||||||
// If not orchestrated
|
// If not orchestrated
|
||||||
// and not setup in reverse proxy
|
// and not setup in reverse proxy
|
||||||
|
@ -35,13 +35,9 @@ var globalGrid atomic.Pointer[grid.Manager]
|
|||||||
var globalGridStart = make(chan struct{})
|
var globalGridStart = make(chan struct{})
|
||||||
|
|
||||||
func initGlobalGrid(ctx context.Context, eps EndpointServerPools) error {
|
func initGlobalGrid(ctx context.Context, eps EndpointServerPools) error {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
hosts, local := eps.GridHosts()
|
hosts, local := eps.GridHosts()
|
||||||
g, err := grid.NewManager(ctx, grid.ManagerOptions{
|
g, err := grid.NewManager(ctx, grid.ManagerOptions{
|
||||||
Dialer: grid.ContextDialer(xhttp.DialContextWithLookupHost(lookupHost, xhttp.NewInternodeDialContext(rest.DefaultTimeout, globalTCPOptions))),
|
Dialer: grid.ContextDialer(xhttp.DialContextWithLookupHost(globalDNSCache.LookupHost, xhttp.NewInternodeDialContext(rest.DefaultTimeout, globalTCPOptions))),
|
||||||
Local: local,
|
Local: local,
|
||||||
Hosts: hosts,
|
Hosts: hosts,
|
||||||
AddAuth: newCachedAuthToken(),
|
AddAuth: newCachedAuthToken(),
|
||||||
|
@ -98,12 +98,7 @@ func mustGetLocalIP6() (ipList set.StringSet) {
|
|||||||
|
|
||||||
// getHostIP returns IP address of given host.
|
// getHostIP returns IP address of given host.
|
||||||
func getHostIP(host string) (ipList set.StringSet, err error) {
|
func getHostIP(host string) (ipList set.StringSet, err error) {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
addrs, err := globalDNSCache.LookupHost(GlobalContext, host)
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = net.DefaultResolver.LookupHost
|
|
||||||
}
|
|
||||||
|
|
||||||
addrs, err := lookupHost(GlobalContext, host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ipList, err
|
return ipList, err
|
||||||
}
|
}
|
||||||
|
@ -141,9 +141,14 @@ var ServerFlags = []cli.Flag{
|
|||||||
},
|
},
|
||||||
cli.DurationFlag{
|
cli.DurationFlag{
|
||||||
Name: "dns-cache-ttl",
|
Name: "dns-cache-ttl",
|
||||||
Usage: "custom DNS cache TTL for baremetal setups",
|
Usage: "custom DNS cache TTL",
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
Value: 10 * time.Minute,
|
Value: func() time.Duration {
|
||||||
|
if orchestrated {
|
||||||
|
return 30 * time.Second
|
||||||
|
}
|
||||||
|
return 10 * time.Minute
|
||||||
|
}(),
|
||||||
EnvVar: "MINIO_DNS_CACHE_TTL",
|
EnvVar: "MINIO_DNS_CACHE_TTL",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
@ -593,12 +598,7 @@ func setGlobalInternodeInterface(interfaceName string) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
lookupHost := globalDNSCache.LookupHost
|
haddrs, err := globalDNSCache.LookupHost(ctx, host)
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = net.DefaultResolver.LookupHost
|
|
||||||
}
|
|
||||||
|
|
||||||
haddrs, err := lookupHost(ctx, host)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ip = haddrs[0]
|
ip = haddrs[0]
|
||||||
}
|
}
|
||||||
@ -636,12 +636,7 @@ func getServerListenAddrs() []string {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
lookupHost := globalDNSCache.LookupHost
|
haddrs, err := globalDNSCache.LookupHost(ctx, host)
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = net.DefaultResolver.LookupHost
|
|
||||||
}
|
|
||||||
|
|
||||||
haddrs, err := lookupHost(ctx, host)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, addr := range haddrs {
|
for _, addr := range haddrs {
|
||||||
addrs.Add(net.JoinHostPort(addr, globalMinioPort))
|
addrs.Add(net.JoinHostPort(addr, globalMinioPort))
|
||||||
|
42
cmd/utils.go
42
cmd/utils.go
@ -572,13 +572,8 @@ func ToS3ETag(etag string) string {
|
|||||||
|
|
||||||
// GetDefaultConnSettings returns default HTTP connection settings.
|
// GetDefaultConnSettings returns default HTTP connection settings.
|
||||||
func GetDefaultConnSettings() xhttp.ConnSettings {
|
func GetDefaultConnSettings() xhttp.ConnSettings {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return xhttp.ConnSettings{
|
return xhttp.ConnSettings{
|
||||||
LookupHost: lookupHost,
|
LookupHost: globalDNSCache.LookupHost,
|
||||||
DialTimeout: rest.DefaultTimeout,
|
DialTimeout: rest.DefaultTimeout,
|
||||||
RootCAs: globalRootCAs,
|
RootCAs: globalRootCAs,
|
||||||
TCPOptions: globalTCPOptions,
|
TCPOptions: globalTCPOptions,
|
||||||
@ -588,13 +583,8 @@ func GetDefaultConnSettings() xhttp.ConnSettings {
|
|||||||
// NewInternodeHTTPTransport returns a transport for internode MinIO
|
// NewInternodeHTTPTransport returns a transport for internode MinIO
|
||||||
// connections.
|
// connections.
|
||||||
func NewInternodeHTTPTransport(maxIdleConnsPerHost int) func() http.RoundTripper {
|
func NewInternodeHTTPTransport(maxIdleConnsPerHost int) func() http.RoundTripper {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return xhttp.ConnSettings{
|
return xhttp.ConnSettings{
|
||||||
LookupHost: lookupHost,
|
LookupHost: globalDNSCache.LookupHost,
|
||||||
DialTimeout: rest.DefaultTimeout,
|
DialTimeout: rest.DefaultTimeout,
|
||||||
RootCAs: globalRootCAs,
|
RootCAs: globalRootCAs,
|
||||||
CipherSuites: fips.TLSCiphers(),
|
CipherSuites: fips.TLSCiphers(),
|
||||||
@ -607,13 +597,8 @@ func NewInternodeHTTPTransport(maxIdleConnsPerHost int) func() http.RoundTripper
|
|||||||
// NewCustomHTTPProxyTransport is used only for proxied requests, specifically
|
// NewCustomHTTPProxyTransport is used only for proxied requests, specifically
|
||||||
// only supports HTTP/1.1
|
// only supports HTTP/1.1
|
||||||
func NewCustomHTTPProxyTransport() func() *http.Transport {
|
func NewCustomHTTPProxyTransport() func() *http.Transport {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return xhttp.ConnSettings{
|
return xhttp.ConnSettings{
|
||||||
LookupHost: lookupHost,
|
LookupHost: globalDNSCache.LookupHost,
|
||||||
DialTimeout: rest.DefaultTimeout,
|
DialTimeout: rest.DefaultTimeout,
|
||||||
RootCAs: globalRootCAs,
|
RootCAs: globalRootCAs,
|
||||||
CipherSuites: fips.TLSCiphers(),
|
CipherSuites: fips.TLSCiphers(),
|
||||||
@ -626,13 +611,8 @@ func NewCustomHTTPProxyTransport() func() *http.Transport {
|
|||||||
// NewHTTPTransportWithClientCerts returns a new http configuration
|
// NewHTTPTransportWithClientCerts returns a new http configuration
|
||||||
// used while communicating with the cloud backends.
|
// used while communicating with the cloud backends.
|
||||||
func NewHTTPTransportWithClientCerts(clientCert, clientKey string) *http.Transport {
|
func NewHTTPTransportWithClientCerts(clientCert, clientKey string) *http.Transport {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
s := xhttp.ConnSettings{
|
s := xhttp.ConnSettings{
|
||||||
LookupHost: lookupHost,
|
LookupHost: globalDNSCache.LookupHost,
|
||||||
DialTimeout: defaultDialTimeout,
|
DialTimeout: defaultDialTimeout,
|
||||||
RootCAs: globalRootCAs,
|
RootCAs: globalRootCAs,
|
||||||
TCPOptions: globalTCPOptions,
|
TCPOptions: globalTCPOptions,
|
||||||
@ -663,14 +643,9 @@ const defaultDialTimeout = 5 * time.Second
|
|||||||
|
|
||||||
// NewHTTPTransportWithTimeout allows setting a timeout.
|
// NewHTTPTransportWithTimeout allows setting a timeout.
|
||||||
func NewHTTPTransportWithTimeout(timeout time.Duration) *http.Transport {
|
func NewHTTPTransportWithTimeout(timeout time.Duration) *http.Transport {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return xhttp.ConnSettings{
|
return xhttp.ConnSettings{
|
||||||
DialContext: newCustomDialContext(),
|
DialContext: newCustomDialContext(),
|
||||||
LookupHost: lookupHost,
|
LookupHost: globalDNSCache.LookupHost,
|
||||||
DialTimeout: defaultDialTimeout,
|
DialTimeout: defaultDialTimeout,
|
||||||
RootCAs: globalRootCAs,
|
RootCAs: globalRootCAs,
|
||||||
TCPOptions: globalTCPOptions,
|
TCPOptions: globalTCPOptions,
|
||||||
@ -702,14 +677,9 @@ func newCustomDialContext() xhttp.DialContext {
|
|||||||
// NewRemoteTargetHTTPTransport returns a new http configuration
|
// NewRemoteTargetHTTPTransport returns a new http configuration
|
||||||
// used while communicating with the remote replication targets.
|
// used while communicating with the remote replication targets.
|
||||||
func NewRemoteTargetHTTPTransport(insecure bool) func() *http.Transport {
|
func NewRemoteTargetHTTPTransport(insecure bool) func() *http.Transport {
|
||||||
lookupHost := globalDNSCache.LookupHost
|
|
||||||
if IsKubernetes() || IsDocker() {
|
|
||||||
lookupHost = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return xhttp.ConnSettings{
|
return xhttp.ConnSettings{
|
||||||
DialContext: newCustomDialContext(),
|
DialContext: newCustomDialContext(),
|
||||||
LookupHost: lookupHost,
|
LookupHost: globalDNSCache.LookupHost,
|
||||||
RootCAs: globalRootCAs,
|
RootCAs: globalRootCAs,
|
||||||
TCPOptions: globalTCPOptions,
|
TCPOptions: globalTCPOptions,
|
||||||
EnableHTTP2: false,
|
EnableHTTP2: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user