mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4882 from xiang90/ctl_combine
*: combine etcdctl and etcdctlv3
This commit is contained in:
commit
2b83d9c2e5
@ -1,5 +1,4 @@
|
||||
# Use goreman to run `go get github.com/mattn/goreman`
|
||||
# etcd1 is the default client server for etcdctlv3 commands
|
||||
etcd1: bin/etcd --name infra1 --listen-client-urls http://127.0.0.1:2379 --advertise-client-urls http://127.0.0.1:2379 --listen-peer-urls http://127.0.0.1:12380 --initial-advertise-peer-urls http://127.0.0.1:12380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof
|
||||
etcd2: bin/etcd --name infra2 --listen-client-urls http://127.0.0.1:22379 --advertise-client-urls http://127.0.0.1:22379 --listen-peer-urls http://127.0.0.1:22380 --initial-advertise-peer-urls http://127.0.0.1:22380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof
|
||||
etcd3: bin/etcd --name infra3 --listen-client-urls http://127.0.0.1:32379 --advertise-client-urls http://127.0.0.1:32379 --listen-peer-urls http://127.0.0.1:32380 --initial-advertise-peer-urls http://127.0.0.1:32380 --initial-cluster-token etcd-cluster-1 --initial-cluster 'infra1=http://127.0.0.1:12380,infra2=http://127.0.0.1:22380,infra3=http://127.0.0.1:32380' --initial-cluster-state new --enable-pprof
|
||||
|
1
build
1
build
@ -32,4 +32,3 @@ fi
|
||||
# Static compilation is useful when etcd is run in a container
|
||||
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s -X ${REPO_PATH}/version.GitSHA${LINK_OPERATOR}${GIT_SHA}" -o bin/etcd ${REPO_PATH}
|
||||
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o bin/etcdctl ${REPO_PATH}/etcdctl
|
||||
CGO_ENABLED=0 go build $GO_BUILD_FLAGS -installsuffix cgo -ldflags "-s" -o bin/etcdctlv3 ${REPO_PATH}/etcdctlv3
|
||||
|
@ -15,11 +15,11 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/pkg/fileutil"
|
||||
"github.com/coreos/etcd/pkg/testutil"
|
||||
)
|
||||
|
||||
@ -58,8 +58,10 @@ func TestCtlV3SetPeerTLSQuorum(t *testing.T) {
|
||||
func testCtlV3Set(t *testing.T, cfg *etcdProcessClusterConfig, dialTimeout time.Duration, quorum bool) {
|
||||
defer testutil.AfterTest(t)
|
||||
|
||||
os.Setenv("ETCDCTL_API", "3")
|
||||
epc := setupCtlV3Test(t, cfg, quorum)
|
||||
defer func() {
|
||||
os.Unsetenv("ETCDCTL_API")
|
||||
if errC := epc.Close(); errC != nil {
|
||||
t.Fatalf("error closing etcd processes (%v)", errC)
|
||||
}
|
||||
@ -108,7 +110,7 @@ func ctlV3PrefixArgs(clus *etcdProcessCluster, dialTimeout time.Duration) []stri
|
||||
}
|
||||
endpoints = strings.Join(es, ",")
|
||||
}
|
||||
cmdArgs := []string{"../bin/etcdctlv3", "--endpoints", endpoints, "--dial-timeout", dialTimeout.String()}
|
||||
cmdArgs := []string{"../bin/etcdctl", "--endpoints", endpoints, "--dial-timeout", dialTimeout.String()}
|
||||
if clus.cfg.clientTLS == clientTLS {
|
||||
cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
||||
}
|
||||
@ -129,14 +131,8 @@ func ctlV3Get(clus *etcdProcessCluster, key, value string, dialTimeout time.Dura
|
||||
return spawnWithExpectedString(cmdArgs, key)
|
||||
}
|
||||
|
||||
func mustCtlV3(t *testing.T) {
|
||||
if !fileutil.Exist("../bin/etcdctlv3") {
|
||||
t.Fatalf("could not find etcdctlv3 binary")
|
||||
}
|
||||
}
|
||||
|
||||
func setupCtlV3Test(t *testing.T, cfg *etcdProcessClusterConfig, quorum bool) *etcdProcessCluster {
|
||||
mustCtlV3(t)
|
||||
mustEtcdctl(t)
|
||||
if !quorum {
|
||||
cfg = configStandalone(*cfg)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
etcdctl
|
||||
========
|
||||
|
||||
TODO: merge into README.md.
|
||||
|
||||
## Commands
|
||||
|
||||
### PUT [options] \<key\> \<value\>
|
||||
@ -277,7 +279,7 @@ bar
|
||||
|
||||
### LOCK \<lockname\>
|
||||
|
||||
LOCK acquires a distributed named mutex with a given name. Once the lock is acquired, it will be held until etcdctlv3 is terminated.
|
||||
LOCK acquires a distributed named mutex with a given name. Once the lock is acquired, it will be held until etcdctl is terminated.
|
||||
|
||||
#### Return value
|
||||
|
70
etcdctl/ctlv2/ctl.go
Normal file
70
etcdctl/ctlv2/ctl.go
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2015 CoreOS, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package ctlv2 contains the main entry point for the etcdctl for v2 API.
|
||||
package ctlv2
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/coreos/etcd/etcdctl/ctlv2/command"
|
||||
"github.com/coreos/etcd/version"
|
||||
)
|
||||
|
||||
func Start() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "etcdctl"
|
||||
app.Version = version.Version
|
||||
app.Usage = "A simple command line client for etcd."
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
|
||||
cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
|
||||
cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple`, `extended` or `json`)"},
|
||||
cli.StringFlag{Name: "discovery-srv, D", Usage: "domain name to query for SRV records describing cluster endpoints"},
|
||||
cli.StringFlag{Name: "peers, C", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
|
||||
cli.StringFlag{Name: "endpoint", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
|
||||
cli.StringFlag{Name: "endpoints", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"http://127.0.0.1:2379,http://127.0.0.1:4001\")"},
|
||||
cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"},
|
||||
cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
|
||||
cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
|
||||
cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."},
|
||||
cli.DurationFlag{Name: "timeout", Value: time.Second, Usage: "connection timeout per request"},
|
||||
cli.DurationFlag{Name: "total-timeout", Value: 5 * time.Second, Usage: "timeout for the command execution (except watch)"},
|
||||
}
|
||||
app.Commands = []cli.Command{
|
||||
command.NewBackupCommand(),
|
||||
command.NewClusterHealthCommand(),
|
||||
command.NewMakeCommand(),
|
||||
command.NewMakeDirCommand(),
|
||||
command.NewRemoveCommand(),
|
||||
command.NewRemoveDirCommand(),
|
||||
command.NewGetCommand(),
|
||||
command.NewLsCommand(),
|
||||
command.NewSetCommand(),
|
||||
command.NewSetDirCommand(),
|
||||
command.NewUpdateCommand(),
|
||||
command.NewUpdateDirCommand(),
|
||||
command.NewWatchCommand(),
|
||||
command.NewExecWatchCommand(),
|
||||
command.NewMemberCommand(),
|
||||
command.NewImportSnapCommand(),
|
||||
command.NewUserCommands(),
|
||||
command.NewRoleCommands(),
|
||||
command.NewAuthCommands(),
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
@ -25,7 +25,7 @@ import (
|
||||
func NewVersionCommand() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version of etcdctlv3.",
|
||||
Short: "Print the version of etcdctl.",
|
||||
Run: versionCommandFunc,
|
||||
}
|
||||
}
|
@ -12,19 +12,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// etcdctlv3 is a command line application that utilizes v3 API.
|
||||
package main
|
||||
// Package ctlv3 contains the main entry point for the etcdctl for v3 API.
|
||||
package ctlv3
|
||||
|
||||
import (
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/etcdctlv3/command"
|
||||
"github.com/coreos/etcd/etcdctl/ctlv3/command"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
cliName = "etcdctlv3"
|
||||
cliName = "etcdctl"
|
||||
cliDescription = "A simple command line client for etcd3."
|
||||
|
||||
defaultDialTimeout = 2 * time.Second
|
||||
@ -40,7 +40,7 @@ var (
|
||||
rootCmd = &cobra.Command{
|
||||
Use: cliName,
|
||||
Short: cliDescription,
|
||||
SuggestFor: []string{"etcctlv3", "etcdcltv3", "etlctlv3"},
|
||||
SuggestFor: []string{"etcdctl"},
|
||||
}
|
||||
)
|
||||
|
||||
@ -85,7 +85,7 @@ func init() {
|
||||
cobra.EnablePrefixMatching = true
|
||||
}
|
||||
|
||||
func main() {
|
||||
func Start() {
|
||||
rootCmd.SetUsageFunc(usageFunc)
|
||||
|
||||
// Make help just show the usage
|
@ -14,7 +14,7 @@
|
||||
|
||||
// copied from https://github.com/coreos/rkt/blob/master/rkt/help.go
|
||||
|
||||
package main
|
||||
package ctlv3
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2015 CoreOS, Inc.
|
||||
// Copyright 2016 CoreOS, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@ -16,55 +16,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/coreos/etcd/etcdctl/command"
|
||||
"github.com/coreos/etcd/version"
|
||||
"github.com/coreos/etcd/etcdctl/ctlv2"
|
||||
"github.com/coreos/etcd/etcdctl/ctlv3"
|
||||
)
|
||||
|
||||
const (
|
||||
apiEnv = "ETCDCTL_API"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "etcdctl"
|
||||
app.Version = version.Version
|
||||
app.Usage = "A simple command line client for etcd."
|
||||
app.Flags = []cli.Flag{
|
||||
cli.BoolFlag{Name: "debug", Usage: "output cURL commands which can be used to reproduce the request"},
|
||||
cli.BoolFlag{Name: "no-sync", Usage: "don't synchronize cluster information before sending request"},
|
||||
cli.StringFlag{Name: "output, o", Value: "simple", Usage: "output response in the given format (`simple`, `extended` or `json`)"},
|
||||
cli.StringFlag{Name: "discovery-srv, D", Usage: "domain name to query for SRV records describing cluster endpoints"},
|
||||
cli.StringFlag{Name: "peers, C", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
|
||||
cli.StringFlag{Name: "endpoint", Value: "", Usage: "DEPRECATED - \"--endpoints\" should be used instead"},
|
||||
cli.StringFlag{Name: "endpoints", Value: "", Usage: "a comma-delimited list of machine addresses in the cluster (default: \"http://127.0.0.1:2379,http://127.0.0.1:4001\")"},
|
||||
cli.StringFlag{Name: "cert-file", Value: "", Usage: "identify HTTPS client using this SSL certificate file"},
|
||||
cli.StringFlag{Name: "key-file", Value: "", Usage: "identify HTTPS client using this SSL key file"},
|
||||
cli.StringFlag{Name: "ca-file", Value: "", Usage: "verify certificates of HTTPS-enabled servers using this CA bundle"},
|
||||
cli.StringFlag{Name: "username, u", Value: "", Usage: "provide username[:password] and prompt if password is not supplied."},
|
||||
cli.DurationFlag{Name: "timeout", Value: time.Second, Usage: "connection timeout per request"},
|
||||
cli.DurationFlag{Name: "total-timeout", Value: 5 * time.Second, Usage: "timeout for the command execution (except watch)"},
|
||||
}
|
||||
app.Commands = []cli.Command{
|
||||
command.NewBackupCommand(),
|
||||
command.NewClusterHealthCommand(),
|
||||
command.NewMakeCommand(),
|
||||
command.NewMakeDirCommand(),
|
||||
command.NewRemoveCommand(),
|
||||
command.NewRemoveDirCommand(),
|
||||
command.NewGetCommand(),
|
||||
command.NewLsCommand(),
|
||||
command.NewSetCommand(),
|
||||
command.NewSetDirCommand(),
|
||||
command.NewUpdateCommand(),
|
||||
command.NewUpdateDirCommand(),
|
||||
command.NewWatchCommand(),
|
||||
command.NewExecWatchCommand(),
|
||||
command.NewMemberCommand(),
|
||||
command.NewImportSnapCommand(),
|
||||
command.NewUserCommands(),
|
||||
command.NewRoleCommands(),
|
||||
command.NewAuthCommands(),
|
||||
apiv := os.Getenv(apiEnv)
|
||||
// unset apiEnv to avoid side-effect for future env and flag parsing.
|
||||
os.Unsetenv(apiv)
|
||||
if len(apiv) == 0 || apiv == "2" {
|
||||
ctlv2.Start()
|
||||
return
|
||||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
if apiv == "3" {
|
||||
ctlv3.Start()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, "unsupported API version", apiv)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
1
etcdctlv3/.gitignore
vendored
1
etcdctlv3/.gitignore
vendored
@ -1 +0,0 @@
|
||||
etcdctlv3
|
2
test
2
test
@ -17,7 +17,7 @@ GO_BUILD_FLAGS=-a
|
||||
source ./build
|
||||
|
||||
# Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
|
||||
TESTABLE_AND_FORMATTABLE="client clientv3 discovery error etcdctl/command etcdmain etcdserver etcdserver/auth etcdserver/etcdhttp etcdserver/etcdhttp/httptypes pkg/fileutil pkg/flags pkg/idutil pkg/ioutil pkg/netutil pkg/osutil pkg/pbutil pkg/types pkg/transport pkg/wait proxy raft snap storage storage/backend store version wal"
|
||||
TESTABLE_AND_FORMATTABLE="client clientv3 discovery error etcdctl/ctlv2 etcdctl/ctlv3 etcdmain etcdserver etcdserver/auth etcdserver/etcdhttp etcdserver/etcdhttp/httptypes pkg/fileutil pkg/flags pkg/idutil pkg/ioutil pkg/netutil pkg/osutil pkg/pbutil pkg/types pkg/transport pkg/wait proxy raft snap storage storage/backend store version wal"
|
||||
# TODO: add it to race testing when the issue is resolved
|
||||
# https://github.com/golang/go/issues/9946
|
||||
NO_RACE_TESTABLE="rafthttp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user