Skip to content

Commit

Permalink
Add flycast ips for flex-dbs
Browse files Browse the repository at this point in the history
  • Loading branch information
DAlperin committed Feb 2, 2023
1 parent c6e9821 commit 4796e52
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions flypg/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu
// In case the user hasn't specified a name, use the app name generated by the API
config.AppName = app.Name

var addr *api.IPAddress

if config.Manager == ReplicationManager {
addr, err = l.client.AllocateIPAddress(ctx, config.AppName, "private_v6", config.Region, config.Organization, "")
if err != nil {
return err
}
}

secrets, err := l.setSecrets(ctx, config)
if err != nil {
return err
Expand Down Expand Up @@ -108,6 +117,41 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu
machineConf.Image = imageRef
}

if config.Manager == ReplicationManager {
var bouncerPort int32 = 5432
var pgPort int32 = 5433
machineConf.Services = []api.MachineService{
{
Protocol: "tcp",
InternalPort: 5432,
Ports: []api.MachinePort{
{
Port: &bouncerPort,
Handlers: []string{
"pg_tls",
},
ForceHttps: false,
},
},
Concurrency: nil,
},
{
Protocol: "tcp",
InternalPort: 5433,
Ports: []api.MachinePort{
{
Port: &pgPort,
Handlers: []string{
"pg_tls",
},
ForceHttps: false,
},
},
Concurrency: nil,
},
}
}

snapshot := config.SnapshotID
verb := "Provisioning"

Expand Down Expand Up @@ -181,10 +225,17 @@ func (l *Launcher) LaunchMachinesPostgres(ctx context.Context, config *CreateClu

connStr := fmt.Sprintf("postgres://postgres:%s@%s.internal:5432\n", secrets["OPERATOR_PASSWORD"], config.AppName)

if config.Manager == ReplicationManager && addr != nil {
connStr = fmt.Sprintf("postgres://postgres:%s@[%s]:5432\n", secrets["OPERATOR_PASSWORD"], addr.Address)
}

fmt.Fprintf(io.Out, "Postgres cluster %s created\n", config.AppName)
fmt.Fprintf(io.Out, " Username: postgres\n")
fmt.Fprintf(io.Out, " Password: %s\n", secrets["OPERATOR_PASSWORD"])
fmt.Fprintf(io.Out, " Hostname: %s.internal\n", config.AppName)
if addr != nil {
fmt.Fprintf(io.Out, " Flycast: %s\n", addr.Address)
}
fmt.Fprintf(io.Out, " Proxy port: 5432\n")
fmt.Fprintf(io.Out, " Postgres port: 5433\n")
fmt.Fprintf(io.Out, " Connection string: %s\n", connStr)
Expand Down

0 comments on commit 4796e52

Please sign in to comment.