From ee3746f438400119bf621078ba4cfd2207c5d6d9 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 14 Mar 2025 12:20:17 -0400 Subject: [PATCH 1/6] Update planetscale-go --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index ff171df6..6e0e0bc7 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c github.com/pkg/errors v0.9.1 - github.com/planetscale/planetscale-go v0.124.0 + github.com/planetscale/planetscale-go v0.125.0 github.com/planetscale/psdb v0.0.0-20240109164348-6848e728f6e7 github.com/planetscale/psdbproxy v0.0.0-20250117221522-0c8e2b0e36e6 github.com/spf13/cobra v1.9.1 @@ -34,7 +34,7 @@ require ( go.uber.org/zap v1.27.0 go.uber.org/zap/exp v0.3.0 golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 - golang.org/x/oauth2 v0.27.0 + golang.org/x/oauth2 v0.28.0 golang.org/x/sync v0.11.0 golang.org/x/sys v0.30.0 golang.org/x/text v0.22.0 diff --git a/go.sum b/go.sum index c6f042f2..60c3848b 100644 --- a/go.sum +++ b/go.sum @@ -114,8 +114,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2vvqGZLvoQfpaGg/j1fNDr4j03s3PRz4rVY= github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q= -github.com/planetscale/planetscale-go v0.124.0 h1:WiPPBEJ0fpg9D9+X+lQC0i7Knb6cQ3yO38Xe90O/qwQ= -github.com/planetscale/planetscale-go v0.124.0/go.mod h1:HXOe9UNFb71w9XIICJj5ncwuY25h2Bng/KrXH80GF0s= +github.com/planetscale/planetscale-go v0.125.0 h1:+R8ZZ0nW+HZhFJGU9IQQxREXM9r7YX6u+S61mFkUWDs= +github.com/planetscale/planetscale-go v0.125.0/go.mod h1:/9cIDXvqglfjCRPzPNP6BklL+J7qq50SKtAP97c4ix0= github.com/planetscale/psdb v0.0.0-20240109164348-6848e728f6e7 h1:dxdoFKWVDlV1gq8UQC8NWCofLjCEjEHw47gfeojgs28= github.com/planetscale/psdb v0.0.0-20240109164348-6848e728f6e7/go.mod h1:WZmi4gw3rOK+ryd1inGxgfKwoFV04O7xBCqzWzv0/0U= github.com/planetscale/psdbproxy v0.0.0-20250117221522-0c8e2b0e36e6 h1:/Ox1ZTAdk+soSngzzKoJh5voOzptrpPrux11o30rIaw= @@ -187,8 +187,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= -golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= -golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc= +golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= From 85706d77f2ff470d68bfb7052621406c5b4852ed Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 14 Mar 2025 12:23:59 -0400 Subject: [PATCH 2/6] Add metal and standard flags to size. --- internal/cmd/size/cluster.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/cmd/size/cluster.go b/internal/cmd/size/cluster.go index 1cba5cc6..0e2a44cb 100644 --- a/internal/cmd/size/cluster.go +++ b/internal/cmd/size/cluster.go @@ -25,7 +25,9 @@ func ClusterCmd(ch *cmdutil.Helper) *cobra.Command { func ListCmd(ch *cmdutil.Helper) *cobra.Command { var flags struct { - region string + region string + metal bool + standard bool } cmd := &cobra.Command{ @@ -47,11 +49,13 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command { return err } - return ch.Printer.PrintResource(toClusterSKUs(clusterSKUs)) + return ch.Printer.PrintResource(toClusterSKUs(clusterSKUs, flags.standard, flags.metal)) }, } cmd.Flags().StringVar(&flags.region, "region", "", "view cluster sizes and rates for a specific region") + cmd.Flags().BoolVar(&flags.metal, "metal", false, "view cluster sizes and rates for metal clusters") + cmd.Flags().BoolVar(&flags.standard, "standard", false, "view cluster sizes and rates for standard clusters") cmd.RegisterFlagCompletionFunc("region", func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) { return cmdutil.RegionsCompletionFunc(ch, cmd, args, toComplete) @@ -103,12 +107,19 @@ func toClusterSKU(clusterSKU *planetscale.ClusterSKU) *ClusterSKU { return cluster } -func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU) []*ClusterSKU { +func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU, filterStandard, filterMetal bool) []*ClusterSKU { clusters := make([]*ClusterSKU, 0, len(clusterSKUs)) for _, clusterSKU := range clusterSKUs { if clusterSKU.Enabled && clusterSKU.Rate != nil && clusterSKU.Name != "PS_DEV" { - clusters = append(clusters, toClusterSKU(clusterSKU)) + // If these flags match, that means we just want to list all clusters. + if filterStandard == filterMetal { + clusters = append(clusters, toClusterSKU(clusterSKU)) + } else if filterStandard && !clusterSKU.Metal { + clusters = append(clusters, toClusterSKU(clusterSKU)) + } else if filterMetal && clusterSKU.Metal { + clusters = append(clusters, toClusterSKU(clusterSKU)) + } } } From dd554c227913e3add9ac1391adab099906195efb Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 14 Mar 2025 12:25:29 -0400 Subject: [PATCH 3/6] Remove ClusterSize typing --- internal/cmd/database/create.go | 2 +- internal/cmd/keyspace/create.go | 2 +- internal/cmd/keyspace/create_test.go | 8 ++++---- internal/cmd/keyspace/resize.go | 2 +- internal/cmd/keyspace/resize_test.go | 4 ++-- internal/cmdutil/cmdutil.go | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/cmd/database/create.go b/internal/cmd/database/create.go index 789f1044..6d41517d 100644 --- a/internal/cmd/database/create.go +++ b/internal/cmd/database/create.go @@ -27,7 +27,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command { return err } - createReq.ClusterSize = ps.ClusterSize(clusterSize) + createReq.ClusterSize = clusterSize createReq.Organization = ch.Config.Organization createReq.Name = args[0] diff --git a/internal/cmd/keyspace/create.go b/internal/cmd/keyspace/create.go index 942e3adf..ba3f252d 100644 --- a/internal/cmd/keyspace/create.go +++ b/internal/cmd/keyspace/create.go @@ -33,7 +33,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command { createReq.Name = keyspace createReq.Shards = flags.shards createReq.ExtraReplicas = flags.additionalReplicas - createReq.ClusterSize = planetscale.ClusterSize(flags.clusterSize) + createReq.ClusterSize = flags.clusterSize client, err := ch.Client() if err != nil { diff --git a/internal/cmd/keyspace/create_test.go b/internal/cmd/keyspace/create_test.go index 60c5f5cc..750725ce 100644 --- a/internal/cmd/keyspace/create_test.go +++ b/internal/cmd/keyspace/create_test.go @@ -30,7 +30,7 @@ func TestKeyspace_CreateCmd(t *testing.T) { ks := &ps.Keyspace{ ID: "wantid", Name: keyspace, - ClusterSize: ps.ClusterSize("PS-20"), + ClusterSize: "PS-20", Replicas: 3, Shards: 2, } @@ -41,7 +41,7 @@ func TestKeyspace_CreateCmd(t *testing.T) { c.Assert(req.Organization, qt.Equals, org) c.Assert(req.Branch, qt.Equals, branch) c.Assert(req.Name, qt.Equals, keyspace) - c.Assert(req.ClusterSize, qt.Equals, ps.ClusterSize("PS-20")) + c.Assert(req.ClusterSize, qt.Equals, "PS-20") c.Assert(req.ExtraReplicas, qt.Equals, 1) c.Assert(req.Shards, qt.Equals, 2) @@ -86,7 +86,7 @@ func TestKeyspace_CreateCmdOnlyClusterSize(t *testing.T) { ks := &ps.Keyspace{ ID: "wantid", Name: keyspace, - ClusterSize: ps.ClusterSize("PS-10"), + ClusterSize: "PS-10", Replicas: 2, ExtraReplicas: 0, Shards: 1, @@ -98,7 +98,7 @@ func TestKeyspace_CreateCmdOnlyClusterSize(t *testing.T) { c.Assert(req.Organization, qt.Equals, org) c.Assert(req.Branch, qt.Equals, branch) c.Assert(req.Name, qt.Equals, keyspace) - c.Assert(req.ClusterSize, qt.Equals, ps.ClusterSize("PS-10")) + c.Assert(req.ClusterSize, qt.Equals, "PS-10") c.Assert(req.ExtraReplicas, qt.Equals, 0) c.Assert(req.Shards, qt.Equals, 1) diff --git a/internal/cmd/keyspace/resize.go b/internal/cmd/keyspace/resize.go index 61b9cca2..222d636e 100644 --- a/internal/cmd/keyspace/resize.go +++ b/internal/cmd/keyspace/resize.go @@ -56,7 +56,7 @@ func ResizeCmd(ch *cmdutil.Helper) *cobra.Command { } if cmd.Flags().Changed("cluster-size") { - size := ps.ClusterSize(flags.clusterSize) + size := flags.clusterSize resizeReq.ClusterSize = &size } diff --git a/internal/cmd/keyspace/resize_test.go b/internal/cmd/keyspace/resize_test.go index f6edfa63..f0985c33 100644 --- a/internal/cmd/keyspace/resize_test.go +++ b/internal/cmd/keyspace/resize_test.go @@ -45,7 +45,7 @@ func TestKeyspace_ResizeCmd(t *testing.T) { c.Assert(req.Branch, qt.Equals, branch) c.Assert(req.Keyspace, qt.Equals, keyspace) c.Assert(*req.ExtraReplicas, qt.Equals, uint(3)) - c.Assert(*req.ClusterSize, qt.Equals, ps.ClusterSize("PS_10")) + c.Assert(*req.ClusterSize, qt.Equals, "PS_10") return krr, nil }, @@ -102,7 +102,7 @@ func TestKeyspace_ResizeCmdOnlyClusterSize(t *testing.T) { c.Assert(req.Branch, qt.Equals, branch) c.Assert(req.Keyspace, qt.Equals, keyspace) c.Assert(req.ExtraReplicas, qt.IsNil) - c.Assert(*req.ClusterSize, qt.Equals, ps.ClusterSize("PS_10")) + c.Assert(*req.ClusterSize, qt.Equals, "PS_10") return krr, nil }, diff --git a/internal/cmdutil/cmdutil.go b/internal/cmdutil/cmdutil.go index f774e21c..ad2b96f9 100644 --- a/internal/cmdutil/cmdutil.go +++ b/internal/cmdutil/cmdutil.go @@ -296,8 +296,8 @@ func DeployRequestBranchToNumber(ctx context.Context, client *ps.Client, organiz return deployRequests[0].Number, nil } -func ToClusterSizeSlug(c ps.ClusterSize) string { - return strings.ReplaceAll(string(c), "_", "-") +func ToClusterSizeSlug(c string) string { + return strings.ReplaceAll(c, "_", "-") } func SnakeToSentenceCase(s string) string { From 4064bcb69ddbb9a6c2886294d0c6f2137abb63b5 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 14 Mar 2025 12:36:21 -0400 Subject: [PATCH 4/6] Use network instead of standard --- internal/cmd/size/cluster.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/cmd/size/cluster.go b/internal/cmd/size/cluster.go index 0e2a44cb..e095e7c7 100644 --- a/internal/cmd/size/cluster.go +++ b/internal/cmd/size/cluster.go @@ -25,9 +25,9 @@ func ClusterCmd(ch *cmdutil.Helper) *cobra.Command { func ListCmd(ch *cmdutil.Helper) *cobra.Command { var flags struct { - region string - metal bool - standard bool + region string + metal bool + network bool } cmd := &cobra.Command{ @@ -49,13 +49,13 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command { return err } - return ch.Printer.PrintResource(toClusterSKUs(clusterSKUs, flags.standard, flags.metal)) + return ch.Printer.PrintResource(toClusterSKUs(clusterSKUs, flags.network, flags.metal)) }, } cmd.Flags().StringVar(&flags.region, "region", "", "view cluster sizes and rates for a specific region") - cmd.Flags().BoolVar(&flags.metal, "metal", false, "view cluster sizes and rates for metal clusters") - cmd.Flags().BoolVar(&flags.standard, "standard", false, "view cluster sizes and rates for standard clusters") + cmd.Flags().BoolVar(&flags.metal, "metal", false, "view cluster sizes and rates for clusters with metal storage") + cmd.Flags().BoolVar(&flags.network, "network", false, "view cluster sizes and rates for clusters with network attached storage") cmd.RegisterFlagCompletionFunc("region", func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) { return cmdutil.RegionsCompletionFunc(ch, cmd, args, toComplete) @@ -107,15 +107,15 @@ func toClusterSKU(clusterSKU *planetscale.ClusterSKU) *ClusterSKU { return cluster } -func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU, filterStandard, filterMetal bool) []*ClusterSKU { +func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU, filterNetwork, filterMetal bool) []*ClusterSKU { clusters := make([]*ClusterSKU, 0, len(clusterSKUs)) for _, clusterSKU := range clusterSKUs { if clusterSKU.Enabled && clusterSKU.Rate != nil && clusterSKU.Name != "PS_DEV" { // If these flags match, that means we just want to list all clusters. - if filterStandard == filterMetal { + if filterNetwork == filterMetal { clusters = append(clusters, toClusterSKU(clusterSKU)) - } else if filterStandard && !clusterSKU.Metal { + } else if filterNetwork && !clusterSKU.Metal { clusters = append(clusters, toClusterSKU(clusterSKU)) } else if filterMetal && clusterSKU.Metal { clusters = append(clusters, toClusterSKU(clusterSKU)) From ca4b0aa7b909944490e27d857a971d061b14022a Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 14 Mar 2025 13:11:52 -0400 Subject: [PATCH 5/6] Only have a metal flag --- internal/cmd/size/cluster.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/internal/cmd/size/cluster.go b/internal/cmd/size/cluster.go index e095e7c7..28d7e748 100644 --- a/internal/cmd/size/cluster.go +++ b/internal/cmd/size/cluster.go @@ -25,9 +25,8 @@ func ClusterCmd(ch *cmdutil.Helper) *cobra.Command { func ListCmd(ch *cmdutil.Helper) *cobra.Command { var flags struct { - region string - metal bool - network bool + region string + metal bool } cmd := &cobra.Command{ @@ -49,13 +48,12 @@ func ListCmd(ch *cmdutil.Helper) *cobra.Command { return err } - return ch.Printer.PrintResource(toClusterSKUs(clusterSKUs, flags.network, flags.metal)) + return ch.Printer.PrintResource(toClusterSKUs(clusterSKUs, flags.metal)) }, } cmd.Flags().StringVar(&flags.region, "region", "", "view cluster sizes and rates for a specific region") cmd.Flags().BoolVar(&flags.metal, "metal", false, "view cluster sizes and rates for clusters with metal storage") - cmd.Flags().BoolVar(&flags.network, "network", false, "view cluster sizes and rates for clusters with network attached storage") cmd.RegisterFlagCompletionFunc("region", func(cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective) { return cmdutil.RegionsCompletionFunc(ch, cmd, args, toComplete) @@ -107,17 +105,14 @@ func toClusterSKU(clusterSKU *planetscale.ClusterSKU) *ClusterSKU { return cluster } -func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU, filterNetwork, filterMetal bool) []*ClusterSKU { +func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU, onlyMetal bool) []*ClusterSKU { clusters := make([]*ClusterSKU, 0, len(clusterSKUs)) for _, clusterSKU := range clusterSKUs { if clusterSKU.Enabled && clusterSKU.Rate != nil && clusterSKU.Name != "PS_DEV" { - // If these flags match, that means we just want to list all clusters. - if filterNetwork == filterMetal { + if onlyMetal && clusterSKU.Metal { clusters = append(clusters, toClusterSKU(clusterSKU)) - } else if filterNetwork && !clusterSKU.Metal { - clusters = append(clusters, toClusterSKU(clusterSKU)) - } else if filterMetal && clusterSKU.Metal { + } else { clusters = append(clusters, toClusterSKU(clusterSKU)) } } From 2d6350ecc505b2b7825c671e53f1ce5d2d82ec07 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Fri, 14 Mar 2025 13:23:22 -0400 Subject: [PATCH 6/6] Fix conditional --- internal/cmd/size/cluster.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/cmd/size/cluster.go b/internal/cmd/size/cluster.go index 28d7e748..f78de74c 100644 --- a/internal/cmd/size/cluster.go +++ b/internal/cmd/size/cluster.go @@ -110,8 +110,10 @@ func toClusterSKUs(clusterSKUs []*planetscale.ClusterSKU, onlyMetal bool) []*Clu for _, clusterSKU := range clusterSKUs { if clusterSKU.Enabled && clusterSKU.Rate != nil && clusterSKU.Name != "PS_DEV" { - if onlyMetal && clusterSKU.Metal { - clusters = append(clusters, toClusterSKU(clusterSKU)) + if onlyMetal { + if clusterSKU.Metal { + clusters = append(clusters, toClusterSKU(clusterSKU)) + } } else { clusters = append(clusters, toClusterSKU(clusterSKU)) }