Skip to content

Commit

Permalink
Merge branch 'master' into feat/cb-cluster-via-cao
Browse files Browse the repository at this point in the history
  • Loading branch information
boseabhishek committed Jan 4, 2024
2 parents 1b2384e + 2e98889 commit 8d7bb78
Show file tree
Hide file tree
Showing 21 changed files with 395 additions and 58 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,26 @@ jobs:
./cbdinocluster-linux init --auto
- name: Setup Cluster
run: |
CBDC_ID=$(./cbdinocluster-linux allocate simple:7.0.0)
CBDC_ID=$(./cbdinocluster-linux -v allocate simple:7.0.0)
echo "CBDC_ID=$CBDC_ID" >> "$GITHUB_ENV"
- name: Run Tests
timeout-minutes: 10
run: |
./cbdinocluster-linux connstr $CBDC_ID
CBDC_MGMT=$(./cbdinocluster-linux mgmt $CBDC_ID)
# validate getting the connection string
./cbdinocluster-linux -v connstr $CBDC_ID
# validate getting management addresses
CBDC_MGMT=$(./cbdinocluster-linux -v mgmt $CBDC_ID)
echo $CBDC_MGMT
# validate cluster is accessible
curl $CBDC_MGMT
# pick a random node to mess with
NODE_IP=$(./cbdinocluster-linux -v ip $CBDC_ID)
# validate blocking traffic to the node
./cbdinocluster-linux -v chaos block-traffic $CBDC_ID $NODE_IP
# validate we can still access that node
curl http://$NODE_IP:8091
# ensure we can unblock traffic
./cbdinocluster-linux -v chaos allow-traffic $CBDC_ID $NODE_IP
- name: Cleanup Cluster
if: always()
run: |
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/data/
/cbdynclusterd
cleanup_registry/.venv
/cbdinocluster*
cleanup_registry/.venv
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,50 @@ environments.
./cbdinocluster rm {{CLUSTER_ID}}
```

#### Create a bucket named `default`

```
./cbdinocluster buckets add {{CLUSTER_ID}} default --ram-quota-mb=100 --flush-enabled=true
```

#### Create a collection in the default scope on the bucket named `default`

```
./cbdinocluster collections add {{CLUSTER_ID}} default _default test
```

#### Using prefixes to match cluster and container IDs

To avoid constantly copying and pasting IDs in terminal, it is recommended to use only unique prefix.

```
~ $ cbdinocluster ps
...
Clusters:
4f9e6625-6f48-4866-bab9-076ae5f57052 [State: ready, Timeout: none, Deployer: docker]
a20294bf-44fc-4a6f-b019-a005d2fbf16b 192.168.107.130 af3dcbd5...
86da5182-9f3c-450e-8b69-1c65fc646f7b 192.168.107.128 b6b7ab97...
51024e57-660d-497d-8878-42ca7781ab4c 192.168.107.129 2ca9e448...
```

Note that the we have only one cluster, and its ID starts with `4`, so it is enough to refert to the cluster with
cbdinocluster commands.

```
~ $ cbdinocluster connstr 4
...
couchbase://192.168.107.130,192.168.107.128,192.168.107.129
```

The same work with docker itself (first node ID starts with `a`):

```
~ $ docker exec -ti a /usr/bin/bash
root@af3dcbd5b2a4:/# ps aux | grep memcached
couchba+ 384 0.0 0.4 1762336 27268 ? SLsl 20:39 0:00 /opt/couchbase/bin/memcached -C /opt/couchbase/var/lib/couchbase/config/memcached.json
root 664 0.0 0.0 2976 1536 pts/0 S+ 20:49 0:00 grep --color=auto memcached
```

### Advanced Usage

#### Resetting Colima
Expand Down
1 change: 1 addition & 0 deletions clusterdef/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type NodeGroup struct {
}

type DockerNodeGroup struct {
EnvVars map[string]string `yaml:"env,omitempty"`
}

type CloudNodeGroup struct {
Expand Down
6 changes: 6 additions & 0 deletions cmd/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var allocateCmd = &cobra.Command{
ctx := helper.GetContext()
config := helper.GetConfig(ctx)

dryRun, _ := cmd.Flags().GetBool("dry-run")
defStr, _ := cmd.Flags().GetString("def")
defFile, _ := cmd.Flags().GetString("def-file")
purpose, _ := cmd.Flags().GetString("purpose")
Expand Down Expand Up @@ -107,6 +108,10 @@ var allocateCmd = &cobra.Command{

logger.Info("deploying definition", zap.Any("def", def))

if dryRun {
return
}

var deployer deployment.Deployer
if def.Deployer == "" {
deployer = helper.GetDefaultDeployer(ctx)
Expand Down Expand Up @@ -134,6 +139,7 @@ var allocateCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(allocateCmd)

allocateCmd.Flags().Bool("dry-run", false, "Disables the actual allocate and simply does a dry-run.")
allocateCmd.Flags().String("def", "", "The cluster definition you wish to provision.")
allocateCmd.Flags().String("def-file", "", "The path to a file containing a cluster definition to provision.")
allocateCmd.Flags().String("purpose", "", "The purpose for allocating this cluster")
Expand Down
2 changes: 1 addition & 1 deletion cmd/chaos-allowtraffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

var chaosAllowTrafficCmd = &cobra.Command{
Use: "allow-traffic",
Short: "Allows inter-node traffic to a specific node",
Short: "Allows all traffic to a specific node",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
helper := CmdHelper{}
Expand Down
22 changes: 19 additions & 3 deletions cmd/chaos-blocktraffic.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cmd

import (
"github.com/couchbaselabs/cbdinocluster/deployment"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var chaosBlockTrafficCmd = &cobra.Command{
Use: "block-traffic",
Short: "Blocks inter-node traffic to a specific node",
Use: "block-traffic [nodes/clients/all]",
Short: "Blocks a type of traffic to a specific node",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
helper := CmdHelper{}
Expand All @@ -17,7 +18,22 @@ var chaosBlockTrafficCmd = &cobra.Command{
_, deployer, cluster := helper.IdentifyCluster(ctx, args[0])
node := helper.IdentifyNode(ctx, cluster, args[1])

err := deployer.BlockNodeTraffic(ctx, cluster.GetID(), node.GetID())
blockType := deployment.BlockNodeTrafficNodes
if len(args) > 2 {
switch args[2] {
case "nodes":
blockType = deployment.BlockNodeTrafficNodes
case "clients":
blockType = deployment.BlockNodeTrafficClients
case "all":
blockType = deployment.BlockNodeTrafficAll
default:
logger.Fatal("unexpected traffic type",
zap.String("type", args[2]))
}
}

err := deployer.BlockNodeTraffic(ctx, cluster.GetID(), node.GetID(), blockType)
if err != nil {
logger.Fatal("failed to block node traffic", zap.Error(err))
}
Expand Down
29 changes: 29 additions & 0 deletions cmd/chaos-pausenode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var chaosPauseNodeCmd = &cobra.Command{
Use: "pause-node",
Short: "Pauses a particular node in the cluster.",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
helper := CmdHelper{}
logger := helper.GetLogger()
ctx := helper.GetContext()

_, deployer, cluster := helper.IdentifyCluster(ctx, args[0])
node := helper.IdentifyNode(ctx, cluster, args[1])

err := deployer.PauseNode(ctx, cluster.GetID(), node.GetID())
if err != nil {
logger.Fatal("failed to pause node", zap.Error(err))
}
},
}

func init() {
chaosCmd.AddCommand(chaosPauseNodeCmd)
}
29 changes: 29 additions & 0 deletions cmd/chaos-unpausenode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var chaosUnpauseNodeCmd = &cobra.Command{
Use: "unpause-node",
Short: "Unpauses a particular node in the cluster.",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
helper := CmdHelper{}
logger := helper.GetLogger()
ctx := helper.GetContext()

_, deployer, cluster := helper.IdentifyCluster(ctx, args[0])
node := helper.IdentifyNode(ctx, cluster, args[1])

err := deployer.UnpauseNode(ctx, cluster.GetID(), node.GetID())
if err != nil {
logger.Fatal("failed to resume node", zap.Error(err))
}
},
}

func init() {
chaosCmd.AddCommand(chaosUnpauseNodeCmd)
}
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ var initCmd = &cobra.Command{
}
}
if dockerNetwork == "" {
dockerNetwork = "default"
dockerNetwork = "bridge"
}

dockerNetwork = readString(
Expand Down
33 changes: 33 additions & 0 deletions cmd/ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"fmt"

"github.com/couchbaselabs/cbdinocluster/deployment"
"github.com/spf13/cobra"
)

var ipCmd = &cobra.Command{
Use: "ip [flags] cluster [node]",
Short: "Gets the IP of a node in the cluster",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
helper := CmdHelper{}
ctx := helper.GetContext()

_, _, cluster := helper.IdentifyCluster(ctx, args[0])

var node deployment.ClusterNodeInfo
if len(args) >= 2 {
node = helper.IdentifyNode(ctx, cluster, args[1])
} else {
node = cluster.GetNodes()[0]
}

fmt.Printf("%s\n", node.GetIPAddress())
},
}

func init() {
rootCmd.AddCommand(ipCmd)
}
8 changes: 1 addition & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import (
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "cbdinocluster",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Short: "provides tooling for quickly creating, modifying and destroying couchbase clusters.",
}

func Execute() {
Expand Down
12 changes: 11 additions & 1 deletion deployment/caodeploy/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,23 @@ func NewDeployer(opts *NewDeployerOptions) (*Deployer, error) {
}, nil
}

// PauseNode implements deployment.Deployer.
func (*Deployer) PauseNode(ctx context.Context, clusterID string, nodeID string) error {
return errors.New("caodeploy does not support pausing node")
}

// UnpauseNode implements deployment.Deployer.
func (*Deployer) UnpauseNode(ctx context.Context, clusterID string, nodeID string) error {
return errors.New("caodeploy does not support unpausing node")
}

// AllowNodeTraffic implements deployment.Deployer.
func (*Deployer) AllowNodeTraffic(ctx context.Context, clusterID string, nodeID string) error {
return errors.New("caodeploy does not support allowing node traffic")
}

// BlockNodeTraffic implements deployment.Deployer.
func (*Deployer) BlockNodeTraffic(ctx context.Context, clusterID string, nodeID string) error {
func (*Deployer) BlockNodeTraffic(ctx context.Context, clusterID string, nodeID string, blockType deployment.BlockNodeTrafficType) error {
return errors.New("caodeploy does not support blocking node traffic")
}

Expand Down
10 changes: 9 additions & 1 deletion deployment/clouddeploy/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ func (d *Deployer) DeleteCollection(ctx context.Context, clusterID string, bucke
return errors.New("clouddeploy does not support deleting collections")
}

func (d *Deployer) BlockNodeTraffic(ctx context.Context, clusterID string, nodeID string) error {
func (d *Deployer) BlockNodeTraffic(ctx context.Context, clusterID string, nodeID string, blockType deployment.BlockNodeTrafficType) error {
return errors.New("clouddeploy does not support traffic control")
}

Expand All @@ -1160,3 +1160,11 @@ func (d *Deployer) ListImages(ctx context.Context) ([]deployment.Image, error) {
func (d *Deployer) SearchImages(ctx context.Context, version string) ([]deployment.Image, error) {
return nil, errors.New("clouddeploy does not support image search")
}

func (d *Deployer) PauseNode(ctx context.Context, clusterID string, nodeID string) error {
return errors.New("clouddeploy does not support node pausing")
}

func (d *Deployer) UnpauseNode(ctx context.Context, clusterID string, nodeID string) error {
return errors.New("clouddeploy does not support node pausing")
}
12 changes: 11 additions & 1 deletion deployment/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ type Image struct {
Name string
}

type BlockNodeTrafficType string

const (
BlockNodeTrafficClients BlockNodeTrafficType = "clients"
BlockNodeTrafficNodes BlockNodeTrafficType = "nodes"
BlockNodeTrafficAll BlockNodeTrafficType = "all"
)

type Deployer interface {
ListClusters(ctx context.Context) ([]ClusterInfo, error)
NewCluster(ctx context.Context, def *clusterdef.Cluster) (ClusterInfo, error)
Expand All @@ -87,9 +95,11 @@ type Deployer interface {
CreateCollection(ctx context.Context, clusterID string, bucketName, scopeName, collectionName string) error
DeleteScope(ctx context.Context, clusterID string, bucketName, scopeName string) error
DeleteCollection(ctx context.Context, clusterID string, bucketName, scopeName, collectionName string) error
BlockNodeTraffic(ctx context.Context, clusterID string, nodeID string) error
BlockNodeTraffic(ctx context.Context, clusterID string, nodeID string, blockType BlockNodeTrafficType) error
AllowNodeTraffic(ctx context.Context, clusterID string, nodeID string) error
CollectLogs(ctx context.Context, clusterID string, destPath string) ([]string, error)
ListImages(ctx context.Context) ([]Image, error)
SearchImages(ctx context.Context, version string) ([]Image, error)
PauseNode(ctx context.Context, clusterID string, nodeID string) error
UnpauseNode(ctx context.Context, clusterID string, nodeID string) error
}
Loading

0 comments on commit 8d7bb78

Please sign in to comment.