Skip to content

Commit

Permalink
[CLOUDGA-20540][CLOUDGA-19943] Get CLI ready for asymmetric geo prod …
Browse files Browse the repository at this point in the history
…GA (#223)

* [CLOUDGA-20540][CLOUDGA-19943] Get CLI ready for asymmetric geo prod GA

* Respond to feedback
  • Loading branch information
daniel-yb authored Apr 9, 2024
1 parent 1a60fd2 commit 37de992
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 88 deletions.
36 changes: 14 additions & 22 deletions cmd/cluster/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var createClusterCmd = &cobra.Command{
logrus.Fatalf(ybmAuthClient.GetApiErrorDetails(err))
}
authApi.GetInfo("", "")
asymmetricGeoEnabled := util.IsFeatureFlagEnabled(util.ASYMMETRIC_GEO)

clusterName, _ := cmd.Flags().GetString("cluster-name")
credentials, _ := cmd.Flags().GetStringToString("credentials")
Expand All @@ -59,10 +58,8 @@ var createClusterCmd = &cobra.Command{
if changedNodeInfo {
nodeConfig, _ := cmd.Flags().GetStringToInt("node-config")
numCores, ok := nodeConfig["num-cores"]
if !asymmetricGeoEnabled && !ok {
logrus.Fatalln("Number of cores not specified in node config")
}
if asymmetricGeoEnabled && ok {

if ok {
defaultNumCores = numCores
}
if diskSizeGb, ok := nodeConfig["disk-size-gb"]; ok {
Expand Down Expand Up @@ -98,15 +95,15 @@ var createClusterCmd = &cobra.Command{
regionInfoMap["vpc"] = val
}
case "num-cores":
if asymmetricGeoEnabled && len(strings.TrimSpace(val)) != 0 {
if len(strings.TrimSpace(val)) != 0 {
regionInfoMap["num-cores"] = val
}
case "disk-size-gb":
if asymmetricGeoEnabled && len(strings.TrimSpace(val)) != 0 {
if len(strings.TrimSpace(val)) != 0 {
regionInfoMap["disk-size-gb"] = val
}
case "disk-iops":
if asymmetricGeoEnabled && len(strings.TrimSpace(val)) != 0 {
if len(strings.TrimSpace(val)) != 0 {
regionInfoMap["disk-iops"] = val
}
}
Expand All @@ -118,13 +115,13 @@ var createClusterCmd = &cobra.Command{
if _, ok := regionInfoMap["num-nodes"]; !ok {
logrus.Fatalln("Number of nodes not specified in region info")
}
if _, ok := regionInfoMap["num-cores"]; asymmetricGeoEnabled && !ok && defaultNumCores > 0 {
if _, ok := regionInfoMap["num-cores"]; !ok && defaultNumCores > 0 {
regionInfoMap["num-cores"] = strconv.Itoa(defaultNumCores)
}
if _, ok := regionInfoMap["disk-size-gb"]; asymmetricGeoEnabled && !ok && defaultDiskSizeGb > 0 {
if _, ok := regionInfoMap["disk-size-gb"]; !ok && defaultDiskSizeGb > 0 {
regionInfoMap["disk-size-gb"] = strconv.Itoa(defaultDiskSizeGb)
}
if _, ok := regionInfoMap["disk-iops"]; asymmetricGeoEnabled && !ok && defaultDiskIops > 0 {
if _, ok := regionInfoMap["disk-iops"]; !ok && defaultDiskIops > 0 {
regionInfoMap["disk-iops"] = strconv.Itoa(defaultDiskIops)
}

Expand Down Expand Up @@ -226,16 +223,11 @@ func init() {
For AZURE:
cloud-provider=AZURE,azu-client-id=<client-id>,azu-client-secret=<client-secret>,azu-tenant-id=<tenant-id>,azu-key-name=<key-name>,azu-key-vault-uri=<key-vault-uri>.
If specified, all parameters for that provider are mandatory.`)
createClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] The fault tolerance domain of the cluster. The possible values are NONE, NODE, ZONE and REGION. Default NONE.")
createClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] Fault tolerance of the cluster. The possible values are NONE, NODE, ZONE, or 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.")
if util.IsFeatureFlagEnabled(util.ASYMMETRIC_GEO) {
createClusterCmd.Flags().MarkDeprecated("node-config", "please use --region-info to specify num-cores, disk-size-gb, and disk-iops")
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>,num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If specified, region and num-nodes are mandatory, while num-cores, disk-size-gb, disk-iops, and vpc are optional. Information about multiple regions can be specified by using multiple --region-info arguments. Default if not specified is us-west-2 AWS region.`)
} else {
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.`)
}
createClusterCmd.Flags().String("preferred-region", "", "[OPTIONAL] The preferred region in a multi region cluster. A preferred region is where all the reads and writes are handled.")
createClusterCmd.Flags().String("default-region", "", "[OPTIONAL] The default region in a geo partitioned cluster. A default region is where all the tables not created within a tablespace reside.")

createClusterCmd.Flags().StringToInt("node-config", nil, "[OPTIONAL] Number of vCPUs and disk size per node for the cluster, provided as key-value pairs. Arguments are num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> (AWS only). num-cores is required.")
createClusterCmd.Flags().MarkDeprecated("node-config", "Deprecated. Use --region-info to specify num-cores, disk-size-gb, and disk-iops")
createClusterCmd.Flags().StringArray("region-info", []string{}, `Region information for the cluster, provided as key-value pairs. Arguments are region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name>,num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> (AWS only). region, num-nodes, num-cores, disk-size-gb are required. Specify one --region-info flag for each region in the cluster.`)
createClusterCmd.Flags().String("preferred-region", "", "[OPTIONAL] The preferred region in a multi region cluster. The preferred region handles all read and write requests from clients.")
createClusterCmd.Flags().String("default-region", "", "[OPTIONAL] The primary region in a partition-by-region cluster. The primary region is where all the tables not created in a tablespace reside.")
}
52 changes: 21 additions & 31 deletions cmd/cluster/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/yugabyte/ybm-cli/cmd/util"
ybmAuthClient "github.com/yugabyte/ybm-cli/internal/client"
"github.com/yugabyte/ybm-cli/internal/formatter"
ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
Expand All @@ -37,7 +36,6 @@ var updateClusterCmd = &cobra.Command{
Long: "Update a cluster",
Run: func(cmd *cobra.Command, args []string) {

asymmetricGeoEnabled := util.IsFeatureFlagEnabled(util.ASYMMETRIC_GEO)
clusterName, _ := cmd.Flags().GetString("cluster-name")
authApi, err := ybmAuthClient.NewAuthApiClient()
if err != nil {
Expand Down Expand Up @@ -73,10 +71,8 @@ var updateClusterCmd = &cobra.Command{
if changedNodeInfo {
nodeConfig, _ := cmd.Flags().GetStringToInt("node-config")
numCores, ok := nodeConfig["num-cores"]
if !asymmetricGeoEnabled && !ok {
logrus.Fatalln("Number of cores not specified in node config")
}
if asymmetricGeoEnabled && ok {

if ok {
defaultNumCores = numCores
}
if diskSizeGb, ok := nodeConfig["disk-size-gb"]; ok {
Expand Down Expand Up @@ -112,15 +108,15 @@ var updateClusterCmd = &cobra.Command{
regionInfoMap["vpc"] = val
}
case "num-cores":
if asymmetricGeoEnabled && len(strings.TrimSpace(val)) != 0 {
if len(strings.TrimSpace(val)) != 0 {
regionInfoMap["num-cores"] = val
}
case "disk-size-gb":
if asymmetricGeoEnabled && len(strings.TrimSpace(val)) != 0 {
if len(strings.TrimSpace(val)) != 0 {
regionInfoMap["disk-size-gb"] = val
}
case "disk-iops":
if asymmetricGeoEnabled && len(strings.TrimSpace(val)) != 0 {
if len(strings.TrimSpace(val)) != 0 {
regionInfoMap["disk-iops"] = val
}
}
Expand All @@ -132,13 +128,13 @@ var updateClusterCmd = &cobra.Command{
if _, ok := regionInfoMap["num-nodes"]; !ok {
logrus.Fatalln("Number of nodes not specified in region info")
}
if _, ok := regionInfoMap["num-cores"]; asymmetricGeoEnabled && !ok && defaultNumCores > 0 {
if _, ok := regionInfoMap["num-cores"]; !ok && defaultNumCores > 0 {
regionInfoMap["num-cores"] = strconv.Itoa(defaultNumCores)
}
if _, ok := regionInfoMap["disk-size-gb"]; asymmetricGeoEnabled && !ok && defaultDiskSizeGb > 0 {
if _, ok := regionInfoMap["disk-size-gb"]; !ok && defaultDiskSizeGb > 0 {
regionInfoMap["disk-size-gb"] = strconv.Itoa(defaultDiskSizeGb)
}
if _, ok := regionInfoMap["disk-iops"]; asymmetricGeoEnabled && !ok && defaultDiskIops > 0 {
if _, ok := regionInfoMap["disk-iops"]; !ok && defaultDiskIops > 0 {
regionInfoMap["disk-iops"] = strconv.Itoa(defaultDiskIops)
}

Expand Down Expand Up @@ -209,15 +205,11 @@ func init() {
updateClusterCmd.Flags().String("new-name", "", "[OPTIONAL] The new name to be given to the cluster.")
updateClusterCmd.Flags().String("cloud-provider", "", "[OPTIONAL] The cloud provider where database needs to be deployed. AWS, AZURE or GCP.")
updateClusterCmd.Flags().String("cluster-type", "", "[OPTIONAL] Cluster replication type. SYNCHRONOUS or GEO_PARTITIONED.")
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.")
if util.IsFeatureFlagEnabled(util.ASYMMETRIC_GEO) {
updateClusterCmd.Flags().MarkDeprecated("node-config", "please use --region-info to specify num-cores, disk-size-gb, and disk-iops")
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>,num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> as the value. If specified, region and num-nodes are mandatory, while num-cores, disk-size-gb, disk-iops, and vpc are optional.`)
} else {
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().StringToInt("node-config", nil, "[OPTIONAL] Number of vCPUs and disk size per node for the cluster, provided as key-value pairs. Arguments are num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> (AWS only). num-cores is required.")
updateClusterCmd.Flags().MarkDeprecated("node-config", "Deprecated. Use --region-info to specify num-cores, disk-size-gb, and disk-iops.")
updateClusterCmd.Flags().StringArray("region-info", []string{}, `Region information for the cluster, provided as key-value pairs. Arguments are region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name>,num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> (AWS only). region, num-nodes, num-cores, disk-size-gb are required. Specify one --region-info flag for each region in the cluster.`)
updateClusterCmd.Flags().String("cluster-tier", "", "[OPTIONAL] The tier of the cluster. Sandbox or Dedicated.")
updateClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] The fault tolerance domain of the cluster. The possible values are NONE, NODE, ZONE and REGION.")
updateClusterCmd.Flags().String("fault-tolerance", "", "[OPTIONAL] Fault tolerance of the cluster. The possible values are NONE, NODE, ZONE, or REGION. Default NONE.")
updateClusterCmd.Flags().String("database-version", "", "[OPTIONAL] The database version of the cluster. Production or Innovation or Preview.")

}
Expand Down Expand Up @@ -295,17 +287,15 @@ func populateFlags(cmd *cobra.Command, originalSpec ybmclient.ClusterSpec, track
regionInfo += ",vpc=" + vpcName
}

if util.IsFeatureFlagEnabled(util.ASYMMETRIC_GEO) {
if nodeInfo, ok := clusterRegionInfo.GetNodeInfoOk(); ok {
if numCores, ok_ := nodeInfo.GetNumCoresOk(); ok_ {
regionInfo += ",num-cores=" + strconv.Itoa(int(*numCores))
}
if diskSizeGb, ok_ := nodeInfo.GetDiskSizeGbOk(); ok_ {
regionInfo += ",disk-size-gb=" + strconv.Itoa(int(*diskSizeGb))
}
if diskIops, ok_ := nodeInfo.GetDiskIopsOk(); ok_ && diskIops != nil {
regionInfo += ",disk-iops=" + strconv.Itoa(int(*diskIops))
}
if nodeInfo, ok := clusterRegionInfo.GetNodeInfoOk(); ok {
if numCores, ok_ := nodeInfo.GetNumCoresOk(); ok_ {
regionInfo += ",num-cores=" + strconv.Itoa(int(*numCores))
}
if diskSizeGb, ok_ := nodeInfo.GetDiskSizeGbOk(); ok_ {
regionInfo += ",disk-size-gb=" + strconv.Itoa(int(*diskSizeGb))
}
if diskIops, ok_ := nodeInfo.GetDiskIopsOk(); ok_ && diskIops != nil {
regionInfo += ",disk-iops=" + strconv.Itoa(int(*diskIops))
}
}
regionInfoList = append(regionInfoList, regionInfo)
Expand Down
1 change: 0 additions & 1 deletion cmd/util/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const (
AZURE_CIDR_ALLOWED FeatureFlag = "AZURE_CIDR_ALLOWED"
ENTERPRISE_SECURITY FeatureFlag = "ENTERPRISE_SECURITY"
INCREMENTAL_BACKUP FeatureFlag = "INCREMENTAL_BACKUP"
ASYMMETRIC_GEO FeatureFlag = "ASYMMETRIC_GEO"
)

func (f FeatureFlag) String() string {
Expand Down
9 changes: 4 additions & 5 deletions docs/ybm_cluster_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ ybm cluster create [flags]
For AZURE:
cloud-provider=AZURE,azu-client-id=<client-id>,azu-client-secret=<client-secret>,azu-tenant-id=<tenant-id>,azu-key-name=<key-name>,azu-key-vault-uri=<key-vault-uri>.
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, NODE, ZONE and REGION. Default NONE.
--fault-tolerance string [OPTIONAL] Fault tolerance of the cluster. The possible values are NONE, NODE, ZONE, or 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.
--preferred-region string [OPTIONAL] The preferred region in a multi region cluster. A preferred region is where all the reads and writes are handled.
--default-region string [OPTIONAL] The default region in a geo partitioned cluster. A default region is where all the tables not created within a tablespace reside.
--region-info stringArray Region information for the cluster, provided as key-value pairs. Arguments are region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name>,num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> (AWS only). region, num-nodes, num-cores, disk-size-gb are required. Specify one --region-info flag for each region in the cluster.
--preferred-region string [OPTIONAL] The preferred region in a multi region cluster. The preferred region handles all read and write requests from clients.
--default-region string [OPTIONAL] The primary region in a partition-by-region cluster. The primary region is where all the tables not created in a tablespace reside.
-h, --help help for create
```

Expand Down
5 changes: 2 additions & 3 deletions docs/ybm_cluster_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ 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 domain of the cluster. The possible values are NONE, NODE, ZONE and REGION.
--fault-tolerance string [OPTIONAL] Fault tolerance of the cluster. The possible values are NONE, NODE, ZONE, or REGION. Default NONE.
-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 [])
--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 provided, region and num-nodes are mandatory, vpc is optional.
--region-info stringArray Region information for the cluster, provided as key-value pairs. Arguments are region=<region-name>,num-nodes=<number-of-nodes>,vpc=<vpc-name>,num-cores=<num-cores>,disk-size-gb=<disk-size-gb>,disk-iops=<disk-iops> (AWS only). region, num-nodes, num-cores, disk-size-gb are required. Specify one --region-info flag for each region in the cluster.
```

### Options inherited from parent commands
Expand Down
Loading

0 comments on commit 37de992

Please sign in to comment.