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

[feat]curveadm: add export cmd for export the yaml that tools-v2 used #344

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b84a1c5
update: wrong word spelling
chengyu-l Apr 23, 2023
53f547c
Merge pull request #211 from chengyu-l/patch-1
zhanghuidinah Apr 26, 2023
c561337
Update topology.yaml
ilixiaocui May 4, 2023
cd641e3
Improve(clean): use install instead scp to sync recycle script.
Wine93 Apr 14, 2023
8221c3b
Bugfix(format): make mountpoint directories with wrong mode.
Wine93 Apr 14, 2023
a558356
Release v0.2.1
Wine93 Apr 14, 2023
abcbae2
Fix(map): report warning when both --format and --quiet are set for d…
Wine93 Jun 14, 2023
c38bed6
Revert "Bugfix(format): make mountpoint directories with wrong mode."
Wine93 Jun 15, 2023
8068f79
Fix(format): use blkid instead lsblk to get block device uuid.
Wine93 Jun 15, 2023
b236900
Improve: use embed module to embedded static shell scripts.
Wine93 Apr 17, 2023
377d0a0
Fix(support): download file failed by ssh when remote path is same as…
Wine93 Apr 17, 2023
fa83dc4
Fix(deploy): wait all chunkserver online time (#114).
Wine93 Jun 15, 2023
d7fb66e
Fix: remove deprecated ioutil.
fengshunli May 19, 2023
1fa2e98
Makefile: add golangci-lint.
fengshunli May 17, 2023
2b8e010
Feature: now we support execute the version 2 tools in service contai…
Cyber-SiKu Feb 28, 2023
1cf0a96
Feature(deploy): now we support deploy curvebs cluster by specified p…
Wine93 Jun 16, 2023
5756146
Fix(mount): path already mounted.
Wine93 Jun 16, 2023
e2f7782
Feature: now we support the rqlite which is distributed database as c…
Wine93 Jun 8, 2023
ba312cf
Improve(format): set reserved blocks percentage to 0 for device.
Wine93 Jun 16, 2023
3ded5dd
Feature(hosts): support setting variable for ssh user.
Wine93 Jun 16, 2023
b72801d
Fix(format): report warning when both --format and --quiet are set fo…
Wine93 Jun 19, 2023
aceec47
Fix(format): tune2fs not works due to the wrong command option.
Wine93 Jun 19, 2023
407973e
Fix: report warning when both --format and --quiet are set for docker…
Wine93 Jun 27, 2023
1962037
Fix: updated usage example.
montaguelhz Jun 25, 2023
125a0b0
Fix(format): use short option for blkid command.
Wine93 Jun 27, 2023
0ec624b
Improve(map): skip create volume task if create option not specified.
Wine93 Jul 3, 2023
590d10c
Bugfix: missing whitespace for config delimiter of tools v2.
Wine93 Jul 5, 2023
2940780
Feature(cluster): support import a cluster from sqlite database file.
Wine93 Jul 5, 2023
9430af0
Feature(format): support fomat with blocksize and chunksize.
wu-hanqing Jun 19, 2023
5b0cd13
Fix(map): wrong checker for create option.
Wine93 Jul 12, 2023
18394ff
Fix(map): create volume failed due to the problematic script.
Wine93 Jul 12, 2023
18841dd
Improve(client/status): added poolset aux info for curvebs volume.
Wine93 Jul 12, 2023
0b403f8
Fix(clean): execute recycle script failed.
Wine93 Jul 14, 2023
929c35e
Improve(client/status): show client config in verbose mode.
Wine93 Jul 18, 2023
1098a7f
Fix(deploy): fix deploy curvefs panic due to poolset is nil (#280).
Wine93 Aug 9, 2023
4b65b90
Improve(client/status): display statuses even if get status failed fo…
Wine93 Aug 17, 2023
06f0b00
Fix(deploy): fix set environment variables failed by ssh (#239).
Wine93 Aug 30, 2023
bc66ce1
playbook(logs): add rotate script which can rotate service logs.
Wine93 Sep 7, 2023
44987ee
Fix(precheck): fix get wrong external ip.
caoxianfei1 Nov 17, 2023
0138432
Fix(playground): replace image repo.
Cyber-SiKu Jun 21, 2023
1c09d35
Fix(precheck): support recognize kernel version like "3.15.0_.*".
jyf111 Aug 30, 2023
59bbb91
Fix: adjust const variables position.
Songjf-ttk Aug 30, 2023
e05a7e3
Improve(config): using more meaningful name for service instances.
tiansuo114 Aug 27, 2023
e771538
Improve(precheck): run ss command in container.
jyf111 Aug 19, 2023
f9830eb
playbook(memcache): support sudo alias.
Cyber-SiKu Feb 22, 2023
b86b5a6
Feature(deploy): support etcd authentication.
Wine93 Nov 22, 2023
11064cd
Improve: add commit id in version information.
Wine93 Nov 22, 2023
f39dbcd
Feature: podman can be an alternative container engine.
caoxianfei1 Aug 10, 2023
49e1d41
Improve(format): support specify the number of concurrent for formatt…
Wine93 Nov 22, 2023
2cf7c66
template: updated container image.
Wine93 Nov 22, 2023
f8de164
Feature(monitor): now we support deploy monitor.
SeanHai Apr 26, 2023
e92745d
Fix(migrate): fixed migration panic.
Songjf-ttk Sep 18, 2023
2728b7d
Release v0.3.0
Wine93 Nov 22, 2023
003ad85
fix/(curveadm-deploy): create pool need calc chunkservers
caoxianfei1 Nov 23, 2023
534e2cc
Fix(curveadm deploy): newer version ss answers invalid arument
caoxianfei1 Nov 22, 2023
580b26d
[FIX]: make build error with musl1.2.4
zztaki Nov 23, 2023
9d83a9c
Fix (target start): curveadm target start timeout
zztaki Nov 24, 2023
f243ad6
docs: Quickly start developing curves based on cobra
hdbdn77 Nov 27, 2023
828680a
Feature(cluster add): add deploy type parameter
WhereAreBugs Dec 7, 2023
e362387
Fix(typo): fix an spelling mistake in code.
WhereAreBugs Dec 7, 2023
a58f65a
add export cmd for export the yaml that tools-v2 used
youarefree123 Dec 9, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ logs/*
.build/
.vscode/
.CHANGELOG
vendor/
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
.PHONY: build debug test tar
.PHONY: build debug install test upload lint

# go env
GOPROXY := "https://goproxy.cn,direct"
GOOS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
GOARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
CGO_LDFLAGS := "-static"
CGO_CFLAGS := "-D_LARGEFILE64_SOURCE"
CC := musl-gcc

GOENV := GO111MODULE=on
GOENV += GOPROXY=$(GOPROXY)
GOENV += CC=$(CC)
GOENV += CGO_ENABLED=1 CGO_LDFLAGS=$(CGO_LDFLAGS)
GOENV += CGO_ENABLED=1 CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_CFLAGS=$(CGO_CFLAGS)
GOENV += GOOS=$(GOOS) GOARCH=$(GOARCH)

GOLANGCILINT_VERSION ?= v1.50.0
GOBIN := $(shell go env GOPATH)/bin
GOBIN_GOLANGCILINT := $(shell which $(GOBIN)/golangci-lint)
# go
GO := go

Expand All @@ -22,6 +25,7 @@ OUTPUT := bin/curveadm
# build flags
LDFLAGS := -s -w
LDFLAGS += -extldflags "-static -fpic"
LDFLAGS += -X github.com/opencurve/curveadm/cli/cli.CommitId=$(shell git rev-parse --short HEAD)

BUILD_FLAGS := -a
BUILD_FLAGS += -trimpath
Expand Down Expand Up @@ -58,8 +62,16 @@ build:
debug:
$(GOENV) $(GO) build -o $(OUTPUT) $(DEBUG_FLAGS) $(PACKAGES)

install:
cp bin/curveadm ~/.curveadm/bin

test:
$(GO_TEST) $(TEST_FLAGS) ./...

upload:
@NOSCMD=$(NOSCMD) bash build/package/upload.sh $(VERSION)

lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
$(GOBIN_GOLANGCILINT) run -v

25 changes: 18 additions & 7 deletions cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type CurveAdm struct {
pluginDir string
logDir string
tempDir string
dbpath string
logpath string
config *configure.CurveAdmConfig

Expand All @@ -70,6 +69,8 @@ type CurveAdm struct {
clusterName string // current cluster name
clusterTopologyData string // cluster topology
clusterPoolData string // cluster pool
clusterType string // cluster type like develop, production, etc.
monitor storage.Monitor
}

/*
Expand Down Expand Up @@ -142,9 +143,9 @@ func (curveadm *CurveAdm) init() error {
// (4) Init error code
errno.Init(logpath)

// (5) New storage: create table in sqlite
dbpath := fmt.Sprintf("%s/curveadm.db", curveadm.dataDir)
s, err := storage.NewStorage(dbpath)
// (5) New storage: create table in sqlite/rqlite
dbUrl := config.GetDBUrl()
s, err := storage.NewStorage(dbUrl)
if err != nil {
log.Error("Init SQLite database failed",
log.Field("Error", err))
Expand Down Expand Up @@ -174,7 +175,13 @@ func (curveadm *CurveAdm) init() error {
log.Field("ClusterName", cluster.Name))
}

curveadm.dbpath = dbpath
// (8) Get monitor configure
monitor, err := s.GetMonitor(cluster.Id)
if err != nil {
log.Error("Get monitor failed", log.Field("Error", err))
return errno.ERR_GET_MONITOR_FAILED.E(err)
}

curveadm.logpath = logpath
curveadm.config = config
curveadm.in = os.Stdin
Expand All @@ -188,7 +195,8 @@ func (curveadm *CurveAdm) init() error {
curveadm.clusterName = cluster.Name
curveadm.clusterTopologyData = cluster.Topology
curveadm.clusterPoolData = cluster.Pool

curveadm.monitor = monitor
curveadm.clusterType = cluster.Type
return nil
}

Expand Down Expand Up @@ -253,11 +261,11 @@ func (curveadm *CurveAdm) DataDir() string { return curveadm.d
func (curveadm *CurveAdm) PluginDir() string { return curveadm.pluginDir }
func (curveadm *CurveAdm) LogDir() string { return curveadm.logDir }
func (curveadm *CurveAdm) TempDir() string { return curveadm.tempDir }
func (curveadm *CurveAdm) DBPath() string { return curveadm.dbpath }
func (curveadm *CurveAdm) LogPath() string { return curveadm.logpath }
func (curveadm *CurveAdm) Config() *configure.CurveAdmConfig { return curveadm.config }
func (curveadm *CurveAdm) SudoAlias() string { return curveadm.config.GetSudoAlias() }
func (curveadm *CurveAdm) SSHTimeout() int { return curveadm.config.GetSSHTimeout() }
func (curveadm *CurveAdm) Engine() string { return curveadm.config.GetEngine() }
func (curveadm *CurveAdm) In() io.Reader { return curveadm.in }
func (curveadm *CurveAdm) Out() io.Writer { return curveadm.out }
func (curveadm *CurveAdm) Err() io.Writer { return curveadm.err }
Expand All @@ -269,6 +277,8 @@ func (curveadm *CurveAdm) ClusterUUId() string { return curveadm.c
func (curveadm *CurveAdm) ClusterName() string { return curveadm.clusterName }
func (curveadm *CurveAdm) ClusterTopologyData() string { return curveadm.clusterTopologyData }
func (curveadm *CurveAdm) ClusterPoolData() string { return curveadm.clusterPoolData }
func (curveadm *CurveAdm) ClusterType() string { return curveadm.clusterType }
func (curveadm *CurveAdm) Monitor() storage.Monitor { return curveadm.monitor }

func (curveadm *CurveAdm) GetHost(host string) (*hosts.HostConfig, error) {
if len(curveadm.Hosts()) == 0 {
Expand Down Expand Up @@ -377,6 +387,7 @@ func (curveadm *CurveAdm) ExecOptions() module.ExecOptions {
ExecInLocal: false,
ExecSudoAlias: curveadm.config.GetSudoAlias(),
ExecTimeoutSec: curveadm.config.GetTimeout(),
ExecWithEngine: curveadm.config.GetEngine(),
}
}

Expand Down
4 changes: 3 additions & 1 deletion cli/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@
package cli

var (
Version = "0.2.0"
Version = "0.3.0"

CommitId = "unknown"
)
12 changes: 8 additions & 4 deletions cli/command/client/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
package client

import (
"github.com/dustin/go-humanize"
"strconv"
"strings"

"github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
Expand All @@ -41,9 +41,10 @@ import (

const (
MAP_EXAMPLE = `Examples:
$ curveadm map user:/volume --host machine1 --create # Map volume which created by automatic
$ curveadm map user:/volume --host machine1 --size=10GB --create # Map volume which size is 10GB and created by automatic
$ curveadm map user:/volume --host machine1 -c /path/to/client.yaml # Map volume with specified configure file`
$ curveadm map user:/volume --host machine1 --create # Map volume which created by automatic
$ curveadm map user:/volume --host machine1 --size=10GiB --create # Map volume which size is 10GiB and created by automatic
$ curveadm map user:/volume --host machine1 --create --poolset ssd # Map volume created by automatic in poolset 'ssd'
$ curveadm map user:/volume --host machine1 -c /path/to/client.yaml # Map volume with specified configure file`
)

var (
Expand All @@ -64,6 +65,7 @@ type mapOptions struct {
create bool
filename string
noExclusive bool
poolset string
}

func ParseImage(image string) (user, name string, err error) {
Expand Down Expand Up @@ -159,6 +161,7 @@ func NewMapCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.BoolVar(&options.noExclusive, "no-exclusive", false, "Map volume non exclusive")
flags.StringVar(&options.size, "size", "10GiB", "Specify volume size")
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")
flags.StringVar(&options.poolset, "poolset", "default", "Specify the poolset name")
return cmd
}

Expand All @@ -181,6 +184,7 @@ func genMapPlaybook(curveadm *cli.CurveAdm,
Size: size,
Create: options.create,
NoExclusive: options.noExclusive,
Poolset: options.poolset,
},
comm.KEY_CLIENT_HOST: options.host, // for checker
comm.KEY_CHECK_KERNEL_MODULE_NAME: comm.KERNERL_MODULE_NBD,
Expand Down
17 changes: 12 additions & 5 deletions cli/command/client/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

var (
GET_STATUS_PLAYBOOK_STEPS = []int{
playbook.INIT_CLIENT_STATUS,
playbook.GET_CLIENT_STATUS,
}
)
Expand All @@ -57,6 +58,9 @@ func NewStatusCommand(curveadm *cli.CurveAdm) *cobra.Command {
DisableFlagsInUseLine: true,
}

flags := cmd.Flags()
flags.BoolVarP(&options.verbose, "verbose", "v", false, "Verbose output for status")

return cmd
}

Expand All @@ -74,8 +78,13 @@ func genStatusPlaybook(curveadm *cli.CurveAdm,
pb.AddStep(&playbook.PlaybookStep{
Type: step,
Configs: config,
Options: map[string]interface{}{
comm.KEY_CLIENT_STATUS_VERBOSE: options.verbose,
},
ExecOptions: playbook.ExecOptions{
SilentSubBar: true,
SilentSubBar: true,
SilentMainBar: step == playbook.INIT_CLIENT_STATUS,
SkipError: true,
},
})
}
Expand Down Expand Up @@ -113,11 +122,9 @@ func runStatus(curveadm *cli.CurveAdm, options statusOptions) error {
}

// 3) run playground
if err = pb.Run(); err != nil {
return err
}
err = pb.Run()

// 4) display service status
displayStatus(curveadm, clients, options)
return nil
return err
}
32 changes: 28 additions & 4 deletions cli/command/cluster/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package cluster

import (
"github.com/google/uuid"
"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
"github.com/opencurve/curveadm/internal/configure/topology"
Expand All @@ -46,12 +47,18 @@ var (
CHECK_TOPOLOGY_PLAYBOOK_STEPS = []int{
playbook.CHECK_TOPOLOGY,
}
SUPPORTED_DEPLOY_TYPES = []string{
"production",
"test",
"develop",
}
)

type addOptions struct {
name string
descriotion string
description string
filename string
deployType string
}

func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -62,6 +69,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
Short: "Add cluster",
Args: utils.ExactArgs(1),
Example: ADD_EXAMPLE,
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkAddOptions(cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
options.name = args[0]
return runAdd(curveadm, options)
Expand All @@ -70,9 +80,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVarP(&options.descriotion, "description", "m", "", "Description for cluster")
flags.StringVarP(&options.description, "description", "m", "", "Description for cluster")
flags.StringVarP(&options.filename, "topology", "f", "", "Specify the path of topology file")

flags.StringVar(&options.deployType, "type", "develop", "Specify the type of cluster")
return cmd
}

Expand Down Expand Up @@ -133,6 +143,19 @@ func checkTopology(curveadm *cli.CurveAdm, data string, options addOptions) erro
return pb.Run()
}

func checkAddOptions(cmd *cobra.Command) error {
deployType, err := cmd.Flags().GetString("deploy-type")
if err != nil {
return err
}
for _, t := range SUPPORTED_DEPLOY_TYPES {
if deployType == t {
return nil
}
}
return errno.ERR_UNSUPPORT_DEPLOY_TYPE.F("deploy type: %s", deployType)
}

func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
// 1) check wether cluster already exist
name := options.name
Expand Down Expand Up @@ -161,7 +184,8 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
}

// 4) insert cluster (with topology) into database
err = storage.InsertCluster(name, options.descriotion, data)
uuid := uuid.NewString()
err = storage.InsertCluster(name, uuid, options.description, data, options.deployType)
if err != nil {
return errno.ERR_INSERT_CLUSTER_FAILED.E(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func NewClusterCommand(curveadm *cli.CurveAdm) *cobra.Command {
NewCheckoutCommand(curveadm),
NewListCommand(curveadm),
NewRemoveCommand(curveadm),
// TODO(P1): enable export and import
// TODO(P1): enable export
//NewExportCommand(curveadm),
//NewImportCommand(curveadm),
NewImportCommand(curveadm),
)
return cmd
}
Loading