make sure to set relevant config entries correctly (#17485)

Bonus: also allow skipping keys properly.
This commit is contained in:
Harshavardhana 2023-06-22 10:04:02 -07:00 committed by GitHub
parent 82ce78a17c
commit 74759b05a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 17 deletions

View File

@ -176,14 +176,11 @@ func (sCfg *Config) UnmarshalJSON(data []byte) error {
// LookupConfig - lookup api config and override with valid environment settings if any.
func LookupConfig(kvs config.KVS) (cfg Config, err error) {
// remove this since we have removed this already.
kvs.Delete(apiReadyDeadline)
kvs.Delete("extend_list_cache_life")
kvs.Delete(apiReplicationWorkers)
kvs.Delete(apiReplicationFailedWorkers)
if err = config.CheckValidKeys(config.APISubSys, kvs, DefaultKVS); err != nil {
return cfg, err
deprecatedKeys := []string{
apiReadyDeadline,
"extend_list_cache_life",
apiReplicationWorkers,
apiReplicationFailedWorkers,
}
disableODirect := env.Get(EnvAPIDisableODirect, kvs.Get(apiDisableODirect)) == config.EnableOn
@ -196,6 +193,16 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
RootAccess: rootAccess,
}
corsAllowOrigin := strings.Split(env.Get(EnvAPICorsAllowOrigin, kvs.Get(apiCorsAllowOrigin)), ",")
if len(corsAllowOrigin) == 0 {
corsAllowOrigin = []string{"*"} // defaults to '*'
}
cfg.CorsAllowOrigin = corsAllowOrigin
if err = config.CheckValidKeys(config.APISubSys, kvs, DefaultKVS, deprecatedKeys...); err != nil {
return cfg, err
}
// Check environment variables parameters
requestsMax, err := strconv.Atoi(env.Get(EnvAPIRequestsMax, kvs.GetWithDefault(apiRequestsMax, DefaultKVS)))
if err != nil {
@ -219,12 +226,6 @@ func LookupConfig(kvs config.KVS) (cfg Config, err error) {
}
cfg.ClusterDeadline = clusterDeadline
corsAllowOrigin := strings.Split(env.Get(EnvAPICorsAllowOrigin, kvs.Get(apiCorsAllowOrigin)), ",")
if len(corsAllowOrigin) == 0 {
corsAllowOrigin = []string{"*"} // defaults to '*'
}
cfg.CorsAllowOrigin = corsAllowOrigin
remoteTransportDeadline, err := time.ParseDuration(env.Get(EnvAPIRemoteTransportDeadline, kvs.GetWithDefault(apiRemoteTransportDeadline, DefaultKVS)))
if err != nil {
return cfg, err

View File

@ -598,7 +598,7 @@ func LookupSite(siteKV KVS, regionKV KVS) (s Site, err error) {
// CheckValidKeys - checks if inputs KVS has the necessary keys,
// returns error if it find extra or superflous keys.
func CheckValidKeys(subSys string, kv KVS, validKVS KVS) error {
func CheckValidKeys(subSys string, kv KVS, validKVS KVS, deprecatedKeys ...string) error {
nkv := KVS{}
for _, kv := range kv {
// Comment is a valid key, its also fully optional
@ -607,6 +607,16 @@ func CheckValidKeys(subSys string, kv KVS, validKVS KVS) error {
if kv.Key == Comment {
continue
}
var skip bool
for _, deprecatedKey := range deprecatedKeys {
if kv.Key == deprecatedKey {
skip = true
break
}
}
if skip {
continue
}
if _, ok := validKVS.Lookup(kv.Key); !ok {
nkv = append(nkv, kv)
}

View File

@ -281,9 +281,11 @@ func DefaultParityBlocks(drive int) int {
func LookupConfig(kvs config.KVS, setDriveCount int) (cfg Config, err error) {
cfg = Config{}
kvs.Delete("dma")
deprecatedKeys := []string{
"dma",
}
if err = config.CheckValidKeys(config.StorageClassSubSys, kvs, DefaultKVS); err != nil {
if err = config.CheckValidKeys(config.StorageClassSubSys, kvs, DefaultKVS, deprecatedKeys...); err != nil {
return Config{}, err
}