Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: Support cluster name flags in all non-sql client commands #48000

Merged
merged 1 commit into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ func init() {
// 'start' will check that the flag is properly defined.
VarFlag(f, &serverCfg.JoinList, cliflags.Join)
VarFlag(f, clusterNameSetter{&baseCfg.ClusterName}, cliflags.ClusterName)
BoolFlag(f, &baseCfg.DisableClusterNameVerification, cliflags.DisableClusterNameVerification, false)
BoolFlag(f, &baseCfg.DisableClusterNameVerification,
cliflags.DisableClusterNameVerification, baseCfg.DisableClusterNameVerification)
if cmd == startSingleNodeCmd {
// Even though all server flags are supported for
// 'start-single-node', we intend that command to be used by
Expand Down Expand Up @@ -470,14 +471,14 @@ func init() {
debugZipCmd,
dumpCmd,
genHAProxyCmd,
initCmd,
quitCmd,
sqlShellCmd,
/* StartCmds are covered above */
}
clientCmds = append(clientCmds, authCmds...)
clientCmds = append(clientCmds, nodeCmds...)
clientCmds = append(clientCmds, systemBenchCmds...)
clientCmds = append(clientCmds, initCmd)
clientCmds = append(clientCmds, nodeLocalCmds...)
for _, cmd := range clientCmds {
f := cmd.PersistentFlags()
Expand Down Expand Up @@ -612,14 +613,18 @@ func init() {
}
}

// Make the other non-SQL client commands also recognize --url in
// strict SSL mode.
// Make the non-SQL client commands also recognize --url in strict SSL mode
// and ensure they can connect to clusters that use a cluster-name.
for _, cmd := range clientCmds {
if f := flagSetForCmd(cmd).Lookup(cliflags.URL.Name); f != nil {
// --url already registered above, nothing to do.
continue
}
VarFlag(cmd.PersistentFlags(), urlParser{cmd, &cliCtx, true /* strictSSL */}, cliflags.URL)
f := cmd.PersistentFlags()
VarFlag(f, urlParser{cmd, &cliCtx, true /* strictSSL */}, cliflags.URL)
VarFlag(f, clusterNameSetter{&baseCfg.ClusterName}, cliflags.ClusterName)
BoolFlag(f, &baseCfg.DisableClusterNameVerification,
cliflags.DisableClusterNameVerification, baseCfg.DisableClusterNameVerification)
}

// Commands that print tables.
Expand Down
36 changes: 36 additions & 0 deletions pkg/cli/interactive_tests/test_cluster_name.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /usr/bin/env expect -f
#
source [file join [file dirnam $argv0] common.tcl]

# Start a server with a --join flag so the init command is required
# (even though we have no intention of starting a second node). Note that unlike other
# expect-based tests, this one doesn't use a fifo for --pid_file
# because we don't want reads from that fifo to change the outcome.
system "$argv start --insecure --pid-file=server_pid -s=path=logs/db --listen-addr=localhost --background --join=localhost:26258 --cluster-name=foo >>logs/expect-cmd.log 2>&1"

start_test "Check that the server has informed us and the log file that it was ready before forking off in the background"
system "grep -q 'initial startup completed' logs/db/logs/cockroach.log"
system "grep -q 'will now attempt to join a running cluster, or wait' logs/db/logs/cockroach.log"
end_test

start_test "Check that init works with a cluster-name provided"
system "$argv init --insecure --host=localhost --cluster-name=foo"
end_test

start_test "Check that decommission works with a cluster-name provided"
send "$argv node decommission 1 --insecure --host=localhost --wait=none --cluster-name=foo\r"
end_test

start_test "Check that recommission works with cluster name verification disabled"
send "$argv node recommission 1 --insecure --host=localhost --disable-cluster-name-verification\r"
end_test

start_test "Check that debug commands work with a cluster name provided"
send "$argv debug gossip-values --insecure --host=localhost --cluster-name=foo\r"
end_test

start_test "Check that quit works with a cluster-name provided"
send "$argv quit --insecure --host=localhost --wait=none --cluster-name=foo\r"
end_test

stop_server $argv