From aee6a491c8ea5dd2192d8df5d85a7d18cb4c22ec Mon Sep 17 00:00:00 2001 From: Martin Sucha Date: Tue, 16 Mar 2021 14:19:14 +0100 Subject: [PATCH] nsqadmin: add option to skip resolving on startup When running nsqlookupd in Kubernetes and pointing to a specific identity of a pod from statefulset, the DNS name is not resolvable if the pod is not currently scheduled. The lookup check currently causes nsqadmin to exit during startup even if only one of the listed nsqlookupd instances is not resolvable. I want nsqadmin to always start. If no lookupd instances are currently resolvable/reachable that fact will be visible in the user interface. --- apps/nsqadmin/main.go | 1 + nsqadmin/nsqadmin.go | 20 +++++++++++--------- nsqadmin/options.go | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/nsqadmin/main.go b/apps/nsqadmin/main.go index cae3144ad..f6ae4ea5a 100644 --- a/apps/nsqadmin/main.go +++ b/apps/nsqadmin/main.go @@ -56,6 +56,7 @@ func nsqadminFlagSet(opts *nsqadmin.Options) *flag.FlagSet { flagSet.Var(&nsqlookupdHTTPAddresses, "lookupd-http-address", "lookupd HTTP address (may be given multiple times)") nsqdHTTPAddresses := app.StringArray{} flagSet.Var(&nsqdHTTPAddresses, "nsqd-http-address", "nsqd HTTP address (may be given multiple times)") + flagSet.Bool("skip-resolve-on-startup", false, "skip DNS lookup of addresses on startup") adminUsers := app.StringArray{} flagSet.Var(&adminUsers, "admin-user", "admin user (may be given multiple times; if specified, only these users will be able to perform privileged actions; acl-http-header is used to determine the authenticated user)") diff --git a/nsqadmin/nsqadmin.go b/nsqadmin/nsqadmin.go index f27801a25..7d67a4c9c 100644 --- a/nsqadmin/nsqadmin.go +++ b/nsqadmin/nsqadmin.go @@ -82,17 +82,19 @@ func New(opts *Options) (*NSQAdmin, error) { n.httpClientTLSConfig.RootCAs = tlsCertPool } - for _, address := range opts.NSQLookupdHTTPAddresses { - _, err := net.ResolveTCPAddr("tcp", address) - if err != nil { - return nil, fmt.Errorf("failed to resolve --lookupd-http-address (%s) - %s", address, err) + if !opts.SkipResolveOnStartup { + for _, address := range opts.NSQLookupdHTTPAddresses { + _, err := net.ResolveTCPAddr("tcp", address) + if err != nil { + return nil, fmt.Errorf("failed to resolve --lookupd-http-address (%s) - %s", address, err) + } } - } - for _, address := range opts.NSQDHTTPAddresses { - _, err := net.ResolveTCPAddr("tcp", address) - if err != nil { - return nil, fmt.Errorf("failed to resolve --nsqd-http-address (%s) - %s", address, err) + for _, address := range opts.NSQDHTTPAddresses { + _, err := net.ResolveTCPAddr("tcp", address) + if err != nil { + return nil, fmt.Errorf("failed to resolve --nsqd-http-address (%s) - %s", address, err) + } } } diff --git a/nsqadmin/options.go b/nsqadmin/options.go index 8100af881..0540482a8 100644 --- a/nsqadmin/options.go +++ b/nsqadmin/options.go @@ -25,6 +25,7 @@ type Options struct { NSQLookupdHTTPAddresses []string `flag:"lookupd-http-address" cfg:"nsqlookupd_http_addresses"` NSQDHTTPAddresses []string `flag:"nsqd-http-address" cfg:"nsqd_http_addresses"` + SkipResolveOnStartup bool `flag:"skip-resolve-on-startup" cfg:"skip_resolve_on_startup"` HTTPClientConnectTimeout time.Duration `flag:"http-client-connect-timeout"` HTTPClientRequestTimeout time.Duration `flag:"http-client-request-timeout"`