From c32c71c836947f1e23f0a308ca80f94b8e8b1133 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 24 Jul 2023 15:13:35 -0700 Subject: [PATCH] allow DNS cache TTL to be configurable (#17709) this is added for now as a hidden variable --- cmd/common-main.go | 38 ++++++++++++++++++++++---------------- cmd/server-main.go | 7 +++++++ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 94523e332..98f8d53ec 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -102,22 +102,6 @@ func init() { globalIsCICD = env.Get("MINIO_CI_CD", "") != "" || env.Get("CI", "") != "" - // Call to refresh will refresh names in cache. - go func() { - // Baremetal setups set DNS refresh window to 10 minutes. - t := time.NewTicker(10 * time.Minute) - defer t.Stop() - for { - select { - case <-t.C: - globalDNSCache.Refresh() - - case <-GlobalContext.Done(): - return - } - } - }() - console.SetColor("Debug", fcolor.New()) gob.Register(StorageErr("")) @@ -443,6 +427,28 @@ func handleCommonCmdArgs(ctx *cli.Context) { globalCertsCADir = &ConfigDir{path: filepath.Join(globalCertsDir.Get(), certsCADir)} logger.FatalIf(mkdirAllIgnorePerm(globalCertsCADir.Get()), "Unable to create certs CA directory at %s", globalCertsCADir.Get()) + + // Check if we have configured a custom DNS cache TTL. + dnsTTL := ctx.Duration("dns-cache-ttl") + if dnsTTL <= 0 { + dnsTTL = 10 * time.Minute + } + + // Call to refresh will refresh names in cache. + go func() { + // Baremetal setups set DNS refresh window up to dnsTTL duration. + t := time.NewTicker(dnsTTL) + defer t.Stop() + for { + select { + case <-t.C: + globalDNSCache.Refresh() + + case <-GlobalContext.Done(): + return + } + } + }() } type envKV struct { diff --git a/cmd/server-main.go b/cmd/server-main.go index bb337470a..8b76a50e0 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -121,6 +121,13 @@ var ServerFlags = []cli.Flag{ Hidden: true, EnvVar: "MINIO_INTERFACE", }, + cli.DurationFlag{ + Name: "dns-cache-ttl", + Usage: "custom DNS cache TTL for baremetal setups", + Hidden: true, + Value: 10 * time.Minute, + EnvVar: "MINIO_DNS_CACHE_TTL", + }, cli.StringSliceFlag{ Name: "ftp", Usage: "enable and configure an FTP(Secure) server",