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

refactor: change cli style, use 'gtctl cluster [create|get|list|delete|scale]' #26

Merged
merged 1 commit into from
Nov 11, 2022
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
- name: Test basic operations of gtctl
run: |
cd bin
./gtctl create cluster mydb -n default
./gtctl get cluster mydb -n default
./gtctl get clusters
./gtctl delete cluster mydb -n default --tear-down-etcd
./gtctl cluster create mydb -n default --timeout 180
./gtctl cluster get mydb -n default
./gtctl cluster list
./gtctl cluster delete mydb -n default --tear-down-etcd

# TODO(zyy17): When the greptimedb is ready, add some SQL tests.
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ gtctl(`g-t-control`) is a command-line tool for managing [GreptimeDB](https://gi
Install your `gtctl` by one line:

```
$ curl -L https://github.com/GreptimeTeam/gtctl/blob/main/hack/install.sh | sh
$ curl -L https://github.com/greptimeteam/gtctl/blob/main/hack/install.sh | sh
```

After downloading, your `gtctl` will in the current directory.

If you want to install the specific version of `gtctl`, you can:

```
$ curl -L https://github.com/GreptimeTeam/gtctl/blob/main/hack/install.sh | sh -s <version>
$ curl -L https://github.com/greptimeteam/gtctl/blob/main/hack/install.sh | sh -s <version>
```

Run `gtctl --hep` to get started:
Expand All @@ -51,12 +51,9 @@ Usage:
gtctl [command]

Available Commands:
cluster Manage GreptimeDB cluster
completion Generate the autocompletion script for the specified shell
create Create GreptimeDB cluster.
delete Delete GreptimeDB cluster.
get Get GreptimeDB cluster.
help Help about any command
scale Scale GreptimeDB cluster.
version Print the version of gtctl and exit

Flags:
Expand All @@ -69,17 +66,17 @@ Use "gtctl [command] --help" for more information about a command.
Create your own GreptimeDB cluster:

```
$ gtctl create cluster mydb -n default
$ gtctl cluster create mydb -n default
```

After creating, the whole GreptimeDB cluster will start in `default` namespace:

```
# Get the cluster.
$ gtctl get cluster mydb -n default
$ gtctl cluster get mydb -n default

# Get all clusters.
$ gtctl get clusters
# List all clusters.
$ gtctl cluster list
```

You can use `kubectl port-forward` command to forward frontend requests:
Expand All @@ -98,18 +95,18 @@ If you want to delete the cluster, you can:

```
# Just delete the cluster.
$ gtctl delete cluster mydb -n default
$ gtctl cluster delete mydb -n default

# Delete GreptimeDB cluster, including etcd cluster.
$ gtctl delete cluster mydb -n default --tear-down-etcd
$ gtctl cluster delete mydb -n default --tear-down-etcd
```

### Dry Run Mode

gtctl provide `--dry-run` option in cluster creation. If the user execute the command with `--dry-run`, gtctl will output the manifests content without applying them:

```
$ gtctl create cluster mydb -n default --dry-run
$ gtctl cluster create mydb -n default --dry-run
```

### Experimental Feature
Expand All @@ -118,10 +115,10 @@ You can use the following commands to scale(or down-scale) your cluster:

```
# Scale datanode to 3 replicas.
$ gtctl scale cluster <your-cluster> -n <your-cluster-namespace> -c datanode --replicas 3
$ gtctl cluster scale <your-cluster> -n <your-cluster-namespace> -c datanode --replicas 3

# Scale frontend to 5 replicas.
$ gtctl scale cluster <your-cluster> -n <your-cluster-namespace> -c frontend --replicas 5
$ gtctl cluster scale <your-cluster> -n <your-cluster-namespace> -c frontend --replicas 5
```


Expand Down
39 changes: 39 additions & 0 deletions cmd/app/cluster/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cluster

import (
"errors"

"github.com/spf13/cobra"

"github.com/GreptimeTeam/gtctl/cmd/app/cluster/create"
"github.com/GreptimeTeam/gtctl/cmd/app/cluster/delete"
"github.com/GreptimeTeam/gtctl/cmd/app/cluster/get"
"github.com/GreptimeTeam/gtctl/cmd/app/cluster/list"
"github.com/GreptimeTeam/gtctl/cmd/app/cluster/scale"
"github.com/GreptimeTeam/gtctl/pkg/log"
)

func NewClusterCommand() *cobra.Command {
cmd := &cobra.Command{
Args: cobra.NoArgs,
Use: "cluster",
Short: "Manage GreptimeDB cluster",
Long: `Manage GreptimeDB cluster in Kubernetes`,
RunE: func(cmd *cobra.Command, args []string) error {
err := cmd.Help()
if err != nil {
return err
}
return errors.New("subcommand is required")
},
}

// TODO(zyy17): Maybe ugly to use NewLogger in every command.
cmd.AddCommand(create.NewCreateClusterCommand(log.NewLogger()))
cmd.AddCommand(delete.NewDeleteClusterCommand(log.NewLogger()))
cmd.AddCommand(scale.NewScaleClusterCommand(log.NewLogger()))
cmd.AddCommand(get.NewGetClusterCommand(log.NewLogger()))
cmd.AddCommand(list.NewListClustersCommand(log.NewLogger()))

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func NewCreateClusterCommand(l log.Logger) *cobra.Command {
var options createClusterCliOptions

cmd := &cobra.Command{
Use: "cluster",
Short: "Create a GreptimeDB cluster.",
Long: `Create a GreptimeDB cluster.`,
Use: "create",
Short: "Create a GreptimeDB cluster",
Long: `Create a GreptimeDB cluster`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("cluster name should be set")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func NewDeleteClusterCommand(l log.Logger) *cobra.Command {
var options deleteClusterCliOptions

cmd := &cobra.Command{
Use: "cluster",
Short: "Delete a GreptimeDB cluster.",
Long: `Delete a GreptimeDB cluster.`,
Use: "delete",
Short: "Delete a GreptimeDB cluster",
Long: `Delete a GreptimeDB cluster`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("cluster name should be set")
Expand Down
6 changes: 3 additions & 3 deletions cmd/app/get/get_cluster.go → cmd/app/cluster/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type getClusterCliOptions struct {
func NewGetClusterCommand(l log.Logger) *cobra.Command {
var options getClusterCliOptions
cmd := &cobra.Command{
Use: "cluster",
Short: "Get a GreptimeDB cluster.",
Long: `Get a GreptimeDB cluster.`,
Use: "get",
Short: "Get GreptimeDB cluster",
Long: `Get GreptimeDB cluster`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("cluster name should be set")
Expand Down
10 changes: 5 additions & 5 deletions cmd/app/get/get_all_clusters.go → cmd/app/cluster/list/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package get
package list

import (
"context"
Expand All @@ -10,11 +10,11 @@ import (
"github.com/GreptimeTeam/gtctl/pkg/manager"
)

func NewGetAllClustersCommand(l log.Logger) *cobra.Command {
func NewListClustersCommand(l log.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "clusters",
Short: "Get all GreptimeDB clusters.",
Long: `Get all GreptimeDB clusters.`,
Use: "list",
Short: "List all GreptimeDB clusters",
Long: `List all GreptimeDB clusters`,
RunE: func(cmd *cobra.Command, args []string) error {
m, err := manager.New(l, false)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/api/errors"

greptimedbv1alpha1 "github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1"
greptimev1alpha1 "github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1"
"github.com/GreptimeTeam/gtctl/pkg/log"
"github.com/GreptimeTeam/gtctl/pkg/manager"
)
Expand All @@ -24,9 +24,9 @@ func NewScaleClusterCommand(l log.Logger) *cobra.Command {
var options scaleCliOptions

cmd := &cobra.Command{
Use: "cluster",
Short: "Scale GreptimeDB cluster.",
Long: `Scale GreptimeDB cluster.`,
Use: "scale",
Short: "Scale GreptimeDB cluster",
Long: `Scale GreptimeDB cluster`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("cluster name should be set")
Expand All @@ -36,8 +36,8 @@ func NewScaleClusterCommand(l log.Logger) *cobra.Command {
return fmt.Errorf("component type is required")
}

if options.ComponentType != string(greptimedbv1alpha1.FrontendComponentKind) &&
options.ComponentType != string(greptimedbv1alpha1.DatanodeComponentKind) {
if options.ComponentType != string(greptimev1alpha1.FrontendComponentKind) &&
options.ComponentType != string(greptimev1alpha1.DatanodeComponentKind) {
return fmt.Errorf("component type is invalid")
}

Expand Down Expand Up @@ -68,12 +68,12 @@ func NewScaleClusterCommand(l log.Logger) *cobra.Command {
}

var oldReplicas int32
if options.ComponentType == string(greptimedbv1alpha1.FrontendComponentKind) {
if options.ComponentType == string(greptimev1alpha1.FrontendComponentKind) {
oldReplicas = cluster.Spec.Frontend.Replicas
cluster.Spec.Frontend.Replicas = options.Replicas
}

if options.ComponentType == string(greptimedbv1alpha1.DatanodeComponentKind) {
if options.ComponentType == string(greptimev1alpha1.DatanodeComponentKind) {
oldReplicas = cluster.Spec.Datanode.Replicas
cluster.Spec.Datanode.Replicas = options.Replicas
}
Expand Down
29 changes: 0 additions & 29 deletions cmd/app/create/create.go

This file was deleted.

29 changes: 0 additions & 29 deletions cmd/app/delete/delete.go

This file was deleted.

30 changes: 0 additions & 30 deletions cmd/app/get/get.go

This file was deleted.

29 changes: 0 additions & 29 deletions cmd/app/scale/scale.go

This file was deleted.

10 changes: 2 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import (

"github.com/spf13/cobra"

"github.com/GreptimeTeam/gtctl/cmd/app/create"
"github.com/GreptimeTeam/gtctl/cmd/app/delete"
"github.com/GreptimeTeam/gtctl/cmd/app/get"
"github.com/GreptimeTeam/gtctl/cmd/app/scale"
"github.com/GreptimeTeam/gtctl/cmd/app/cluster"
"github.com/GreptimeTeam/gtctl/cmd/app/version"
internalversion "github.com/GreptimeTeam/gtctl/pkg/version"
)
Expand All @@ -25,11 +22,8 @@ func NewRootCommand() *cobra.Command {
}

// Add all top level subcommands.
cmd.AddCommand(create.NewCreateCommand())
cmd.AddCommand(version.NewVersionCommand())
cmd.AddCommand(delete.NewDeleteCommand())
cmd.AddCommand(scale.NewScaleCommand())
cmd.AddCommand(get.NewGetCommand())
cmd.AddCommand(cluster.NewClusterCommand())

return cmd
}
Binary file modified docs/images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.