MM-21285: Remove environment overrides before config broadcast (#13527)
While sending the config broadcast message across a cluster, we would include the environment overrides in the config. We fix this by exposing a config config store method to remove the overrides, and then calling that before saving the config across the cluster. Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
62f77d81aa
Коммит
ecb41c6eb5
@@ -395,6 +395,7 @@ func (a *App) SaveConfig(newCfg *model.Config, sendConfigChangeClusterMessage bo
|
||||
}
|
||||
|
||||
if a.Cluster != nil {
|
||||
newCfg = a.Srv.configStore.RemoveEnvironmentOverrides(newCfg)
|
||||
err := a.Cluster.ConfigChanged(oldCfg, newCfg, sendConfigChangeClusterMessage)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -77,7 +77,7 @@ func (cs *commonStore) set(newCfg *model.Config, allowEnvironmentOverrides bool,
|
||||
}
|
||||
}
|
||||
|
||||
if err := persist(cs.removeEnvOverrides(newCfg)); err != nil {
|
||||
if err := persist(cs.RemoveEnvironmentOverrides(newCfg)); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to persist")
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func (cs *commonStore) validate(cfg *model.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// removeEnvOverrides returns a new config without the given environment overrides.
|
||||
func (cs *commonStore) removeEnvOverrides(cfg *model.Config) *model.Config {
|
||||
// RemoveEnvironmentOverrides returns a new config without the given environment overrides.
|
||||
func (cs *commonStore) RemoveEnvironmentOverrides(cfg *model.Config) *model.Config {
|
||||
return removeEnvOverrides(cfg, cs.configWithoutOverrides, cs.environmentOverrides)
|
||||
}
|
||||
|
||||
@@ -162,5 +162,17 @@ func TestConfigEnvironmentOverrides(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRemoveEnvironmentOverrides(t *testing.T) {
|
||||
os.Setenv("MM_SERVICESETTINGS_SITEURL", "http://overridden.ca")
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_SITEURL")
|
||||
|
||||
base, err := config.NewMemoryStore()
|
||||
require.NoError(t, err)
|
||||
oldCfg := base.Get()
|
||||
assert.Equal(t, "http://overridden.ca", *oldCfg.ServiceSettings.SiteURL)
|
||||
newCfg := base.RemoveEnvironmentOverrides(oldCfg)
|
||||
assert.Equal(t, "", *newCfg.ServiceSettings.SiteURL)
|
||||
}
|
||||
|
||||
func newBool(b bool) *bool { return &b }
|
||||
func newString(s string) *string { return &s }
|
||||
|
||||
@@ -20,6 +20,10 @@ type Store interface {
|
||||
// GetEnvironmentOverrides fetches the configuration fields overridden by environment variables.
|
||||
GetEnvironmentOverrides() map[string]interface{}
|
||||
|
||||
// RemoveEnvironmentOverrides returns a new config without the environment
|
||||
// overrides
|
||||
RemoveEnvironmentOverrides(cfg *model.Config) *model.Config
|
||||
|
||||
// Set replaces the current configuration in its entirety and updates the backing store.
|
||||
Set(*model.Config) (*model.Config, error)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user