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

Support all VMSizeFlags in fly postgres create #4216

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
46 changes: 35 additions & 11 deletions internal/command/postgres/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,6 +35,7 @@ func newCreate() *cobra.Command {
flag.Region(),
flag.Org(),
flag.Detach(),
flag.VMSizeFlags,
flag.Bool{
Name: "enable-backups",
Description: "Create a new tigris bucket and enable WAL-based backups",
Expand All @@ -48,10 +50,6 @@ func newCreate() *cobra.Command {
Shorthand: "p",
Description: "The superuser password. The password will be generated for you if you leave this blank",
},
flag.String{
Name: "vm-size",
Description: "the size of the VM",
},
flag.Int{
Name: "initial-cluster-size",
Description: "Initial cluster size",
Expand Down Expand Up @@ -288,7 +286,24 @@ func CreateCluster(ctx context.Context, org *fly.Organization, region *fly.Regio
BarmanRemoteRestoreConfig: flag.GetString(ctx, "restore-target-app"),
}

customConfig := params.DiskGb != 0 || params.VMSize != "" || params.InitialClusterSize != 0 || params.ScaleToZero != nil
isCustomMachine := false
for _, sizeFlag := range flag.VMSizeFlags {
nameField := reflect.ValueOf(sizeFlag).FieldByName("Name")

if nameField.IsValid() {
name := nameField.String()
if name == "vm-size" {
continue
}

if flag.IsSpecified(ctx, name) {
isCustomMachine = true
break
}
}
}

customConfig := isCustomMachine || params.DiskGb != 0 || params.VMSize != "" || params.InitialClusterSize != 0 || params.ScaleToZero != nil

var config *PostgresConfiguration

Expand Down Expand Up @@ -344,13 +359,22 @@ func CreateCluster(ctx context.Context, org *fly.Organization, region *fly.Regio
}
input.InitialClusterSize = params.PostgresConfiguration.InitialClusterSize

// Resolve VM size
vmSize, err := resolveVMSize(ctx, params.VMSize)
if err != nil {
return err
}
if isCustomMachine {
guest, err := flag.GetMachineGuest(ctx, nil)
if err != nil {
return err
}

input.VMSize = vmSize
input.Guest = guest
} else {
// Resolve VM size
vmSize, err := resolveVMSize(ctx, params.VMSize)
if err != nil {
return err
}

input.VMSize = vmSize
}

if params.ScaleToZero != nil {
input.ScaleToZero = *params.ScaleToZero
Expand Down