Skip to content

Commit 572e3f1

Browse files
authored
Merge pull request #39 from fly-apps/silly_config_mistake
Don't overwrite config if we aren't the primary 🤦🏼
2 parents 89cf65a + 2c76793 commit 572e3f1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/api/handle_admin.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ func (s *Server) handleUpdatePostgresSettings(w http.ResponseWriter, r *http.Req
5959
}
6060
defer close()
6161

62+
consul, err := state.NewStore()
63+
if err != nil {
64+
renderErr(w, err)
65+
return
66+
}
67+
6268
user := s.node.PGConfig.UserConfig()
6369

6470
var in map[string]interface{}
@@ -108,6 +114,12 @@ func (s *Server) handleUpdatePostgresSettings(w http.ResponseWriter, r *http.Req
108114
}}
109115
}
110116

117+
err = flypg.PushUserConfig(s.node.PGConfig, consul)
118+
if err != nil {
119+
renderErr(w, err)
120+
return
121+
}
122+
111123
renderJSON(w, res, http.StatusOK)
112124
}
113125

@@ -125,7 +137,7 @@ func (s *Server) handleApplyConfig(w http.ResponseWriter, r *http.Request) {
125137
return
126138
}
127139

128-
err = flypg.WriteUserConfig(s.node.PGConfig, consul)
140+
err = flypg.SyncUserConfig(s.node.PGConfig, consul)
129141
if err != nil {
130142
renderErr(w, err)
131143
return

pkg/flypg/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ func WriteUserConfig(c Config, consul *state.Store) error {
3535
return nil
3636
}
3737

38+
func PushUserConfig(c Config, consul *state.Store) error {
39+
if c.UserConfig() != nil {
40+
if err := pushToConsul(c, consul); err != nil {
41+
return fmt.Errorf("failed to write to consul: %s", err)
42+
}
43+
}
44+
return nil
45+
}
46+
3847
func SyncUserConfig(c Config, consul *state.Store) error {
3948
cfg, err := pullFromConsul(c, consul)
4049
if err != nil {

0 commit comments

Comments
 (0)