Skip to content

Commit

Permalink
fly pg unregister hook: update for new node names
Browse files Browse the repository at this point in the history
  • Loading branch information
benwaffle committed Aug 13, 2024
1 parent 3c430bb commit d620d6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions flypg/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func (pc *Command) UpdateSettings(ctx context.Context, leaderIp string, config m
return nil
}

func (pc *Command) UnregisterMember(ctx context.Context, leaderIP string, standbyIP string) error {
payload := encodeCommand(standbyIP)
func (pc *Command) UnregisterMember(ctx context.Context, leaderIP string, standbyNodeName string) error {
payload := encodeCommand(standbyNodeName)
cmd := fmt.Sprintf("pg_unregister %s", payload)

resp, err := ssh.RunSSHCommand(ctx, pc.app, pc.dialer, leaderIP, cmd, ssh.DefaultSshUsername)
Expand Down
1 change: 1 addition & 0 deletions internal/command/machine/lifecycle_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func runOnDeletionHook(ctx context.Context, app *fly.AppCompact, machine *fly.Ma
if err := postgres.UnregisterMember(ctx, app, machine); err != nil {
fmt.Fprintln(io.Out, "(failed)")
fmt.Fprintf(io.Out, "failed to unregister postgres member: %v\n", err)
return
}
fmt.Fprintln(io.Out, "(success)")
}
Expand Down
8 changes: 6 additions & 2 deletions internal/command/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ func UnregisterMember(ctx context.Context, app *fly.AppCompact, machine *fly.Mac
return err
}

if err := cmd.UnregisterMember(ctx, leader.PrivateIP, machine.PrivateIP); err != nil {
return err
hostname := fmt.Sprintf("%s.vm.%s.internal", machine.ID, app.Name)

if err := cmd.UnregisterMember(ctx, leader.PrivateIP, hostname); err != nil {
if err2 := cmd.UnregisterMember(ctx, leader.PrivateIP, machine.PrivateIP); err2 != nil {
return err
}
}

return nil
Expand Down

0 comments on commit d620d6e

Please sign in to comment.