diff --git a/demo/supervisord.conf b/demo/supervisord.conf index 439637d5d..61eb3e01d 100644 --- a/demo/supervisord.conf +++ b/demo/supervisord.conf @@ -23,7 +23,7 @@ stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 [program:karma] -command=/karma --config.dir /etc/ +command=/karma --config.file /etc/karma.yaml autorestart=true stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 426d4eaf0..97ed7f2a6 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -8,22 +8,15 @@ it needs to have `.yaml` extension. Custom filename and directory can be passed via command line flags or environment variables: -- `--config.file` flag or `CONFIG_FILE` env variable - name of the config file - to load (without extension). -- `--config.dir` flag or `CONFIG_DIR` env variable - directory where config file - can be found. +- `--config.file` flag or `CONFIG_FILE` env variable - path to the config file Example with flags: - karma --config.file example --config.dir ./docs/ + karma --config.file docs/example.yaml Example with environment variables: - CONFIG_FILE="example" CONFIG_DIR="./docs/" karma - -Example using both: - - CONFIG_FILE="example" karma --config.dir ./docs/ + CONFIG_FILE="docs/example.yaml" ### Alertmanagers diff --git a/internal/config/config.go b/internal/config/config.go index a1b7885dd..339915bbb 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -3,7 +3,6 @@ package config import ( "bufio" "bytes" - "path" "strings" "time" @@ -40,10 +39,7 @@ func init() { pflag.StringSlice("annotations.visible", []string{}, "List of annotations that are visible by default") - pflag.String("config.dir", ".", - "Directory with configuration file to read") - pflag.String("config.file", "karma", - "Name of the configuration file to read") + pflag.String("config.path", "", "Full path to the configuration file") pflag.Bool("debug", false, "Enable debug mode") @@ -105,21 +101,18 @@ func (config *configSchema) Read() { log.Errorf("Failed to bind sentry.private config key to the SENTRY_DSN env variable: %s", err) } - configFile := v.GetString("config.file") - configDir := v.GetString("config.dir") v.SetConfigType("yaml") - v.SetConfigName(configFile) - v.AddConfigPath(configDir) - log.Infof("Reading configuration file %s.yaml", path.Join(configDir, configFile)) + configPath := v.GetString("config.path") + if configPath != "" { + log.Infof("Reading configuration file %s", configPath) + v.SetConfigFile(configPath) + } + err = v.ReadInConfig() if v.ConfigFileUsed() != "" && err != nil { log.Fatal(err) } - if v.ConfigFileUsed() != "" { - log.Infof("Config file used: %s", v.ConfigFileUsed()) - } - config.Alertmanager.Servers = []alertmanagerConfig{} config.Alertmanager.Interval = v.GetDuration("alertmanager.interval") config.Annotations.Default.Hidden = v.GetBool("annotations.default.hidden") diff --git a/internal/config/config_test.go b/internal/config/config_test.go index f851a16cb..4db06d920 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -24,7 +24,6 @@ func resetEnv() { "ANNOTATIONS_DEFAULT_HIDDEN", "ANNOTATIONS_HIDDEN", "ANNOTATIONS_VISIBLE", - "CONFIG_DIR", "CONFIG_FILE", "DEBUG", "FILTERS_DEFAULT",