Skip to content

Commit 717beb1

Browse files
committed
need to handle errors
1 parent a948535 commit 717beb1

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pkg/flypg/node.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func NewNode() (*Node, error) {
6464
}
6565
node.PrivateIP = ipv6.String()
6666

67-
machineID := os.Getenv("FLY_ALLOC_ID")
6867
// Generate a random, reconstructable signed int32
68+
machineID := os.Getenv("FLY_ALLOC_ID")
6969
seed := binary.LittleEndian.Uint64([]byte(machineID))
7070
rand.Seed(int64(seed))
7171
node.ID = rand.Int31()
@@ -119,11 +119,6 @@ func (n *Node) Init() error {
119119
return fmt.Errorf("failed to query current primary: %s", err)
120120
}
121121

122-
// Initialize PGBouncer
123-
if err := n.PGBouncer.configure(primaryIP); err != nil {
124-
return err
125-
}
126-
127122
// Writes or updates the replication manager configuration.
128123
if err := initializeRepmgr(*n); err != nil {
129124
fmt.Printf("Failed to initialize replmgr: %s\n", err.Error())
@@ -176,9 +171,10 @@ func (n *Node) Init() error {
176171
return fmt.Errorf("failed to configure postgres %s", err)
177172
}
178173

179-
fmt.Println("Configuring pgbouncer auth")
180-
if err := n.PGBouncer.configureAuth(); err != nil {
181-
return fmt.Errorf("failed to configure pgbouncer auth %s", err)
174+
// Initialize PGBouncer
175+
fmt.Println("Configuring PGBouncer")
176+
if err := n.PGBouncer.configure(primaryIP); err != nil {
177+
return err
182178
}
183179

184180
return nil

pkg/flypg/pgbouncer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ func (p *PGBouncer) configure(primary string) error {
6262
}
6363
}
6464

65-
p.configureAuth()
66-
p.ConfigurePrimary(primary, false)
65+
if err := p.configureAuth(); err != nil {
66+
return fmt.Errorf("failed to configure pgbouncer auth. %s", err)
67+
}
68+
69+
if err := p.ConfigurePrimary(primary, false); err != nil {
70+
return fmt.Errorf("failed to configure pgbouncer primary. %s", err)
71+
}
6772

6873
return nil
6974
}

0 commit comments

Comments
 (0)