Skip to content

Commit

Permalink
[CLOUDGA-15694] Add support fror RF5/RF7 clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnav15 committed Aug 18, 2023
1 parent a24d02b commit d0b8249
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 23 deletions.
3 changes: 2 additions & 1 deletion cmd/cluster/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func init() {
For GCP:
cloud-provider=GCP,gcp-resource-id=<resource-id>,gcp-service-account-path=<service-account-path>.
If specified, all parameters for that provider are mandatory.`)
createClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] The fault tolerance of the cluster. The possible values are NONE, ZONE and REGION. Default NONE.")
createClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] The fault tolerance domain of the cluster. The possible values are NONE, ZONE and REGION. Default NONE.")
createClusterCmd.Flags().Int32("num-faults-to-tolerate", 0, "[OPTIONAL] The number of domain faults to tolerate for the level specified. The possible values are 0 for NONE, 1 for ZONE and [1-3] for anything else. Defaults to 0 for NONE, 1 otherwise.")
createClusterCmd.Flags().StringToInt("node-config", nil, "[OPTIONAL] Configuration of the cluster nodes. Please provide key value pairs num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If specified, num-cores is mandatory, while disk-size-gb and disk-iops are optional.")
createClusterCmd.Flags().StringArray("region-info", []string{}, `[OPTIONAL] Region information for the cluster. Please provide key value pairs region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name> as the value. If specified, region and num-nodes are mandatory, vpc is optional. Information about multiple regions can be specified by using multiple --region-info arguments. Default if not specified is us-west-2 AWS region.`)

Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func init() {
updateClusterCmd.Flags().StringToInt("node-config", nil, "[OPTIONAL] Configuration of the cluster nodes. Please provide key value pairs num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If provided, num-cores is mandatory, while disk-size-gb and disk-iops are optional.")
updateClusterCmd.Flags().StringArray("region-info", []string{}, `[OPTIONAL] Region information for the cluster. Please provide key value pairs, region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name> as the value. If provided, region and num-nodes are mandatory, vpc is optional.`)
updateClusterCmd.Flags().String("cluster-tier", "", "[OPTIONAL] The tier of the cluster. Sandbox or Dedicated.")
updateClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] The fault tolerance of the cluster. The possible values are NONE, ZONE and REGION.")
updateClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] The fault tolerance domain of the cluster. The possible values are NONE, ZONE and REGION.")
updateClusterCmd.Flags().String("database-version", "", "[OPTIONAL] The database version of the cluster. Production or Innovation or Preview.")

}
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/list-clusters.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/one-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/pause-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/paused-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/pausing-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/resume-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/test/fixtures/resume-queue-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cluster_type": "SYNCHRONOUS",
"num_nodes": 1,
"fault_tolerance": "NONE",
"num_faults_to_tolerate": 0,
"node_info": {
"num_cores": 2,
"memory_mb": 8192,
Expand Down
1 change: 1 addition & 0 deletions cmd/util/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
AZURE_CIDR_ALLOWED FeatureFlag = "AZURE_CIDR_ALLOWED"
CLUSTER_CMK_UPDATE FeatureFlag = "CLUSTER_CMK_UPDATE"
ENTERPRISE_SECURITY FeatureFlag = "ENTERPRISE_SECURITY"
CLUSTER_RF FeatureFlag = "CLUSTER_RF"
)

func (f FeatureFlag) String() string {
Expand Down
24 changes: 22 additions & 2 deletions cmd/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,27 @@ func GetClusterTier(tierCli string) (string, error) {
return "FREE", nil
}

return "", fmt.Errorf("The tier must be either 'Sandbox' or 'Dedicated'")
return "", fmt.Errorf("the tier must be either 'Sandbox' or 'Dedicated'")
}

func ValidateNumFaultsToTolerate(numFaultsToTolerate int32, faultTolerance ybmclient.ClusterFaultTolerance) (bool, error) {
if numFaultsToTolerate < 0 || numFaultsToTolerate > 3 {
return false, fmt.Errorf("number of faults to tolerate must be between 0 and 3")
}
if faultTolerance == ybmclient.CLUSTERFAULTTOLERANCE_NONE && numFaultsToTolerate != 0 {
return false, fmt.Errorf("number of faults to tolerate must be 0 for fault tolerance level 'NONE'")
}
if faultTolerance == ybmclient.CLUSTERFAULTTOLERANCE_NODE && numFaultsToTolerate < 1 {
return false, fmt.Errorf("number of faults to tolerate must be greater than 0 for fault tolerance level 'NODE'")
}
if faultTolerance == ybmclient.CLUSTERFAULTTOLERANCE_REGION && numFaultsToTolerate < 1 {
return false, fmt.Errorf("number of faults to tolerate must be greater than 0 for fault tolerance level 'REGION'")
}
if faultTolerance == ybmclient.CLUSTERFAULTTOLERANCE_ZONE && numFaultsToTolerate != 1 {
return false, fmt.Errorf("number of faults to tolerate must be 1 for fault tolerance level 'ZONE'")
}

return true, nil
}

func ValidateCIDR(cidr string) (bool, error) {
Expand All @@ -68,7 +88,7 @@ func ExtractJwtClaims(tokenStr string) (jwt.MapClaims, error) {
if _, ok := token.Claims.(jwt.MapClaims); ok {
return token.Claims.(jwt.MapClaims), nil
}
return nil, errors.New("Unable to extract claims from token")
return nil, errors.New("unable to extract claims from token")
}

func IsJwtTokenExpiredWithTime(tokenStr string, now time.Time) (bool, error) {
Expand Down
37 changes: 19 additions & 18 deletions docs/ybm_cluster_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ ybm cluster create [flags]
### Options

```
--cluster-name string [REQUIRED] Name of the cluster.
--credentials stringToString [REQUIRED] Credentials to login to the cluster. Please provide key value pairs username=<user-name>,password=<password>. (default [])
--cloud-provider string [OPTIONAL] The cloud provider where database needs to be deployed. AWS, AZURE or GCP. Default AWS.
--cluster-tier string [OPTIONAL] The tier of the cluster. Sandbox or Dedicated. Default Sandbox.
--cluster-type string [OPTIONAL] Cluster replication type. SYNCHRONOUS or GEO_PARTITIONED. Default SYNCHRONOUS.
--database-version string [OPTIONAL] The database version of the cluster. Stable or Preview. Default depends on cluster tier, Sandbox is Preview, Dedicated is Stable.
--encryption-spec string [OPTIONAL] The customer managed key spec for the cluster.
Please provide key value pairs as follows:
For AWS:
cloud-provider=AWS,aws-secret-key=<secret-key>,aws-access-key=<access-key>,aws-arn=<arn1>,aws-arn=<arn2> .
aws-access-key can be ommitted if the environment variable YBM_AWS_SECRET_KEY is set. If the environment variable is not set, the user will be prompted to enter the value.
For GCP:
cloud-provider=GCP,gcp-resource-id=<resource-id>,gcp-service-account-path=<service-account-path>.
If specified, all parameters for that provider are mandatory.
--fault-tolerance string [OPTIONAL] The fault tolerance of the cluster. The possible values are NONE, ZONE and REGION. Default NONE.
--node-config stringToInt [OPTIONAL] Configuration of the cluster nodes. Please provide key value pairs num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If specified, num-cores is mandatory, while disk-size-gb and disk-iops are optional. (default [])
--region-info stringArray [OPTIONAL] Region information for the cluster. Please provide key value pairs region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name> as the value. If specified, region and num-nodes are mandatory, vpc is optional. Information about multiple regions can be specified by using multiple --region-info arguments. Default if not specified is us-west-2 AWS region.
-h, --help help for create
--cluster-name string [REQUIRED] Name of the cluster.
--credentials stringToString [REQUIRED] Credentials to login to the cluster. Please provide key value pairs username=<user-name>,password=<password>. (default [])
--cloud-provider string [OPTIONAL] The cloud provider where database needs to be deployed. AWS, AZURE or GCP. Default AWS.
--cluster-tier string [OPTIONAL] The tier of the cluster. Sandbox or Dedicated. Default Sandbox.
--cluster-type string [OPTIONAL] Cluster replication type. SYNCHRONOUS or GEO_PARTITIONED. Default SYNCHRONOUS.
--database-version string [OPTIONAL] The database version of the cluster. Stable or Preview. Default depends on cluster tier, Sandbox is Preview, Dedicated is Stable.
--encryption-spec string [OPTIONAL] The customer managed key spec for the cluster.
Please provide key value pairs as follows:
For AWS:
cloud-provider=AWS,aws-secret-key=<secret-key>,aws-access-key=<access-key>,aws-arn=<arn1>,aws-arn=<arn2> .
aws-access-key can be ommitted if the environment variable YBM_AWS_SECRET_KEY is set. If the environment variable is not set, the user will be prompted to enter the value.
For GCP:
cloud-provider=GCP,gcp-resource-id=<resource-id>,gcp-service-account-path=<service-account-path>.
If specified, all parameters for that provider are mandatory.
--fault-tolerance string [OPTIONAL] The fault tolerance domain of the cluster. The possible values are NONE, ZONE and REGION. Default NONE.
--num-faults-to-tolerate int32 [OPTIONAL] The number of domain faults to tolerate for the level specified. The possible values are 0 for NONE, 1 for ZONE and [1-3] for anything else. Defaults to 0 for NONE, 1 otherwise.
--node-config stringToInt [OPTIONAL] Configuration of the cluster nodes. Please provide key value pairs num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If specified, num-cores is mandatory, while disk-size-gb and disk-iops are optional. (default [])
--region-info stringArray [OPTIONAL] Region information for the cluster. Please provide key value pairs region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name> as the value. If specified, region and num-nodes are mandatory, vpc is optional. Information about multiple regions can be specified by using multiple --region-info arguments. Default if not specified is us-west-2 AWS region.
-h, --help help for create
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/ybm_cluster_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ybm cluster update [flags]
--cluster-tier string [OPTIONAL] The tier of the cluster. Sandbox or Dedicated.
--cluster-type string [OPTIONAL] Cluster replication type. SYNCHRONOUS or GEO_PARTITIONED.
--database-version string [OPTIONAL] The database version of the cluster. Production or Innovation or Preview.
--fault-tolerance string [OPTIONAL] The fault tolerance of the cluster. The possible values are NONE, ZONE and REGION.
--fault-tolerance string [OPTIONAL] The fault tolerance domain of the cluster. The possible values are NONE, ZONE and REGION.
-h, --help help for update
--new-name string [OPTIONAL] The new name to be given to the cluster.
--node-config stringToInt [OPTIONAL] Configuration of the cluster nodes. Please provide key value pairs num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If provided, num-cores is mandatory, while disk-size-gb and disk-iops are optional. (default [])
Expand Down
9 changes: 9 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ func (a *AuthApiClient) CreateClusterSpec(cmd *cobra.Command, regionInfoList []m
faultTolerance, _ := cmd.Flags().GetString("fault-tolerance")
clusterInfo.SetFaultTolerance(ybmclient.ClusterFaultTolerance(faultTolerance))
}
if util.IsFeatureFlagEnabled(util.CLUSTER_RF) {
if cmd.Flags().Changed("num-faults-to-tolerate") {
numFaultsToTolerate, _ := cmd.Flags().GetInt32("num-faults-to-tolerate")
if valid, err := util.ValidateNumFaultsToTolerate(numFaultsToTolerate, clusterInfo.GetFaultTolerance()); !valid {
return nil, err
}
clusterInfo.SetNumFaultsToTolerate(numFaultsToTolerate)
}
}
if util.IsFeatureFlagEnabled(util.ENTERPRISE_SECURITY) {
if cmd.Flags().Changed("enterprise-security") {
enterpriseSecurity, _ := cmd.Flags().GetBool("enterprise-security")
Expand Down
5 changes: 5 additions & 0 deletions internal/formatter/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/enescakir/emoji"
"github.com/inhies/go-bytesize"
"github.com/sirupsen/logrus"
"github.com/yugabyte/ybm-cli/cmd/util"
ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -181,6 +182,10 @@ func (c *ClusterContext) Tier() string {
return "Dedicated"
}
func (c *ClusterContext) FaultTolerance() string {
if util.IsFeatureFlagEnabled(util.CLUSTER_RF) {
rf := *c.c.GetSpec().ClusterInfo.NumFaultsToTolerate.Get()*2 + 1
return fmt.Sprintf("%s, RF %d", string(c.c.GetSpec().ClusterInfo.FaultTolerance), rf)
}
return string(c.c.GetSpec().ClusterInfo.FaultTolerance)
}

Expand Down
22 changes: 22 additions & 0 deletions internal/formatter/clusters_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"bytes"
"encoding/json"
"fmt"
"runtime"
"sort"
"text/template"

"github.com/enescakir/emoji"
"github.com/sirupsen/logrus"
"github.com/yugabyte/ybm-cli/internal/client"
"github.com/yugabyte/ybm-cli/internal/cluster"
Expand Down Expand Up @@ -307,6 +309,10 @@ func (c *clusterInfoRegionsContext) DiskSizeGb() string {
}

func (c *clusterInfoRegionsContext) Region() string {
// If the fault tolerance is regional, check if there is an affinitized region
if c.clusterInfo.FaultTolerance == ybmclient.CLUSTERFAULTTOLERANCE_REGION && c.clusterInfoRegion.IsAffinitized.IsSet() {
return fmt.Sprintf("%s %s", AffinitizedRegionToEmoji(*c.clusterInfoRegion.IsAffinitized.Get()), c.clusterInfoRegion.GetPlacementInfo().CloudInfo.Region)
}
return c.clusterInfoRegion.GetPlacementInfo().CloudInfo.Region
}

Expand All @@ -316,3 +322,19 @@ func (c *clusterInfoRegionsContext) VpcName() string {
func (c *clusterInfoRegionsContext) MarshalJSON() ([]byte, error) {
return json.Marshal(c.clusterInfoRegion)
}

func AffinitizedRegionToEmoji(isAffinitized bool) string {
switch isAffinitized {
case true:
// Windows terminal do not support emoji
// So we return directly the healthstate
if runtime.GOOS == "windows" {
return fmt.Sprintf("*")
}
return emoji.Parse(":star:")
case false:
return fmt.Sprintf("")
default:
return fmt.Sprintf("")
}
}

0 comments on commit d0b8249

Please sign in to comment.