mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-13 02:20:15 +00:00
* Update config.go, tapConfig.go, and models.go * WIP * Update go.sum * Update tapRunner.go * Update tap.go * WIP * WIP * Update Dockerfile, main.go, and 2 more files... * WIP * Update utils.go, tapClusterResourceManagement.go, and utils.go * Merge branch 'develop' * Update metadata_controller.go, utils.go, and 2 more files... * Update main.go, utils.go, and tapRunner.go * Update tapRunner.go * Update config.go, config.go, and models.go * Update main.go, main.go, and stats_provider_test.go * Update provider.go * bug fixes * Update main.go, metadata_controller.go, and 13 more files... * Update metadata_controller.go, status_controller.go, and 4 more files... * Update main.go, config.go, and 3 more files... * Update tapRunner.go * Update config.go, stats_provider_test.go, and consts.go
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/up9inc/mizu/shared"
|
|
"github.com/up9inc/mizu/tap/api"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// these values are used when the config.json file is not present
|
|
const (
|
|
defaultMaxDatabaseSizeBytes int64 = 200 * 1000 * 1000
|
|
defaultRegexTarget string = ".*"
|
|
DefaultDatabasePath string = "./entries"
|
|
)
|
|
|
|
var Config *shared.MizuAgentConfig
|
|
|
|
func LoadConfig() error {
|
|
if Config != nil {
|
|
return nil
|
|
}
|
|
filePath := fmt.Sprintf("%s%s", shared.ConfigDirPath, shared.ConfigFileName)
|
|
|
|
content, err := ioutil.ReadFile(filePath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return applyDefaultConfig()
|
|
}
|
|
return err
|
|
}
|
|
|
|
if err = json.Unmarshal(content, &Config); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func applyDefaultConfig() error {
|
|
defaultConfig, err := getDefaultConfig()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
Config = defaultConfig
|
|
return nil
|
|
}
|
|
|
|
func getDefaultConfig() (*shared.MizuAgentConfig, error) {
|
|
regex, err := api.CompileRegexToSerializableRegexp(defaultRegexTarget)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &shared.MizuAgentConfig{
|
|
TapTargetRegex: *regex,
|
|
MaxDBSizeBytes: defaultMaxDatabaseSizeBytes,
|
|
AgentDatabasePath: DefaultDatabasePath,
|
|
DaemonMode: false,
|
|
}, nil
|
|
}
|