Skip to content

Commit fb0862a

Browse files
committed
Cleanup
1 parent 14d199b commit fb0862a

File tree

2 files changed

+42
-48
lines changed

2 files changed

+42
-48
lines changed

internal/flypg/node.go

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ func (n *Node) Init(ctx context.Context) error {
131131
// Initiate a restore
132132
if os.Getenv("FLY_RESTORED_FROM") != "" {
133133
// Check to see if there's an active restore.
134-
isRestore, err := isActiveRestore()
134+
active, err := isRestoreActive()
135135
if err != nil {
136136
return err
137137
}
138138

139-
if isRestore {
139+
if active {
140140
if err := Restore(ctx, n); err != nil {
141141
return fmt.Errorf("failed to issue restore: %s", err)
142142
}
@@ -204,7 +204,7 @@ func (n *Node) Init(ctx context.Context) error {
204204
}
205205
}
206206

207-
err := WriteSSHKey()
207+
err := writeSSHKey()
208208
if err != nil {
209209
return fmt.Errorf("failed initialize ssh. %v", err)
210210
}
@@ -227,12 +227,10 @@ func (n *Node) Init(ctx context.Context) error {
227227

228228
if !clusterInitialized {
229229
// Initialize ourselves as the primary.
230-
fmt.Println("Initializing postgres")
231230
if err := n.initializePG(); err != nil {
232231
return fmt.Errorf("failed to initialize postgres %s", err)
233232
}
234233

235-
fmt.Println("Setting default HBA")
236234
if err := n.setDefaultHBA(); err != nil {
237235
return fmt.Errorf("failed updating pg_hba.conf: %s", err)
238236
}
@@ -249,7 +247,6 @@ func (n *Node) Init(ctx context.Context) error {
249247
}
250248
}
251249

252-
fmt.Println("Initializing Postgres configuration")
253250
if err := n.configurePostgres(store); err != nil {
254251
return fmt.Errorf("failed to configure postgres: %s", err)
255252
}
@@ -261,44 +258,6 @@ func (n *Node) Init(ctx context.Context) error {
261258
return nil
262259
}
263260

264-
func WriteSSHKey() error {
265-
err := os.Mkdir("/data/.ssh", 0700)
266-
if err != nil && !os.IsExist(err) {
267-
return err
268-
}
269-
270-
key := os.Getenv("SSH_KEY")
271-
272-
keyFile, err := os.Create("/data/.ssh/id_rsa")
273-
if err != nil {
274-
return err
275-
}
276-
defer keyFile.Close()
277-
_, err = keyFile.Write([]byte(key))
278-
if err != nil {
279-
return err
280-
}
281-
282-
cert := os.Getenv("SSH_CERT")
283-
284-
certFile, err := os.Create("/data/.ssh/id_rsa-cert.pub")
285-
if err != nil {
286-
return err
287-
}
288-
defer certFile.Close()
289-
_, err = certFile.Write([]byte(cert))
290-
if err != nil {
291-
return err
292-
}
293-
294-
err = setSSHOwnership()
295-
if err != nil {
296-
return err
297-
}
298-
299-
return nil
300-
}
301-
302261
// PostInit are operations that should be executed against a running Postgres on boot.
303262
func (n *Node) PostInit(ctx context.Context) error {
304263
if ZombieLockExists() {
@@ -545,17 +504,14 @@ func (n *Node) isPGInitialized() bool {
545504
}
546505

547506
func (n *Node) configure(ctx context.Context, store *state.Store) error {
548-
fmt.Println("Initializing internal config")
549507
if err := n.configureInternal(store); err != nil {
550508
return fmt.Errorf("failed to set internal config: %s", err)
551509
}
552510

553-
fmt.Println("Initializing replication manager")
554511
if err := n.configureRepmgr(store); err != nil {
555512
return fmt.Errorf("failed to configure repmgr config: %s", err)
556513
}
557514

558-
fmt.Println("Initializing pgbouncer")
559515
if err := n.configurePGBouncer(store); err != nil {
560516
return fmt.Errorf("failed to configure pgbouncer: %s", err)
561517
}
@@ -569,6 +525,44 @@ func (n *Node) configure(ctx context.Context, store *state.Store) error {
569525
return nil
570526
}
571527

528+
func writeSSHKey() error {
529+
err := os.Mkdir("/data/.ssh", 0700)
530+
if err != nil && !os.IsExist(err) {
531+
return err
532+
}
533+
534+
key := os.Getenv("SSH_KEY")
535+
536+
keyFile, err := os.Create("/data/.ssh/id_rsa")
537+
if err != nil {
538+
return err
539+
}
540+
defer keyFile.Close()
541+
_, err = keyFile.Write([]byte(key))
542+
if err != nil {
543+
return err
544+
}
545+
546+
cert := os.Getenv("SSH_CERT")
547+
548+
certFile, err := os.Create("/data/.ssh/id_rsa-cert.pub")
549+
if err != nil {
550+
return err
551+
}
552+
defer certFile.Close()
553+
_, err = certFile.Write([]byte(cert))
554+
if err != nil {
555+
return err
556+
}
557+
558+
err = setSSHOwnership()
559+
if err != nil {
560+
return err
561+
}
562+
563+
return nil
564+
}
565+
572566
func (n *Node) configureInternal(store *state.Store) error {
573567
if err := n.InternalConfig.initialize(); err != nil {
574568
return fmt.Errorf("failed to initialize internal config: %s", err)

internal/flypg/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Restore(ctx context.Context, node *Node) error {
8585
return nil
8686
}
8787

88-
func isActiveRestore() (bool, error) {
88+
func isRestoreActive() (bool, error) {
8989
if _, err := os.Stat(restoreLockFile); err == nil {
9090
val, err := os.ReadFile(restoreLockFile)
9191
if err != nil {

0 commit comments

Comments
 (0)