diff --git a/go/flags/endtoend/mysqlctld.txt b/go/flags/endtoend/mysqlctld.txt index e6374093b57..06b48347bf6 100644 --- a/go/flags/endtoend/mysqlctld.txt +++ b/go/flags/endtoend/mysqlctld.txt @@ -22,6 +22,7 @@ Flags: --alsologtostderr log to standard error as well as files --app_idle_timeout duration Idle timeout for app connections (default 1m0s) --app_pool_size int Size of the connection pool for app connections (default 40) + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified --config-file string Full path of the config file (with extension) to use. If set, --config-path, --config-type, and --config-name are ignored. --config-file-not-found-handling ConfigFileNotFoundHandling Behavior when a config file is not found. (Options: error, exit, ignore, warn) (default warn) @@ -64,6 +65,7 @@ Flags: --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_client_creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server. --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy diff --git a/go/flags/endtoend/vtbackup.txt b/go/flags/endtoend/vtbackup.txt index 720e37dfeda..2dd6bf3ef28 100644 --- a/go/flags/endtoend/vtbackup.txt +++ b/go/flags/endtoend/vtbackup.txt @@ -55,6 +55,7 @@ Flags: --backup_storage_compress if set, the backup files will be compressed. (default true) --backup_storage_implementation string Which backup storage implementation to use for creating and restoring backups. --backup_storage_number_blocks int if backup_storage_compress is true, backup_storage_number_blocks sets the number of blocks that can be processed, in parallel, before the writer blocks, during compression (default is 2). It should be equal to the number of CPUs available for compression. (default 2) + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --builtinbackup-file-read-buffer-size uint read files using an IO buffer of this many bytes. Golang defaults are used when set to 0. --builtinbackup-file-write-buffer-size uint write files using an IO buffer of this many bytes. Golang defaults are used when set to 0. (default 2097152) --builtinbackup_mysqld_timeout duration how long to wait for mysqld to shutdown at the start of the backup. (default 10m0s) diff --git a/go/flags/endtoend/vtcombo.txt b/go/flags/endtoend/vtcombo.txt index 0357932f070..a2273cbd25d 100644 --- a/go/flags/endtoend/vtcombo.txt +++ b/go/flags/endtoend/vtcombo.txt @@ -20,6 +20,7 @@ Flags: --backup_storage_block_size int if backup_storage_compress is true, backup_storage_block_size sets the byte size for each block while compressing (default is 250000). (default 250000) --backup_storage_compress if set, the backup files will be compressed. (default true) --backup_storage_number_blocks int if backup_storage_compress is true, backup_storage_number_blocks sets the number of blocks that can be processed, in parallel, before the writer blocks, during compression (default is 2). It should be equal to the number of CPUs available for compression. (default 2) + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --binlog_host string PITR restore parameter: hostname/IP of binlog server. --binlog_password string PITR restore parameter: password of binlog server. --binlog_player_protocol string the protocol to download binlogs from a vttablet (default "grpc") @@ -145,6 +146,7 @@ Flags: --grpc_auth_mode string Which auth plugin implementation to use (eg: static) --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_crl string path to a certificate revocation list in PEM format, client certificates will be further verified against this file during TLS handshake diff --git a/go/flags/endtoend/vtctld.txt b/go/flags/endtoend/vtctld.txt index 2cf009be350..a9a5cebb0f3 100644 --- a/go/flags/endtoend/vtctld.txt +++ b/go/flags/endtoend/vtctld.txt @@ -34,6 +34,7 @@ Flags: --backup_storage_compress if set, the backup files will be compressed. (default true) --backup_storage_implementation string Which backup storage implementation to use for creating and restoring backups. --backup_storage_number_blocks int if backup_storage_compress is true, backup_storage_number_blocks sets the number of blocks that can be processed, in parallel, before the writer blocks, during compression (default is 2). It should be equal to the number of CPUs available for compression. (default 2) + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --builtinbackup-file-read-buffer-size uint read files using an IO buffer of this many bytes. Golang defaults are used when set to 0. --builtinbackup-file-write-buffer-size uint write files using an IO buffer of this many bytes. Golang defaults are used when set to 0. (default 2097152) --builtinbackup_mysqld_timeout duration how long to wait for mysqld to shutdown at the start of the backup. (default 10m0s) @@ -59,6 +60,7 @@ Flags: --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_client_creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server. --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy diff --git a/go/flags/endtoend/vtgate.txt b/go/flags/endtoend/vtgate.txt index a496b2765d2..6da515d91f3 100644 --- a/go/flags/endtoend/vtgate.txt +++ b/go/flags/endtoend/vtgate.txt @@ -28,6 +28,7 @@ Flags: --allow-kill-statement Allows the execution of kill statement --allowed_tablet_types strings Specifies the tablet types this vtgate is allowed to route queries to. Should be provided as a comma-separated set of tablet types. --alsologtostderr log to standard error as well as files + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --buffer_drain_concurrency int Maximum number of requests retried simultaneously. More concurrency will increase the load on the PRIMARY vttablet when draining the buffer. (default 1) --buffer_keyspace_shards string If not empty, limit buffering to these entries (comma separated). Entry format: keyspace or keyspace/shard. Requires --enable_buffer=true. --buffer_max_failover_duration duration Stop buffering completely if a failover takes longer than this duration. (default 20s) @@ -70,6 +71,7 @@ Flags: --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_client_creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server. --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy diff --git a/go/flags/endtoend/vtgateclienttest.txt b/go/flags/endtoend/vtgateclienttest.txt index 778dbfc8243..4580d4d6ce7 100644 --- a/go/flags/endtoend/vtgateclienttest.txt +++ b/go/flags/endtoend/vtgateclienttest.txt @@ -5,6 +5,7 @@ Usage: Flags: --alsologtostderr log to standard error as well as files + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified --config-file string Full path of the config file (with extension) to use. If set, --config-path, --config-type, and --config-name are ignored. --config-file-not-found-handling ConfigFileNotFoundHandling Behavior when a config file is not found. (Options: error, exit, ignore, warn) (default warn) @@ -17,6 +18,7 @@ Flags: --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_client_creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server. --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy diff --git a/go/flags/endtoend/vtorc.txt b/go/flags/endtoend/vtorc.txt index 74690187ed0..b13756e793c 100644 --- a/go/flags/endtoend/vtorc.txt +++ b/go/flags/endtoend/vtorc.txt @@ -22,6 +22,7 @@ Flags: --audit-purge-duration duration Duration for which audit logs are held before being purged. Should be in multiples of days (default 168h0m0s) --audit-to-backend Whether to store the audit log in the VTOrc database --audit-to-syslog Whether to store the audit log in the syslog + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --catch-sigpipe catch and ignore SIGPIPE on stdout and stderr if specified --change-tablets-with-errant-gtid-to-drained Whether VTOrc should be changing the type of tablets with errant GTIDs to DRAINED --clusters_to_watch strings Comma-separated list of keyspaces or keyspace/shards that this instance will monitor and repair. Defaults to all clusters in the topology. Example: "ks1,ks2/-80" diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt index 7d3a417d0e8..3b3f5142c97 100644 --- a/go/flags/endtoend/vttablet.txt +++ b/go/flags/endtoend/vttablet.txt @@ -56,6 +56,7 @@ Flags: --backup_storage_compress if set, the backup files will be compressed. (default true) --backup_storage_implementation string Which backup storage implementation to use for creating and restoring backups. --backup_storage_number_blocks int if backup_storage_compress is true, backup_storage_number_blocks sets the number of blocks that can be processed, in parallel, before the writer blocks, during compression (default is 2). It should be equal to the number of CPUs available for compression. (default 2) + --bind-address string Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system. --binlog_host string PITR restore parameter: hostname/IP of binlog server. --binlog_password string PITR restore parameter: password of binlog server. --binlog_player_grpc_ca string the server ca to use to validate servers when connecting @@ -170,6 +171,7 @@ Flags: --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_client_creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server. --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy diff --git a/go/flags/endtoend/vttestserver.txt b/go/flags/endtoend/vttestserver.txt index d9fbe1618e6..fb9c42d932a 100644 --- a/go/flags/endtoend/vttestserver.txt +++ b/go/flags/endtoend/vttestserver.txt @@ -47,6 +47,7 @@ Flags: --grpc_auth_mtls_allowed_substrings string List of substrings of at least one of the client certificate names (separated by colon). --grpc_auth_static_client_creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server. --grpc_auth_static_password_file string JSON File to read the users/passwords from. + --grpc_bind_address string Bind address for gRPC calls. If empty, listen on all addresses. --grpc_ca string server CA to use for gRPC connections, requires TLS, and enforces client certificate check --grpc_cert string server certificate to use for gRPC connections, requires grpc_key, enables TLS --grpc_compression string Which protocol to use for compressing gRPC. Default: nothing. Supported: snappy diff --git a/go/test/endtoend/cluster/cluster_process.go b/go/test/endtoend/cluster/cluster_process.go index ade8d4e7ec1..f74a031f4d8 100644 --- a/go/test/endtoend/cluster/cluster_process.go +++ b/go/test/endtoend/cluster/cluster_process.go @@ -1127,7 +1127,7 @@ func (cluster *LocalProcessCluster) GetAndReservePort() int { for { cluster.nextPortForProcess = cluster.nextPortForProcess + 1 log.Infof("Attempting to reserve port: %v", cluster.nextPortForProcess) - ln, err := net.Listen("tcp", fmt.Sprintf(":%v", cluster.nextPortForProcess)) + ln, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa(cluster.nextPortForProcess))) if err != nil { log.Errorf("Can't listen on port %v: %s, trying next port", cluster.nextPortForProcess, err) diff --git a/go/test/endtoend/cluster/vtctld_process.go b/go/test/endtoend/cluster/vtctld_process.go index 4902ee1be33..d0b2e5ab93e 100644 --- a/go/test/endtoend/cluster/vtctld_process.go +++ b/go/test/endtoend/cluster/vtctld_process.go @@ -66,6 +66,14 @@ func (vtctld *VtctldProcess) Setup(cell string, extraArgs ...string) (err error) "--port", fmt.Sprintf("%d", vtctld.Port), "--grpc_port", fmt.Sprintf("%d", vtctld.GrpcPort), ) + + if v, err := GetMajorVersion("vtctld"); err != nil { + return err + } else if v >= 18 { + vtctld.proc.Args = append(vtctld.proc.Args, "--bind-address", "127.0.0.1") + vtctld.proc.Args = append(vtctld.proc.Args, "--grpc_bind_address", "127.0.0.1") + } + if *isCoverage { vtctld.proc.Args = append(vtctld.proc.Args, "--test.coverprofile="+getCoveragePath("vtctld.out")) } diff --git a/go/test/endtoend/cluster/vtgate_process.go b/go/test/endtoend/cluster/vtgate_process.go index 15dccb17825..ab82a32f651 100644 --- a/go/test/endtoend/cluster/vtgate_process.go +++ b/go/test/endtoend/cluster/vtgate_process.go @@ -86,6 +86,12 @@ func (vtgate *VtgateProcess) Setup() (err error) { "--service_map", vtgate.ServiceMap, "--mysql_auth_server_impl", vtgate.MySQLAuthServerImpl, } + if v, err := GetMajorVersion("vtgate"); err != nil { + return err + } else if v >= 18 { + args = append(args, "--bind-address", "127.0.0.1") + args = append(args, "--grpc_bind_address", "127.0.0.1") + } // If no explicit mysql_server_version has been specified then we autodetect // the MySQL version that will be used for the test and base the vtgate's // mysql server version on that. diff --git a/go/test/endtoend/cluster/vtorc_process.go b/go/test/endtoend/cluster/vtorc_process.go index def050b9188..f80690d8d60 100644 --- a/go/test/endtoend/cluster/vtorc_process.go +++ b/go/test/endtoend/cluster/vtorc_process.go @@ -118,6 +118,13 @@ func (orc *VTOrcProcess) Setup() (err error) { // Faster topo information refresh speeds up the tests. This doesn't add any significant load either "--topo-information-refresh-duration", "3s", ) + + if v, err := GetMajorVersion("vtorc"); err != nil { + return err + } else if v >= 18 { + orc.proc.Args = append(orc.proc.Args, "--bind-address", "127.0.0.1") + } + if *isCoverage { orc.proc.Args = append(orc.proc.Args, "--test.coverprofile="+getCoveragePath("orc.out")) } diff --git a/go/test/endtoend/cluster/vttablet_process.go b/go/test/endtoend/cluster/vttablet_process.go index 6f87dfb4b35..517f4bf3874 100644 --- a/go/test/endtoend/cluster/vttablet_process.go +++ b/go/test/endtoend/cluster/vttablet_process.go @@ -112,6 +112,13 @@ func (vttablet *VttabletProcess) Setup() (err error) { "--vreplication_tablet_type", vttablet.VreplicationTabletType, "--db_charset", vttablet.Charset, ) + if v, err := GetMajorVersion("vttablet"); err != nil { + return err + } else if v >= 18 { + vttablet.proc.Args = append(vttablet.proc.Args, "--bind-address", "127.0.0.1") + vttablet.proc.Args = append(vttablet.proc.Args, "--grpc_bind_address", "127.0.0.1") + } + if *isCoverage { vttablet.proc.Args = append(vttablet.proc.Args, "--test.coverprofile="+getCoveragePath("vttablet.out")) } diff --git a/go/test/endtoend/keyspace/keyspace_test.go b/go/test/endtoend/keyspace/keyspace_test.go index c8ff519910f..338ad5c8cd2 100644 --- a/go/test/endtoend/keyspace/keyspace_test.go +++ b/go/test/endtoend/keyspace/keyspace_test.go @@ -248,7 +248,7 @@ func TestDeleteKeyspace(t *testing.T) { // Start over and this time use recursive DeleteKeyspace to do everything. _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateKeyspace", "test_delete_keyspace") _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateShard", "test_delete_keyspace/0") - _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--", "--port=1234", "--keyspace=test_delete_keyspace", "--shard=0", "zone1-0000000100", "primary") + _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--", "--port=1234", "--bind-address=127.0.0.1", "--keyspace=test_delete_keyspace", "--shard=0", "zone1-0000000100", "primary") // Create the serving/replication entries and check that they exist, // so we can later check they're deleted. @@ -279,10 +279,10 @@ func TestDeleteKeyspace(t *testing.T) { _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateKeyspace", "test_delete_keyspace_removekscell") _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateShard", "test_delete_keyspace_removekscell/0") _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateShard", "test_delete_keyspace_removekscell/1") - _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "-keyspace=test_delete_keyspace_removekscell", "--shard=0", "zone1-0000000100", "primary") - _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "-keyspace=test_delete_keyspace_removekscell", "--shard=1", "zone1-0000000101", "primary") - _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "-keyspace=test_delete_keyspace_removekscell", "--shard=0", "zone2-0000000100", "replica") - _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "-keyspace=test_delete_keyspace_removekscell", "--shard=1", "zone2-0000000101", "replica") + _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "--bind-address=127.0.0.1", "-keyspace=test_delete_keyspace_removekscell", "--shard=0", "zone1-0000000100", "primary") + _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "--bind-address=127.0.0.1", "-keyspace=test_delete_keyspace_removekscell", "--shard=1", "zone1-0000000101", "primary") + _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "--bind-address=127.0.0.1", "-keyspace=test_delete_keyspace_removekscell", "--shard=0", "zone2-0000000100", "replica") + _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("InitTablet", "--port=1234", "--bind-address=127.0.0.1", "-keyspace=test_delete_keyspace_removekscell", "--shard=1", "zone2-0000000101", "replica") // Create the serving/replication entries and check that they exist, so we can later check they're deleted. _ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("RebuildKeyspaceGraph", "test_delete_keyspace_removekscell") diff --git a/go/vt/servenv/grpc_server.go b/go/vt/servenv/grpc_server.go index bd79aed8108..7a41cca389a 100644 --- a/go/vt/servenv/grpc_server.go +++ b/go/vt/servenv/grpc_server.go @@ -19,9 +19,9 @@ package servenv import ( "context" "crypto/tls" - "fmt" "math" "net" + "strconv" "time" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" @@ -72,6 +72,9 @@ var ( // gRPCPort is the port to listen on for gRPC. If zero, don't listen. gRPCPort int + // gRPCBindAddress is the address to bind to for gRPC. If empty, bind to all addresses. + gRPCBindAddress string + // gRPCMaxConnectionAge is the maximum age of a client connection, before GoAway is sent. // This is useful for L4 loadbalancing to ensure rebalancing after scaling. gRPCMaxConnectionAge = time.Duration(math.MaxInt64) @@ -124,6 +127,7 @@ var ( func RegisterGRPCServerFlags() { OnParse(func(fs *pflag.FlagSet) { fs.IntVar(&gRPCPort, "grpc_port", gRPCPort, "Port to listen on for gRPC calls. If zero, do not listen.") + fs.StringVar(&gRPCBindAddress, "grpc_bind_address", gRPCBindAddress, "Bind address for gRPC calls. If empty, listen on all addresses.") fs.DurationVar(&gRPCMaxConnectionAge, "grpc_max_connection_age", gRPCMaxConnectionAge, "Maximum age of a client connection before GoAway is sent.") fs.DurationVar(&gRPCMaxConnectionAgeGrace, "grpc_max_connection_age_grace", gRPCMaxConnectionAgeGrace, "Additional grace period after grpc_max_connection_age, after which connections are forcibly closed.") fs.IntVar(&gRPCInitialConnWindowSize, "grpc_server_initial_conn_window_size", gRPCInitialConnWindowSize, "gRPC server initial connection window size") @@ -284,7 +288,7 @@ func serveGRPC() { // listen on the port log.Infof("Listening for gRPC calls on port %v", gRPCPort) - listener, err := net.Listen("tcp", fmt.Sprintf(":%d", gRPCPort)) + listener, err := net.Listen("tcp", net.JoinHostPort(gRPCBindAddress, strconv.Itoa(gRPCPort))) if err != nil { log.Exitf("Cannot listen on port %v for gRPC: %v", gRPCPort, err) } diff --git a/go/vt/servenv/run.go b/go/vt/servenv/run.go index 5b585184331..ec0d8971e56 100644 --- a/go/vt/servenv/run.go +++ b/go/vt/servenv/run.go @@ -17,11 +17,11 @@ limitations under the License. package servenv import ( - "fmt" "net" "net/url" "os" "os/signal" + "strconv" "syscall" "time" @@ -37,14 +37,14 @@ var ( // Run starts listening for RPC and HTTP requests, // and blocks until it the process gets a signal. -func Run(port int) { +func Run(bindAddress string, port int) { populateListeningURL(int32(port)) createGRPCServer() onRunHooks.Fire() serveGRPC() serveSocketFile() - l, err := net.Listen("tcp", fmt.Sprintf(":%v", port)) + l, err := net.Listen("tcp", net.JoinHostPort(bindAddress, strconv.Itoa(port))) if err != nil { log.Exit(err) } diff --git a/go/vt/servenv/servenv.go b/go/vt/servenv/servenv.go index 40d74c06062..e7c28855997 100644 --- a/go/vt/servenv/servenv.go +++ b/go/vt/servenv/servenv.go @@ -60,7 +60,8 @@ import ( var ( // port is part of the flags used when calling RegisterDefaultFlags. - port int + port int + bindAddress string // mutex used to protect the Init function mu sync.Mutex @@ -266,6 +267,7 @@ func FireRunHooks() { func RegisterDefaultFlags() { OnParse(func(fs *pflag.FlagSet) { fs.IntVar(&port, "port", port, "port for the server") + fs.StringVar(&bindAddress, "bind-address", bindAddress, "Bind address for the server. If empty, the server will listen on all available unicast and anycast IP addresses of the local system.") }) } @@ -276,7 +278,7 @@ func Port() int { // RunDefault calls Run() with the parameters from the flags. func RunDefault() { - Run(port) + Run(bindAddress, port) } var ( diff --git a/go/vt/vttest/vtprocess.go b/go/vt/vttest/vtprocess.go index a6c03176f1b..ec26acf41b8 100644 --- a/go/vt/vttest/vtprocess.go +++ b/go/vt/vttest/vtprocess.go @@ -127,6 +127,7 @@ func (vtp *VtProcess) WaitStart() (err error) { vtp.proc = exec.Command( vtp.Binary, "--port", fmt.Sprintf("%d", vtp.Port), + "--bind-address", "127.0.0.1", "--log_dir", vtp.LogDirectory, "--alsologtostderr", ) diff --git a/go/vt/wrangler/fake_tablet_test.go b/go/vt/wrangler/fake_tablet_test.go index d81443777f7..0fc9487eeca 100644 --- a/go/vt/wrangler/fake_tablet_test.go +++ b/go/vt/wrangler/fake_tablet_test.go @@ -164,7 +164,7 @@ func (ft *fakeTablet) StartActionLoop(t *testing.T, wr *Wrangler) { // Listen on a random port for gRPC. var err error - ft.Listener, err = net.Listen("tcp", ":0") + ft.Listener, err = net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("Cannot listen: %v", err) } @@ -173,7 +173,7 @@ func (ft *fakeTablet) StartActionLoop(t *testing.T, wr *Wrangler) { // If needed, listen on a random port for HTTP. vtPort := ft.Tablet.PortMap["vt"] if ft.StartHTTPServer { - ft.HTTPListener, err = net.Listen("tcp", ":0") + ft.HTTPListener, err = net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("Cannot listen on http port: %v", err) } @@ -186,6 +186,7 @@ func (ft *fakeTablet) StartActionLoop(t *testing.T, wr *Wrangler) { } ft.Tablet.PortMap["vt"] = vtPort ft.Tablet.PortMap["grpc"] = gRPCPort + ft.Tablet.Hostname = "127.0.0.1" // Create a test tm on that port, and re-read the record // (it has new ports and IP). diff --git a/go/vt/wrangler/testlib/fake_tablet.go b/go/vt/wrangler/testlib/fake_tablet.go index 7d840e13c16..a1b30813f53 100644 --- a/go/vt/wrangler/testlib/fake_tablet.go +++ b/go/vt/wrangler/testlib/fake_tablet.go @@ -27,11 +27,9 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" "google.golang.org/grpc" "vitess.io/vitess/go/mysql/fakesqldb" - "vitess.io/vitess/go/netutil" "vitess.io/vitess/go/vt/binlog/binlogplayer" "vitess.io/vitess/go/vt/dbconfigs" "vitess.io/vitess/go/vt/mysqlctl" @@ -132,12 +130,10 @@ func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32, t.Fatalf("uid has to be between 0 and 99: %v", uid) } mysqlPort := int32(3300 + uid) - hostname, err := netutil.FullyQualifiedHostname() - require.NoError(t, err) tablet := &topodatapb.Tablet{ Alias: &topodatapb.TabletAlias{Cell: cell, Uid: uid}, - Hostname: hostname, - MysqlHostname: hostname, + Hostname: "127.0.0.1", + MysqlHostname: "127.0.0.1", PortMap: map[string]int32{ "vt": int32(8100 + uid), "grpc": int32(8200 + uid), @@ -180,7 +176,7 @@ func (ft *FakeTablet) StartActionLoop(t *testing.T, wr *wrangler.Wrangler) { // Listen on a random port for gRPC. var err error - ft.Listener, err = net.Listen("tcp", ":0") + ft.Listener, err = net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("Cannot listen: %v", err) } @@ -189,7 +185,7 @@ func (ft *FakeTablet) StartActionLoop(t *testing.T, wr *wrangler.Wrangler) { // If needed, listen on a random port for HTTP. vtPort := ft.Tablet.PortMap["vt"] if ft.StartHTTPServer { - ft.HTTPListener, err = net.Listen("tcp", ":0") + ft.HTTPListener, err = net.Listen("tcp", "127.0.0.1:0") if err != nil { t.Fatalf("Cannot listen on http port: %v", err) } @@ -202,6 +198,7 @@ func (ft *FakeTablet) StartActionLoop(t *testing.T, wr *wrangler.Wrangler) { } ft.Tablet.PortMap["vt"] = vtPort ft.Tablet.PortMap["grpc"] = gRPCPort + ft.Tablet.Hostname = "127.0.0.1" // Create a test tm on that port, and re-read the record // (it has new ports and IP).