Skip to content

Commit

Permalink
Modularize config factory
Browse files Browse the repository at this point in the history
  • Loading branch information
N-o-Z committed Jan 15, 2025
1 parent 06312c7 commit 28f6f39
Show file tree
Hide file tree
Showing 7 changed files with 679 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cmd/lakefs-loadtest/cmd/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
nanoid "github.com/matoous/go-nanoid/v2"
"github.com/schollz/progressbar/v3"
"github.com/spf13/cobra"
configfactory "github.com/treeverse/lakefs/modules/config/factory"
"github.com/treeverse/lakefs/pkg/catalog"
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/kv"
"github.com/treeverse/lakefs/pkg/kv/kvparams"
"github.com/treeverse/lakefs/pkg/logging"
Expand Down Expand Up @@ -50,10 +50,12 @@ var entryCmd = &cobra.Command{

ctx := cmd.Context()

conf, err := config.NewConfig("")
confInterface, err := configfactory.BuildConfig("")
if err != nil {
fmt.Printf("config: %s\n", err)
}
conf := confInterface.BaseConfig()

err = conf.Validate()
if err != nil {
fmt.Printf("invalid config: %s\n", err)
Expand Down
9 changes: 6 additions & 3 deletions cmd/lakefs/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
configfactory "github.com/treeverse/lakefs/modules/config/factory"

Check failure on line 14 in cmd/lakefs/cmd/root.go

View workflow job for this annotation

GitHub Actions / Run Go tests

no required module provides package github.com/treeverse/lakefs/modules/config/factory; to add it:

Check failure on line 14 in cmd/lakefs/cmd/root.go

View workflow job for this annotation

GitHub Actions / Analyze

no required module provides package github.com/treeverse/lakefs/modules/config/factory; to add it:
"github.com/treeverse/lakefs/pkg/block"
"github.com/treeverse/lakefs/pkg/config"
"github.com/treeverse/lakefs/pkg/kv/local"
Expand Down Expand Up @@ -52,6 +53,8 @@ func init() {
rootCmd.PersistentFlags().Bool(config.QuickstartConfiguration, false, "Use lakeFS quickstart configuration")
}

// TODO (niro): All this validation logic should be in the OSS config package

func validateQuickstartEnv(cfg *config.Config) {
if (cfg.Database.Type != local.DriverName && cfg.Database.Type != mem.DriverName) || cfg.Blockstore.Type != block.BlockstoreTypeLocal {
_, _ = fmt.Fprint(os.Stderr, "\nFATAL: quickstart mode can only run with local settings\n")
Expand Down Expand Up @@ -85,15 +88,15 @@ func newConfig() (*config.Config, error) {
name = configurations[idx]
}

cfg, err := config.NewConfig(name)
cfg, err := configfactory.BuildConfig(name)
if err != nil {
return nil, err
}

if name == config.QuickstartConfiguration {
validateQuickstartEnv(cfg)
validateQuickstartEnv(cfg.BaseConfig())
}
return cfg, nil
return cfg.BaseConfig(), nil
}

func loadConfig() *config.Config {
Expand Down
7 changes: 7 additions & 0 deletions modules/config/factory/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package factory

import "github.com/treeverse/lakefs/pkg/config"

func BuildConfig(cfgType string) (config.Interface, error) {
return config.NewConfig(cfgType)
}
3 changes: 3 additions & 0 deletions modules/config/factory/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/treeverse/lakefs/modules/config/factory

go 1.23
6 changes: 6 additions & 0 deletions modules/config/factory/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.23

use (
.
../../..
)
639 changes: 639 additions & 0 deletions modules/config/factory/go.work.sum

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,18 @@ type Database struct {
} `mapstructure:"cosmosdb"`
}

// ApproximateOwnership configures an approximate ("mostly correct") ownership.
// ApproximatelyCorrectOwnership configures an approximate ("mostly correct") ownership.
type ApproximatelyCorrectOwnership struct {
Enabled bool `mapstructure:"enabled"`
Refresh time.Duration `mapstructure:"refresh"`
Acquire time.Duration `mapstructure:"acquire"`
}

type Interface interface {
BaseConfig() *Config
StorageConfig() interface{}
}

// Config - Output struct of configuration, used to validate. If you read a key using a viper accessor
// rather than accessing a field of this struct, that key will *not* be validated. So don't
// do that.
Expand Down Expand Up @@ -621,3 +626,11 @@ func (c *Config) UISnippets() []apiparams.CodeSnippet {
}
return snippets
}

func (c *Config) BaseConfig() *Config {
return c
}

func (c *Config) StorageConfig() interface{} {
return c.Blockstore
}

0 comments on commit 28f6f39

Please sign in to comment.