Skip to content

Commit

Permalink
*: combine etcdctl and etcdctlv3
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Mar 28, 2016
1 parent 83ada72 commit 87d9f06
Show file tree
Hide file tree
Showing 57 changed files with 107 additions and 66 deletions.
1 change: 0 additions & 1 deletion V3DemoProcfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 5 additions & 9 deletions e2e/etcdctlv3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package e2e

import (
"os"
"strings"
"testing"
"time"

"github.com/coreos/etcd/pkg/fileutil"
"github.com/coreos/etcd/pkg/testutil"
)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion etcdctlv3/README.md → etcdctl/READMEv3.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
etcdctl
========

TODO: merge into README.md.

## Commands

### PUT [options] \<key\> \<value\>
Expand Down Expand Up @@ -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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions etcdctl/ctlv2/ctl.go
Original file line number Diff line number Diff line change
@@ -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)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions etcdctlv3/main.go → etcdctl/ctlv3/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +40,7 @@ var (
rootCmd = &cobra.Command{
Use: cliName,
Short: cliDescription,
SuggestFor: []string{"etcctlv3", "etcdcltv3", "etlctlv3"},
SuggestFor: []string{"etcdctl"},
}
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func init() {
cobra.EnablePrefixMatching = true
}

func main() {
func Start() {
rootCmd.SetUsageFunc(usageFunc)

// Make help just show the usage
Expand Down
2 changes: 1 addition & 1 deletion etcdctlv3/help.go → etcdctl/ctlv3/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// copied from https://github.com/coreos/rkt/blob/master/rkt/help.go

package main
package ctlv3

import (
"bytes"
Expand Down
File renamed without changes.
64 changes: 20 additions & 44 deletions etcdctl/main.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)"},
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.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(),

if apiv == "3" {
ctlv3.Start()
return
}

app.Run(os.Args)
fmt.Fprintln(os.Stderr, "unsupported API version", apiv)
os.Exit(1)
}
1 change: 0 additions & 1 deletion etcdctlv3/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion test
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 87d9f06

Please sign in to comment.