Helm values picked by Sloop (#133)
* fixed helm issuues being picked up by file * changed formatting of code * added unit tests * added unit tests * changes to test files * added panic tests * changes tests, moved test files * removed returning error * removed an extra line to change email * updated data files to not reflect default values
This commit is contained in:
Родитель
ace7752827
Коммит
45e0fdca04
|
@ -8,15 +8,16 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/salesforce/sloop/pkg/sloop/webserver"
|
"github.com/salesforce/sloop/pkg/sloop/webserver"
|
||||||
)
|
)
|
||||||
|
@ -136,10 +137,10 @@ func Init() *SloopConfig {
|
||||||
}
|
}
|
||||||
if configFilename != "" {
|
if configFilename != "" {
|
||||||
newConfig = loadFromFile(configFilename)
|
newConfig = loadFromFile(configFilename)
|
||||||
|
} else {
|
||||||
|
registerFlags(flag.CommandLine, newConfig)
|
||||||
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
registerFlags(flag.CommandLine, newConfig)
|
|
||||||
flag.Parse()
|
|
||||||
// Set this to the correct value in case we got it from envVar
|
// Set this to the correct value in case we got it from envVar
|
||||||
newConfig.ConfigFile = configFilename
|
newConfig.ConfigFile = configFilename
|
||||||
return newConfig
|
return newConfig
|
||||||
|
@ -172,16 +173,26 @@ func (c *SloopConfig) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFromFile(filename string) *SloopConfig {
|
func loadFromFile(filename string) *SloopConfig {
|
||||||
yamlFile, err := ioutil.ReadFile(filename)
|
var config SloopConfig
|
||||||
|
|
||||||
|
configFile, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to read %v. %v", filename, err))
|
panic(fmt.Sprintf("failed to read %v. %v", filename, err))
|
||||||
}
|
}
|
||||||
var config SloopConfig
|
|
||||||
err = yaml.Unmarshal(yamlFile, &config)
|
if strings.Contains(filename, ".yaml") {
|
||||||
|
err = yaml.Unmarshal(configFile, &config)
|
||||||
|
} else if strings.Contains(filename, ".json") {
|
||||||
|
err = json.Unmarshal(configFile, &config)
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("incorrect file format %v. Use json or yaml file type. ", filename))
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to unmarshal %v. %v", filename, err))
|
panic(fmt.Sprintf("failed to unmarshal %v. %v", filename, err))
|
||||||
}
|
}
|
||||||
return &config
|
return &config
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pre-parse flags and return config filename without side-effects
|
// Pre-parse flags and return config filename without side-effects
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_loadFromJSONFile_Success(t *testing.T) {
|
||||||
|
var expectedconfig SloopConfig
|
||||||
|
configfilename, _ := filepath.Abs("../testFiles/testconfig.json")
|
||||||
|
configFile, err := ioutil.ReadFile(configfilename)
|
||||||
|
err = json.Unmarshal(configFile, &expectedconfig)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
out_config := loadFromFile(configfilename)
|
||||||
|
assert.Equal(t, out_config, &expectedconfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_loadFromYAMLFile_Success(t *testing.T) {
|
||||||
|
var expectedconfig SloopConfig
|
||||||
|
configfilename, _ := filepath.Abs("../testFiles/testconfig.yaml")
|
||||||
|
configFile, err := ioutil.ReadFile(configfilename)
|
||||||
|
err = yaml.Unmarshal(configFile, &expectedconfig)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
out_config := loadFromFile(configfilename)
|
||||||
|
assert.Equal(t, out_config, &expectedconfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_loadFromTxtFile_shouldPanic(t *testing.T) {
|
||||||
|
configfilename, _ := filepath.Abs("../testFiles/testconfig.txt")
|
||||||
|
assert.Panics(t, func() { loadFromFile(configfilename) }, "The code did not panic")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_loadFromNoFile_shouldPanic(t *testing.T) {
|
||||||
|
configfilename, _ := filepath.Abs("../testconfig.json")
|
||||||
|
assert.Panics(t, func() { loadFromFile(configfilename) }, "The code did not panic")
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"ConfigFile": "",
|
||||||
|
"leftBarLinks": null,
|
||||||
|
"resourceLinks": null,
|
||||||
|
"disableKubeWatch": false,
|
||||||
|
"kubeWatchResyncInterval": 1800000000000,
|
||||||
|
"webfilesPath": "./pkg/sloop/webfiles",
|
||||||
|
"bindAddress": "",
|
||||||
|
"port": 8080,
|
||||||
|
"storeRoot": "./data",
|
||||||
|
"maxLookBack": 1209600000000000,
|
||||||
|
"maxDiskMb": 32768,
|
||||||
|
"debugPlaybackFile": "",
|
||||||
|
"debugRecordFile": "",
|
||||||
|
"deletionBatchSize": 1000,
|
||||||
|
"mockBadger": false,
|
||||||
|
"disableStoreManager": false,
|
||||||
|
"cleanupFrequency": 1800000000000,
|
||||||
|
"keepMinorNodeUpdates": false,
|
||||||
|
"defaultNamespace": "default",
|
||||||
|
"defaultKind": "Pod",
|
||||||
|
"defaultLookback": "6h",
|
||||||
|
"context": "",
|
||||||
|
"displayContext": "",
|
||||||
|
"apiServerHost": "",
|
||||||
|
"watchCrds": true,
|
||||||
|
"threshold for GC": 0.8,
|
||||||
|
"restoreDatabaseFile": "",
|
||||||
|
"badgerDiscardRatio": 0.99,
|
||||||
|
"badgerVLogGCFreq": 60000000000,
|
||||||
|
"badgerMaxTableSize": 0,
|
||||||
|
"badgerLevelOneSize": 0,
|
||||||
|
"badgerLevSizeMultiplier": 0,
|
||||||
|
"badgerKeepL0InMemory": true,
|
||||||
|
"badgerVLogFileSize": 0,
|
||||||
|
"badgerVLogMaxEntries": 200000,
|
||||||
|
"badgerUseLSMOnlyOptions": true,
|
||||||
|
"badgerEnableEventLogging": false,
|
||||||
|
"badgerNumOfCompactors": 0,
|
||||||
|
"badgerSyncWrites": true,
|
||||||
|
"badgerVLogFileIOMapping": false,
|
||||||
|
"badgerVLogTruncate": true,
|
||||||
|
"enableDeleteKeys": false
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"ConfigFile": "",
|
||||||
|
"leftBarLinks": null,
|
||||||
|
"resourceLinks": null,
|
||||||
|
"disableKubeWatch": true,
|
||||||
|
"kubeWatchResyncInterval": 1800000000000,
|
||||||
|
"webfilesPath": "./pkg/sloop/webfiles",
|
||||||
|
"bindAddress": "",
|
||||||
|
"port": 8080,
|
||||||
|
"storeRoot": "./data",
|
||||||
|
"maxLookBack": 1209600000000000,
|
||||||
|
"maxDiskMb": 32768,
|
||||||
|
"debugPlaybackFile": "",
|
||||||
|
"debugRecordFile": "",
|
||||||
|
"deletionBatchSize": 1000,
|
||||||
|
"mockBadger": false,
|
||||||
|
"disableStoreManager": true,
|
||||||
|
"cleanupFrequency": 1800000000000,
|
||||||
|
"keepMinorNodeUpdates": true,
|
||||||
|
"defaultNamespace": "_all",
|
||||||
|
"defaultKind": "Pod",
|
||||||
|
"defaultLookback": "12h",
|
||||||
|
"context": "",
|
||||||
|
"displayContext": "",
|
||||||
|
"apiServerHost": "",
|
||||||
|
"watchCrds": true,
|
||||||
|
"threshold for GC": 0.8,
|
||||||
|
"restoreDatabaseFile": "",
|
||||||
|
"badgerDiscardRatio": 0.92,
|
||||||
|
"badgerVLogGCFreq": 60000000000,
|
||||||
|
"badgerMaxTableSize": 0,
|
||||||
|
"badgerLevelOneSize": 0,
|
||||||
|
"badgerLevSizeMultiplier": 0,
|
||||||
|
"badgerKeepL0InMemory": true,
|
||||||
|
"badgerVLogFileSize": 0,
|
||||||
|
"badgerVLogMaxEntries": 200000,
|
||||||
|
"badgerUseLSMOnlyOptions": true,
|
||||||
|
"badgerEnableEventLogging": true,
|
||||||
|
"badgerNumOfCompactors": 0,
|
||||||
|
"badgerSyncWrites": true,
|
||||||
|
"badgerVLogFileIOMapping": false,
|
||||||
|
"badgerVLogTruncate": true,
|
||||||
|
"enableDeleteKeys": false
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
---
|
||||||
|
ConfigFile: ''
|
||||||
|
leftBarLinks:
|
||||||
|
resourceLinks:
|
||||||
|
disableKubeWatch: false
|
||||||
|
kubeWatchResyncInterval: 1800000000000
|
||||||
|
webfilesPath: "./pkg/sloop/webfiles"
|
||||||
|
bindAddress: ''
|
||||||
|
port: 8080
|
||||||
|
storeRoot: "./data"
|
||||||
|
maxLookBack: 1109600000000000
|
||||||
|
maxDiskMb: 32768
|
||||||
|
debugPlaybackFile: ''
|
||||||
|
debugRecordFile: ''
|
||||||
|
deletionBatchSize: 1000
|
||||||
|
mockBadger: false
|
||||||
|
disableStoreManager: false
|
||||||
|
cleanupFrequency: 1800000000000
|
||||||
|
keepMinorNodeUpdates: false
|
||||||
|
defaultNamespace: default
|
||||||
|
defaultKind: Pod
|
||||||
|
defaultLookback: 3h
|
||||||
|
context: ''
|
||||||
|
displayContext: ''
|
||||||
|
apiServerHost: ''
|
||||||
|
watchCrds: true
|
||||||
|
threshold for GC: 0.75
|
||||||
|
restoreDatabaseFile: ''
|
||||||
|
badgerDiscardRatio: 0.80
|
||||||
|
badgerVLogGCFreq: 60000000000
|
||||||
|
badgerMaxTableSize: 0
|
||||||
|
badgerLevelOneSize: 0
|
||||||
|
badgerLevSizeMultiplier: 0
|
||||||
|
badgerKeepL0InMemory: true
|
||||||
|
badgerVLogFileSize: 0
|
||||||
|
badgerVLogMaxEntries: 150000
|
||||||
|
badgerUseLSMOnlyOptions: true
|
||||||
|
badgerEnableEventLogging: false
|
||||||
|
badgerNumOfCompactors: 0
|
||||||
|
badgerSyncWrites: true
|
||||||
|
badgerVLogFileIOMapping: true
|
||||||
|
badgerVLogTruncate: true
|
||||||
|
enableDeleteKeys: false
|
Загрузка…
Ссылка в новой задаче