Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lakefs config.yaml align name and search order #2372

Merged
merged 7 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Unreleased - XXXX-XX-XX

- Add search locations to load lakeFS configuration. More information on https://docs.lakefs.io/reference/configuration (#2355)

## v0.48.0 - 2021-08-22

Expand Down
60 changes: 39 additions & 21 deletions cmd/lakefs/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"errors"
"fmt"
"os"
"path"
"strings"
"sync"

Expand Down Expand Up @@ -50,46 +52,62 @@ func init() {
func initConfig() {
logger := logging.Default().WithField("phase", "startup")
if cfgFile != "" {
logger.WithField("file", cfgFile).Info("configuration file")
logger.WithField("file", cfgFile).Info("Configuration file")
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
logger.Info("search for configuration file .lakefs")
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Search config in home directory with name ".lakefs" (without extension).
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".lakefs")
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AddConfigPath(path.Join(getHomeDir(), ".lakefs"))
viper.AddConfigPath("/etc/lakefs")
}

viper.SetEnvPrefix("LAKEFS")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config
// read in environment variables
viper.AutomaticEnv()

// If a config file is found, read it in.
// read configuration file
err := viper.ReadInConfig()
logger = logger.WithField("file", viper.ConfigFileUsed())

if err == nil {
logger.Info("loaded configuration from file")
} else if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
logger.WithError(err).Fatal("failed to read config file")
logger = logger.WithField("file", viper.ConfigFileUsed()) // should be called after SetConfigFile
var errFileNotFound viper.ConfigFileNotFoundError
if err != nil && !errors.As(err, &errFileNotFound) {
logger.WithError(err).Fatal("Failed to find a config file")
}
// fallback - try to load the previous supported $HOME/.lakefs.yaml
// if err is set it will be file-not-found based on previous check
nopcoder marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
fallbackCfgFile := path.Join(getHomeDir(), ".lakefs.yaml")
if cfgFile != fallbackCfgFile {
viper.SetConfigFile(fallbackCfgFile)
logger = logger.WithField("file", viper.ConfigFileUsed()) // should be called after SetConfigFile
err = viper.ReadInConfig()
if err != nil && !os.IsNotExist(err) {
logger.WithError(err).Fatal("Failed to read config file")
}
}
}

// setup config used by the executed command
cfg, err = config.NewConfig()
if err != nil {
logger.WithError(err).Fatal("load config")
logger.WithError(err).Fatal("Load config")
} else {
logger.Info("Config loaded")
}
err = cfg.Validate()
if err != nil {
logger.WithError(err).Fatal("invalid config")
logger.WithError(err).Fatal("Invalid config")
}
}

// getHomeDir find and return the home directory
func getHomeDir() string {
home, err := homedir.Dir()
if err != nil {
fmt.Println("Get home directory -", err)
os.Exit(1)
}
return home
}
6 changes: 3 additions & 3 deletions docs/deploy/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Here is a minimal example, but you can see the [reference](../reference/configur
<li><a href="#docker-tabs-2">Google Cloud</a></li>
<li><a href="#docker-tabs-3">Microsoft Azure</a></li>
</ul>
<div markdown="1" id="docker-tabs-1">
<div markdown="1" id="docker-tabs-1">
{% include_relative includes/aws-docker-config.md %}
</div>
<div markdown="1" id="docker-tabs-2">
Expand All @@ -45,8 +45,8 @@ Save the configuration file locally as `lakefs-config.yaml` and run the followin
docker run \
--name lakefs \
-p 8000:8000 \
-v $(pwd)/lakefs-config.yaml:/home/lakefs/.lakefs.yaml \
treeverse/lakefs:latest run
-v $(pwd)/lakefs-config.yaml:/etc/lakefs/config.yaml \
treeverse/lakefs:latest run --config /etc/lakefs/config.yaml
```

## Load balancing
Expand Down
11 changes: 10 additions & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ has_children: false

{% include toc.html %}

Configuring lakeFS is done using a yaml configuration file.
Configuring lakeFS is done using a yaml configuration file and/or environment variable.
The configuration file location can be set with the '--config' flag. If not specified, the the first file found in the following order will be used:
1. ./config.yaml
1. `$HOME`/lakefs/config.yaml
1. /etc/lakefs/config.yaml
1. `$HOME`/.lakefs.yaml

Configuration items can each be controlled by an environment variable. The variable name will have a prefix of *LAKEFS_*, followed by the name of the configuration, replacing every '.' with a '_'.
Example: `LAKEFS_LOGGING_LEVEL` controls `logging.format`.

This reference uses `.` to denote the nesting of values.

## Reference
Expand Down