-
Notifications
You must be signed in to change notification settings - Fork 218
/
describe_plan.go
70 lines (51 loc) · 2.06 KB
/
describe_plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package launch
import (
"context"
"fmt"
"strings"
"github.com/samber/lo"
fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/command/launch/plan"
"github.com/superfly/flyctl/internal/command/redis"
)
// This had to be broken out from `plan` because of a circular dependency.
// Easily the most annoying part of go.
const descriptionNone = "<none>"
func describePostgresPlan(launchPlan *plan.LaunchPlan) (string, error) {
switch provider := launchPlan.Postgres.Provider().(type) {
case *plan.FlyPostgresPlan:
return describeFlyPostgresPlan(provider)
case *plan.SupabasePostgresPlan:
return describeSupabasePostgresPlan(provider, launchPlan)
}
return descriptionNone, nil
}
func describeFlyPostgresPlan(p *plan.FlyPostgresPlan) (string, error) {
nodePlural := lo.Ternary(p.Nodes == 1, "", "s")
nodesStr := fmt.Sprintf("(Fly Postgres) %d Node%s", p.Nodes, nodePlural)
guestStr := fly.MachinePresets[p.VmSize].String()
diskSizeStr := fmt.Sprintf("%dGB disk", p.DiskSizeGB)
info := []string{nodesStr, guestStr, diskSizeStr}
if p.AutoStop {
info = append(info, "auto-stop")
}
return strings.Join(info, ", "), nil
}
func describeSupabasePostgresPlan(p *plan.SupabasePostgresPlan, launchPlan *plan.LaunchPlan) (string, error) {
return fmt.Sprintf("(Supabase) %s in %s", p.GetDbName(launchPlan), p.GetRegion(launchPlan)), nil
}
func describeRedisPlan(ctx context.Context, p plan.RedisPlan, org *fly.Organization) (string, error) {
switch provider := p.Provider().(type) {
case *plan.UpstashRedisPlan:
return describeUpstashRedisPlan(ctx, provider, org)
}
return descriptionNone, nil
}
func describeUpstashRedisPlan(ctx context.Context, p *plan.UpstashRedisPlan, org *fly.Organization) (string, error) {
plan, err := redis.DeterminePlan(ctx, org)
if err != nil {
return "<plan not found, this is an error>", fmt.Errorf("redis plan not found: %w", err)
}
evictionStatus := lo.Ternary(p.Eviction, "enabled", "disabled")
return fmt.Sprintf("%s Plan: %s Max Data Size, eviction %s", plan.DisplayName, plan.MaxDataSize, evictionStatus), nil
}