mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Avoid config migration on every startup (#16278)
This commit is contained in:
parent
ed37b7a9d5
commit
b4f71362e9
@ -71,7 +71,7 @@ func (a adminAPIHandlers) DelConfigKVHandler(w http.ResponseWriter, r *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readServerConfig(ctx, objectAPI)
|
cfg, err := readServerConfig(ctx, objectAPI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
return
|
return
|
||||||
@ -142,7 +142,7 @@ func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Requ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readServerConfig(ctx, objectAPI)
|
cfg, err := readServerConfig(ctx, objectAPI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
return
|
return
|
||||||
@ -296,7 +296,7 @@ func (a adminAPIHandlers) RestoreConfigHistoryKVHandler(w http.ResponseWriter, r
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readServerConfig(ctx, objectAPI)
|
cfg, err := readServerConfig(ctx, objectAPI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -107,7 +107,7 @@ func (a adminAPIHandlers) addOrUpdateIDPHandler(ctx context.Context, w http.Resp
|
|||||||
cfgData = subSys + tgtSuffix + config.KvSpaceSeparator + string(reqBytes)
|
cfgData = subSys + tgtSuffix + config.KvSpaceSeparator + string(reqBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readServerConfig(ctx, objectAPI)
|
cfg, err := readServerConfig(ctx, objectAPI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
return
|
return
|
||||||
@ -408,7 +408,7 @@ func (a adminAPIHandlers) DeleteIdentityProviderCfg(w http.ResponseWriter, r *ht
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err := readServerConfig(ctx, objectAPI)
|
cfg, err := readServerConfig(ctx, objectAPI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
||||||
return
|
return
|
||||||
|
@ -2135,7 +2135,7 @@ func fetchHealthInfo(healthCtx context.Context, objectAPI ObjectLayer, query *ur
|
|||||||
|
|
||||||
getAndWriteMinioConfig := func() {
|
getAndWriteMinioConfig := func() {
|
||||||
if query.Get("minioconfig") == "true" {
|
if query.Get("minioconfig") == "true" {
|
||||||
config, err := readServerConfig(healthCtx, objectAPI)
|
config, err := readServerConfig(healthCtx, objectAPI, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
healthInfo.Minio.Config = madmin.MinioConfig{
|
healthInfo.Minio.Config = madmin.MinioConfig{
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
|
@ -782,13 +782,14 @@ func newSrvConfig(objAPI ObjectLayer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getValidConfig(objAPI ObjectLayer) (config.Config, error) {
|
func getValidConfig(objAPI ObjectLayer) (config.Config, error) {
|
||||||
return readServerConfig(GlobalContext, objAPI)
|
return readServerConfig(GlobalContext, objAPI, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadConfig - loads a new config from disk, overrides params
|
// loadConfig - loads a new config from disk, overrides params
|
||||||
// from env if found and valid
|
// from env if found and valid
|
||||||
func loadConfig(objAPI ObjectLayer) error {
|
// data is optional. If nil it will be loaded from backend.
|
||||||
srvCfg, err := getValidConfig(objAPI)
|
func loadConfig(objAPI ObjectLayer, data []byte) error {
|
||||||
|
srvCfg, err := readServerConfig(GlobalContext, objAPI, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func TestServerConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize server config.
|
// Initialize server config.
|
||||||
if err := loadConfig(objLayer); err != nil {
|
if err := loadConfig(objLayer, nil); err != nil {
|
||||||
t.Fatalf("Unable to initialize from updated config file %s", err)
|
t.Fatalf("Unable to initialize from updated config file %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2533,6 +2533,21 @@ func checkConfigVersion(objAPI ObjectLayer, configFile string, version string) (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if version == "kvs" {
|
||||||
|
// Check api config values are present.
|
||||||
|
var vcfg struct {
|
||||||
|
API struct {
|
||||||
|
E []struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
} `json:"_"`
|
||||||
|
} `json:"api"`
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(data, &vcfg); err != nil {
|
||||||
|
return false, nil, nil
|
||||||
|
}
|
||||||
|
return len(vcfg.API.E) > 0, data, nil
|
||||||
|
}
|
||||||
var versionConfig struct {
|
var versionConfig struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ func TestServerConfigMigrateV1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize server config and check again if everything is fine
|
// Initialize server config and check again if everything is fine
|
||||||
if err := loadConfig(objLayer); err != nil {
|
if err := loadConfig(objLayer, nil); err != nil {
|
||||||
t.Fatalf("Unable to initialize from updated config file %s", err)
|
t.Fatalf("Unable to initialize from updated config file %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ func TestServerConfigMigrateV2toV33(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize server config and check again if everything is fine
|
// Initialize server config and check again if everything is fine
|
||||||
if err := loadConfig(objLayer); err != nil {
|
if err := loadConfig(objLayer, nil); err != nil {
|
||||||
t.Fatalf("Unable to initialize from updated config file %s", err)
|
t.Fatalf("Unable to initialize from updated config file %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,30 +152,34 @@ func saveServerConfig(ctx context.Context, objAPI ObjectLayer, cfg interface{})
|
|||||||
return saveConfig(ctx, objAPI, configFile, data)
|
return saveConfig(ctx, objAPI, configFile, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readServerConfig(ctx context.Context, objAPI ObjectLayer) (config.Config, error) {
|
// data is optional. If nil it will be loaded from backend.
|
||||||
|
func readServerConfig(ctx context.Context, objAPI ObjectLayer, data []byte) (config.Config, error) {
|
||||||
srvCfg := config.New()
|
srvCfg := config.New()
|
||||||
configFile := path.Join(minioConfigPrefix, minioConfigFile)
|
var err error
|
||||||
data, err := readConfig(ctx, objAPI, configFile)
|
if len(data) == 0 {
|
||||||
if err != nil {
|
configFile := path.Join(minioConfigPrefix, minioConfigFile)
|
||||||
if errors.Is(err, errConfigNotFound) {
|
data, err = readConfig(ctx, objAPI, configFile)
|
||||||
lookupConfigs(srvCfg, objAPI)
|
|
||||||
return srvCfg, nil
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if GlobalKMS != nil && !utf8.Valid(data) {
|
|
||||||
data, err = config.DecryptBytes(GlobalKMS, data, kms.Context{
|
|
||||||
minioMetaBucket: path.Join(minioMetaBucket, configFile),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lookupConfigs(srvCfg, objAPI)
|
if errors.Is(err, errConfigNotFound) {
|
||||||
|
lookupConfigs(srvCfg, objAPI)
|
||||||
|
return srvCfg, nil
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if GlobalKMS != nil && !utf8.Valid(data) {
|
||||||
|
data, err = config.DecryptBytes(GlobalKMS, data, kms.Context{
|
||||||
|
minioMetaBucket: path.Join(minioMetaBucket, configFile),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lookupConfigs(srvCfg, objAPI)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
if err = json.Unmarshal(data, &srvCfg); err != nil {
|
if err := json.Unmarshal(data, &srvCfg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +216,15 @@ func initConfig(objAPI ObjectLayer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the config version is latest (kvs), if not migrate.
|
||||||
|
ok, data, err := checkConfigVersion(objAPI, path.Join(minioConfigPrefix, minioConfigFile), "kvs")
|
||||||
|
if err != nil && !errors.Is(err, errConfigNotFound) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return loadConfig(objAPI, data)
|
||||||
|
}
|
||||||
|
|
||||||
// Migrates ${HOME}/.minio/config.json or config.json.deprecated
|
// Migrates ${HOME}/.minio/config.json or config.json.deprecated
|
||||||
// to '<export_path>/.minio.sys/config/config.json'
|
// to '<export_path>/.minio.sys/config/config.json'
|
||||||
// ignore if the file doesn't exist.
|
// ignore if the file doesn't exist.
|
||||||
@ -232,5 +245,5 @@ func initConfig(objAPI ObjectLayer) error {
|
|||||||
return fmt.Errorf("migrateMinioSysConfigToKV: %w", err)
|
return fmt.Errorf("migrateMinioSysConfigToKV: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadConfig(objAPI)
|
return loadConfig(objAPI, nil)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user