@@ -15,6 +15,7 @@ import (
1515 "github.com/superfly/flyctl/internal/flapsutil"
1616 "github.com/superfly/flyctl/internal/flyutil"
1717 mach "github.com/superfly/flyctl/internal/machine"
18+ "github.com/superfly/flyctl/internal/uiex"
1819 "github.com/superfly/flyctl/internal/watch"
1920
2021 "github.com/superfly/fly-go/flaps"
@@ -38,15 +39,16 @@ const (
3839)
3940
4041type Launcher struct {
41- client flyutil.Client
42+ client flyutil.Client
43+ flapsClient flapsutil.FlapsClient
4244}
4345
4446type CreateClusterInput struct {
4547 AppName string
4648 ConsulURL string
4749 ImageRef string
4850 InitialClusterSize int
49- Organization * fly .Organization
51+ Organization * uiex .Organization
5052 Password string
5153 Region string
5254 VolumeSize * int
@@ -66,9 +68,10 @@ type CreateClusterInput struct {
6668 RestoreTargetInclusive bool
6769}
6870
69- func NewLauncher (client flyutil.Client ) * Launcher {
71+ func NewLauncher (client flyutil.Client , flapsClient flapsutil. FlapsClient ) * Launcher {
7072 return & Launcher {
71- client : client ,
73+ client : client ,
74+ flapsClient : flapsClient ,
7275 }
7376}
7477
@@ -91,10 +94,17 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu
9194 config .Autostart = true
9295 }
9396
94- app , err := l .createApp (ctx , config )
97+ fmt .Println ("Creating app..." )
98+
99+ app , err := l .flapsClient .CreateApp (ctx , flaps.CreateAppRequest {
100+ Name : config .AppName ,
101+ Org : config .Organization .RawSlug ,
102+ AppRoleID : "postgres_cluster" ,
103+ })
95104 if err != nil {
96105 return err
97106 }
107+
98108 // In case the user hasn't specified a name, use the app name generated by the API
99109 config .AppName = app .Name
100110
@@ -112,10 +122,13 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu
112122 config .ImageRef = imageRef
113123 }
114124
115- var addr * fly. IPAddress
125+ var addr * flaps. IPAssignment
116126
117127 if config .Manager == ReplicationManager {
118- addr , err = l .client .AllocateIPAddress (ctx , config .AppName , "private_v6" , config .Region , config .Organization , "" )
128+ addr , err = l .flapsClient .AssignIP (ctx , config .AppName , flaps.AssignIPRequest {
129+ Type : "private_v6" ,
130+ Organization : config .Organization .RawSlug ,
131+ })
119132 if err != nil {
120133 return err
121134 }
@@ -130,8 +143,8 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu
130143 }
131144
132145 flapsClient , err := flapsutil .NewClientWithOptions (ctx , flaps.NewClientOpts {
133- AppCompact : app ,
134- AppName : app .Name ,
146+ AppData : app ,
147+ AppName : app .Name ,
135148 })
136149 if err != nil {
137150 return err
@@ -297,7 +310,7 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu
297310 fmt .Fprintf (io .Out , " Password: %s\n " , secrets ["OPERATOR_PASSWORD" ])
298311 fmt .Fprintf (io .Out , " Hostname: %s.internal\n " , config .AppName )
299312 if addr != nil {
300- fmt .Fprintf (io .Out , " Flycast: %s\n " , addr .Address )
313+ fmt .Fprintf (io .Out , " Flycast: %s\n " , addr .IP )
301314 }
302315 fmt .Fprintf (io .Out , " Proxy port: 5432\n " )
303316 fmt .Fprintf (io .Out , " Postgres port: 5433\n " )
@@ -391,41 +404,6 @@ func (l *Launcher) getPostgresConfig(config *CreateClusterInput) *fly.MachineCon
391404 return & machineConfig
392405}
393406
394- func (l * Launcher ) createApp (ctx context.Context , config * CreateClusterInput ) (* fly.AppCompact , error ) {
395- fmt .Println ("Creating app..." )
396- appInput := fly.CreateAppInput {
397- OrganizationID : config .Organization .ID ,
398- Name : config .AppName ,
399- PreferredRegion : & config .Region ,
400- AppRoleID : "postgres_cluster" ,
401- }
402-
403- app , err := l .client .CreateApp (ctx , appInput )
404- if err != nil {
405- return nil , err
406- }
407-
408- f , err := flapsutil .NewClientWithOptions (ctx , flaps.NewClientOpts {AppName : app .Name })
409- if err != nil {
410- return nil , err
411- } else if err := f .WaitForApp (ctx , app .Name ); err != nil {
412- return nil , err
413- }
414-
415- return & fly.AppCompact {
416- ID : app .ID ,
417- Name : app .Name ,
418- Status : app .Status ,
419- Deployed : app .Deployed ,
420- Hostname : app .Hostname ,
421- AppURL : app .AppURL ,
422- Organization : & fly.OrganizationBasic {
423- ID : app .Organization .ID ,
424- Slug : app .Organization .Slug ,
425- },
426- }, nil
427- }
428-
429407func (l * Launcher ) setSecrets (ctx context.Context , config * CreateClusterInput ) (map [string ]string , error ) {
430408 flapsClient := flapsutil .ClientFromContext (ctx )
431409 if flapsClient == nil {
@@ -475,7 +453,7 @@ func (l *Launcher) setSecrets(ctx context.Context, config *CreateClusterInput) (
475453 validHours := 876600
476454
477455 app := fly.App {Name : config .AppName }
478- cert , err := l .client .IssueSSHCertificate (ctx , config .Organization , []string {"root" , "fly" , "postgres" }, []string {app .Name }, & validHours , pub )
456+ cert , err := l .client .IssueSSHCertificate (ctx , config .Organization . ID , []string {"root" , "fly" , "postgres" }, []string {app .Name }, & validHours , pub )
479457 if err != nil {
480458 return nil , err
481459 }
0 commit comments