mirror of
https://github.com/minio/minio.git
synced 2026-02-05 02:10:14 -05:00
Export command prints turned-off sub-sys as comments (#8594)
This PR also tries to - Preserve the order of keys printed in export command - Fix cache to be enabled with _STATE env to keep backward compatibility
This commit is contained in:
committed by
kannappanr
parent
2ab8d5e47f
commit
794eb54da8
42
cmd/config/cache/config.go
vendored
42
cmd/config/cache/config.go
vendored
@@ -61,22 +61,26 @@ func (cfg *Config) UnmarshalJSON(data []byte) (err error) {
|
||||
return errors.New("config quota value should not be null or negative")
|
||||
}
|
||||
|
||||
if _, err = parseCacheDrives(_cfg.Drives); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = parseCacheExcludes(_cfg.Exclude); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parses given cacheDrivesEnv and returns a list of cache drives.
|
||||
func parseCacheDrives(drives []string) ([]string, error) {
|
||||
func parseCacheDrives(drives string) ([]string, error) {
|
||||
var drivesSlice []string
|
||||
if len(drives) == 0 {
|
||||
return drives, nil
|
||||
return drivesSlice, nil
|
||||
}
|
||||
|
||||
drivesSlice = strings.Split(drives, cacheDelimiterLegacy)
|
||||
if len(drivesSlice) == 1 && drivesSlice[0] == drives {
|
||||
drivesSlice = strings.Split(drives, cacheDelimiter)
|
||||
}
|
||||
|
||||
var endpoints []string
|
||||
for _, d := range drives {
|
||||
for _, d := range drivesSlice {
|
||||
if len(d) == 0 {
|
||||
return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("cache dir cannot be an empty path")
|
||||
}
|
||||
if ellipses.HasEllipses(d) {
|
||||
s, err := parseCacheDrivePaths(d)
|
||||
if err != nil {
|
||||
@@ -89,9 +93,6 @@ func parseCacheDrives(drives []string) ([]string, error) {
|
||||
}
|
||||
|
||||
for _, d := range endpoints {
|
||||
if len(d) == 0 {
|
||||
return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("cache dir cannot be an empty path")
|
||||
}
|
||||
if !filepath.IsAbs(d) {
|
||||
return nil, config.ErrInvalidCacheDrivesValue(nil).Msg("cache dir should be absolute path: %s", d)
|
||||
}
|
||||
@@ -114,8 +115,18 @@ func parseCacheDrivePaths(arg string) (ep []string, err error) {
|
||||
}
|
||||
|
||||
// Parses given cacheExcludesEnv and returns a list of cache exclude patterns.
|
||||
func parseCacheExcludes(excludes []string) ([]string, error) {
|
||||
for _, e := range excludes {
|
||||
func parseCacheExcludes(excludes string) ([]string, error) {
|
||||
var excludesSlice []string
|
||||
if len(excludes) == 0 {
|
||||
return excludesSlice, nil
|
||||
}
|
||||
|
||||
excludesSlice = strings.Split(excludes, cacheDelimiterLegacy)
|
||||
if len(excludesSlice) == 1 && excludesSlice[0] == excludes {
|
||||
excludesSlice = strings.Split(excludes, cacheDelimiter)
|
||||
}
|
||||
|
||||
for _, e := range excludesSlice {
|
||||
if len(e) == 0 {
|
||||
return nil, config.ErrInvalidCacheExcludesValue(nil).Msg("cache exclude path (%s) cannot be empty", e)
|
||||
}
|
||||
@@ -123,5 +134,6 @@ func parseCacheExcludes(excludes []string) ([]string, error) {
|
||||
return nil, config.ErrInvalidCacheExcludesValue(nil).Msg("cache exclude pattern (%s) cannot start with / as prefix", e)
|
||||
}
|
||||
}
|
||||
return excludes, nil
|
||||
|
||||
return excludesSlice, nil
|
||||
}
|
||||
|
||||
11
cmd/config/cache/config_test.go
vendored
11
cmd/config/cache/config_test.go
vendored
@@ -19,7 +19,6 @@ package cache
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -61,6 +60,11 @@ func TestParseCacheDrives(t *testing.T) {
|
||||
expectedPatterns []string
|
||||
success bool
|
||||
}{"/home/drive1;/home/drive2;/home/drive3", []string{"/home/drive1", "/home/drive2", "/home/drive3"}, true})
|
||||
testCases = append(testCases, struct {
|
||||
driveStr string
|
||||
expectedPatterns []string
|
||||
success bool
|
||||
}{"/home/drive1,/home/drive2,/home/drive3", []string{"/home/drive1", "/home/drive2", "/home/drive3"}, true})
|
||||
testCases = append(testCases, struct {
|
||||
driveStr string
|
||||
expectedPatterns []string
|
||||
@@ -73,7 +77,7 @@ func TestParseCacheDrives(t *testing.T) {
|
||||
}{"/home/drive{1..3}", []string{}, false})
|
||||
}
|
||||
for i, testCase := range testCases {
|
||||
drives, err := parseCacheDrives(strings.Split(testCase.driveStr, cacheDelimiterLegacy))
|
||||
drives, err := parseCacheDrives(testCase.driveStr)
|
||||
if err != nil && testCase.success {
|
||||
t.Errorf("Test %d: Expected success but failed instead %s", i+1, err)
|
||||
}
|
||||
@@ -102,11 +106,12 @@ func TestParseCacheExclude(t *testing.T) {
|
||||
|
||||
// valid input
|
||||
{"bucket1/*;*.png;images/trip/barcelona/*", []string{"bucket1/*", "*.png", "images/trip/barcelona/*"}, true},
|
||||
{"bucket1/*,*.png,images/trip/barcelona/*", []string{"bucket1/*", "*.png", "images/trip/barcelona/*"}, true},
|
||||
{"bucket1", []string{"bucket1"}, true},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
excludes, err := parseCacheExcludes(strings.Split(testCase.excludeStr, cacheDelimiterLegacy))
|
||||
excludes, err := parseCacheExcludes(testCase.excludeStr)
|
||||
if err != nil && testCase.success {
|
||||
t.Errorf("Test %d: Expected success but failed instead %s", i+1, err)
|
||||
}
|
||||
|
||||
56
cmd/config/cache/lookup.go
vendored
56
cmd/config/cache/lookup.go
vendored
@@ -19,7 +19,6 @@ package cache
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/minio/cmd/config"
|
||||
"github.com/minio/minio/pkg/env"
|
||||
@@ -84,42 +83,43 @@ func LookupConfig(kvs config.KVS) (Config, error) {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
// Check if cache is explicitly disabled
|
||||
stateBool, err := config.ParseBool(env.Get(EnvCacheState, kvs.Get(config.State)))
|
||||
if err != nil {
|
||||
// Parsing failures happen due to empty KVS, ignore it.
|
||||
if kvs.Empty() {
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
drives := env.Get(EnvCacheDrives, kvs.Get(Drives))
|
||||
if stateBool {
|
||||
if len(drives) == 0 {
|
||||
return cfg, config.Error("'drives' key cannot be empty if you wish to enable caching")
|
||||
}
|
||||
}
|
||||
if len(drives) == 0 {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
cfg.Drives, err = parseCacheDrives(strings.Split(drives, cacheDelimiter))
|
||||
if err != nil {
|
||||
cfg.Drives, err = parseCacheDrives(strings.Split(drives, cacheDelimiterLegacy))
|
||||
if len(drives) > 0 {
|
||||
// Drives is not-empty means user wishes to enable this explicitly, but
|
||||
// check if ENV is set to false to disable caching.
|
||||
stateBool, err := config.ParseBool(env.Get(EnvCacheState, config.StateOn))
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if !stateBool {
|
||||
return cfg, nil
|
||||
}
|
||||
} else {
|
||||
// Check if cache is explicitly disabled
|
||||
stateBool, err := config.ParseBool(env.Get(EnvCacheState, kvs.Get(config.State)))
|
||||
if err != nil {
|
||||
if kvs.Empty() {
|
||||
return cfg, nil
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
if stateBool {
|
||||
return cfg, config.Error("'drives' key cannot be empty to enable caching")
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
cfg.Drives, err = parseCacheDrives(drives)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
cfg.Enabled = true
|
||||
if excludes := env.Get(EnvCacheExclude, kvs.Get(Exclude)); excludes != "" {
|
||||
cfg.Exclude, err = parseCacheExcludes(strings.Split(excludes, cacheDelimiter))
|
||||
cfg.Exclude, err = parseCacheExcludes(excludes)
|
||||
if err != nil {
|
||||
cfg.Exclude, err = parseCacheExcludes(strings.Split(excludes, cacheDelimiterLegacy))
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user