mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
Remove safe mode for invalid entries in config (#8650)
The approach is that now safe mode is only invoked when we cannot read the config or under some catastrophic situations, but not under situations when config entries are invalid or unreachable. This allows for maximum availability for MinIO and not fail on our users unlike most of our historical releases.
This commit is contained in:
@@ -32,23 +32,13 @@ import (
|
||||
|
||||
// Error config error type
|
||||
type Error struct {
|
||||
Kind ErrorKind
|
||||
Err string
|
||||
Err string
|
||||
}
|
||||
|
||||
// ErrorKind config error kind
|
||||
type ErrorKind int8
|
||||
|
||||
// Various error kinds.
|
||||
const (
|
||||
ContinueKind ErrorKind = iota + 1
|
||||
SafeModeKind
|
||||
)
|
||||
|
||||
// Errorf - formats according to a format specifier and returns
|
||||
// the string as a value that satisfies error of type config.Error
|
||||
func Errorf(errKind ErrorKind, format string, a ...interface{}) error {
|
||||
return Error{Kind: errKind, Err: fmt.Sprintf(format, a...)}
|
||||
func Errorf(format string, a ...interface{}) error {
|
||||
return Error{Err: fmt.Sprintf(format, a...)}
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
@@ -366,9 +356,9 @@ func LookupCreds(kv KVS) (auth.Credentials, error) {
|
||||
if err := CheckValidKeys(CredentialsSubSys, kv, DefaultCredentialKVS); err != nil {
|
||||
return auth.Credentials{}, err
|
||||
}
|
||||
accessKey := env.Get(EnvAccessKey, kv.Get(AccessKey))
|
||||
secretKey := env.Get(EnvSecretKey, kv.Get(SecretKey))
|
||||
if accessKey == "" && secretKey == "" {
|
||||
accessKey := kv.Get(AccessKey)
|
||||
secretKey := kv.Get(SecretKey)
|
||||
if accessKey == "" || secretKey == "" {
|
||||
accessKey = auth.DefaultAccessKey
|
||||
secretKey = auth.DefaultSecretKey
|
||||
}
|
||||
@@ -390,7 +380,7 @@ func LookupRegion(kv KVS) (string, error) {
|
||||
if validRegionRegex.MatchString(region) {
|
||||
return region, nil
|
||||
}
|
||||
return "", Errorf(SafeModeKind,
|
||||
return "", Errorf(
|
||||
"region '%s' is invalid, expected simple characters such as [us-east-1, myregion...]",
|
||||
region)
|
||||
}
|
||||
@@ -414,7 +404,6 @@ func CheckValidKeys(subSys string, kv KVS, validKVS KVS) error {
|
||||
}
|
||||
if len(nkv) > 0 {
|
||||
return Errorf(
|
||||
ContinueKind,
|
||||
"found invalid keys (%s) for '%s' sub-system, use 'mc admin config reset myminio %s' to fix invalid keys", nkv.String(), subSys, subSys)
|
||||
}
|
||||
return nil
|
||||
@@ -447,15 +436,15 @@ type Targets []Target
|
||||
// GetKVS - get kvs from specific subsystem.
|
||||
func (c Config) GetKVS(s string, defaultKVS map[string]KVS) (Targets, error) {
|
||||
if len(s) == 0 {
|
||||
return nil, Errorf(SafeModeKind, "input cannot be empty")
|
||||
return nil, Errorf("input cannot be empty")
|
||||
}
|
||||
inputs := strings.Fields(s)
|
||||
if len(inputs) > 1 {
|
||||
return nil, Errorf(SafeModeKind, "invalid number of arguments %s", s)
|
||||
return nil, Errorf("invalid number of arguments %s", s)
|
||||
}
|
||||
subSystemValue := strings.SplitN(inputs[0], SubSystemSeparator, 2)
|
||||
if len(subSystemValue) == 0 {
|
||||
return nil, Errorf(SafeModeKind, "invalid number of arguments %s", s)
|
||||
return nil, Errorf("invalid number of arguments %s", s)
|
||||
}
|
||||
found := SubSystems.Contains(subSystemValue[0])
|
||||
if !found {
|
||||
@@ -464,18 +453,18 @@ func (c Config) GetKVS(s string, defaultKVS map[string]KVS) (Targets, error) {
|
||||
found = !SubSystems.FuncMatch(strings.HasPrefix, subSystemValue[0]).IsEmpty() && len(subSystemValue) == 1
|
||||
}
|
||||
if !found {
|
||||
return nil, Errorf(SafeModeKind, "unknown sub-system %s", s)
|
||||
return nil, Errorf("unknown sub-system %s", s)
|
||||
}
|
||||
|
||||
targets := Targets{}
|
||||
subSysPrefix := subSystemValue[0]
|
||||
if len(subSystemValue) == 2 {
|
||||
if len(subSystemValue[1]) == 0 {
|
||||
return nil, Errorf(SafeModeKind, "sub-system target '%s' cannot be empty", s)
|
||||
return nil, Errorf("sub-system target '%s' cannot be empty", s)
|
||||
}
|
||||
kvs, ok := c[subSysPrefix][subSystemValue[1]]
|
||||
if !ok {
|
||||
return nil, Errorf(SafeModeKind, "sub-system target '%s' doesn't exist", s)
|
||||
return nil, Errorf("sub-system target '%s' doesn't exist", s)
|
||||
}
|
||||
for _, kv := range defaultKVS[subSysPrefix] {
|
||||
_, ok = kvs.Lookup(kv.Key)
|
||||
@@ -527,15 +516,15 @@ func (c Config) GetKVS(s string, defaultKVS map[string]KVS) (Targets, error) {
|
||||
// DelKVS - delete a specific key.
|
||||
func (c Config) DelKVS(s string) error {
|
||||
if len(s) == 0 {
|
||||
return Errorf(SafeModeKind, "input arguments cannot be empty")
|
||||
return Errorf("input arguments cannot be empty")
|
||||
}
|
||||
inputs := strings.Fields(s)
|
||||
if len(inputs) > 1 {
|
||||
return Errorf(SafeModeKind, "invalid number of arguments %s", s)
|
||||
return Errorf("invalid number of arguments %s", s)
|
||||
}
|
||||
subSystemValue := strings.SplitN(inputs[0], SubSystemSeparator, 2)
|
||||
if len(subSystemValue) == 0 {
|
||||
return Errorf(SafeModeKind, "invalid number of arguments %s", s)
|
||||
return Errorf("invalid number of arguments %s", s)
|
||||
}
|
||||
if !SubSystems.Contains(subSystemValue[0]) {
|
||||
// Unknown sub-system found try to remove it anyways.
|
||||
@@ -546,13 +535,13 @@ func (c Config) DelKVS(s string) error {
|
||||
subSys := subSystemValue[0]
|
||||
if len(subSystemValue) == 2 {
|
||||
if len(subSystemValue[1]) == 0 {
|
||||
return Errorf(SafeModeKind, "sub-system target '%s' cannot be empty", s)
|
||||
return Errorf("sub-system target '%s' cannot be empty", s)
|
||||
}
|
||||
tgt = subSystemValue[1]
|
||||
}
|
||||
_, ok := c[subSys][tgt]
|
||||
if !ok {
|
||||
return Errorf(SafeModeKind, "sub-system %s already deleted", s)
|
||||
return Errorf("sub-system %s already deleted", s)
|
||||
}
|
||||
delete(c[subSys], tgt)
|
||||
return nil
|
||||
@@ -573,23 +562,23 @@ func (c Config) Clone() Config {
|
||||
// SetKVS - set specific key values per sub-system.
|
||||
func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error {
|
||||
if len(s) == 0 {
|
||||
return Errorf(SafeModeKind, "input arguments cannot be empty")
|
||||
return Errorf("input arguments cannot be empty")
|
||||
}
|
||||
inputs := strings.SplitN(s, KvSpaceSeparator, 2)
|
||||
if len(inputs) <= 1 {
|
||||
return Errorf(SafeModeKind, "invalid number of arguments '%s'", s)
|
||||
return Errorf("invalid number of arguments '%s'", s)
|
||||
}
|
||||
subSystemValue := strings.SplitN(inputs[0], SubSystemSeparator, 2)
|
||||
if len(subSystemValue) == 0 {
|
||||
return Errorf(SafeModeKind, "invalid number of arguments %s", s)
|
||||
return Errorf("invalid number of arguments %s", s)
|
||||
}
|
||||
|
||||
if !SubSystems.Contains(subSystemValue[0]) {
|
||||
return Errorf(SafeModeKind, "unknown sub-system %s", s)
|
||||
return Errorf("unknown sub-system %s", s)
|
||||
}
|
||||
|
||||
if SubSystemsSingleTargets.Contains(subSystemValue[0]) && len(subSystemValue) == 2 {
|
||||
return Errorf(SafeModeKind, "sub-system '%s' only supports single target", subSystemValue[0])
|
||||
return Errorf("sub-system '%s' only supports single target", subSystemValue[0])
|
||||
}
|
||||
|
||||
var kvs = KVS{}
|
||||
@@ -612,7 +601,7 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error {
|
||||
kvs.Set(prevK, madmin.SanitizeValue(kv[1]))
|
||||
continue
|
||||
}
|
||||
return Errorf(SafeModeKind, "key '%s', cannot have empty value", kv[0])
|
||||
return Errorf("key '%s', cannot have empty value", kv[0])
|
||||
}
|
||||
|
||||
tgt := Default
|
||||
@@ -662,7 +651,7 @@ func (c Config) SetKVS(s string, defaultKVS map[string]KVS) error {
|
||||
// Return error only if the
|
||||
// key is enabled, for state=off
|
||||
// let it be empty.
|
||||
return Errorf(SafeModeKind,
|
||||
return Errorf(
|
||||
"'%s' is not optional for '%s' sub-system, please check '%s' documentation",
|
||||
hkv.Key, subSys, subSys)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user