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

Plug in the new config #2411

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 0 additions & 12 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,6 @@ func resolvePathForTheFlagsInContext(c *cli.Context) (err error) {
return
}

// resolveConfigFilePaths resolves the config file paths specified in the config file.
func resolveConfigFilePaths(mountConfig *config.MountConfig) (err error) {
// Resolve cache-dir path
resolvedPath, err := resolveFilePath(string(mountConfig.CacheDir), "cache-dir")
mountConfig.CacheDir = resolvedPath
if err != nil {
return
}

return
}

// Add the flags accepted by run to the supplied flag set, returning the
// variables into which the flags will parse.
func populateFlags(c *cli.Context) (flags *flagStorage, err error) {
Expand Down
21 changes: 0 additions & 21 deletions cmd/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,27 +298,6 @@ func (t *FlagsTest) TestResolvePathForTheFlagsInContext() {
assert.Equal(t.T(), nil, err)
}

func (t *FlagsTest) Test_resolveConfigFilePaths() {
mountConfig := &config.MountConfig{}
mountConfig.CacheDir = "~/cache-dir"

err := resolveConfigFilePaths(mountConfig)

assert.Equal(t.T(), nil, err)
homeDir, err := os.UserHomeDir()
assert.Equal(t.T(), nil, err)
assert.EqualValues(t.T(), filepath.Join(homeDir, "cache-dir"), mountConfig.CacheDir)
}

func (t *FlagsTest) Test_resolveConfigFilePaths_WithoutSettingPaths() {
mountConfig := &config.MountConfig{}

err := resolveConfigFilePaths(mountConfig)

assert.Equal(t.T(), nil, err)
assert.EqualValues(t.T(), "", mountConfig.CacheDir)
}

func (t *FlagsTest) Test_KernelListCacheTtlSecs() {
args := []string{
"--kernel-list-cache-ttl-secs=-1",
Expand Down
21 changes: 9 additions & 12 deletions cmd/legacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,31 +256,28 @@ func runCLIApp(c *cli.Context) (err error) {
return fmt.Errorf("error resolving flags and configs: %w", err)
}

bucketName, mountPoint, err := populateArgs(c.Args())
if err != nil {
return
}

return Mount(newConfig, bucketName, mountPoint)
}

func Mount(newConfig *cfg.Config, bucketName, mountPoint string) (err error) {
// Ideally this call to SetLogFormat (which internally creates a new defaultLogger)
// should be set as an else to the 'if flags.Foreground' check below, but currently
// that means the logs generated by resolveConfigFilePaths below don't honour
// the user-provided log-format.
logger.SetLogFormat(newConfig.Logging.Format)

err = resolveConfigFilePaths(mountConfig)
if err != nil {
return fmt.Errorf("Resolving path: %w", err)
}

if newConfig.Foreground {
err = logger.InitLogFile(newConfig.Logging)
if err != nil {
return fmt.Errorf("init log file: %w", err)
}
}

var bucketName string
var mountPoint string
bucketName, mountPoint, err = populateArgs(c.Args())
if err != nil {
return
}

logger.Infof("Start gcsfuse/%s for app %q using mount point: %s\n", getVersion(), newConfig.AppName, mountPoint)

// Log mount-config and the CLI flags in the log-file.
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"strings"

"github.com/googlecloudplatform/gcsfuse/v2/cfg"
"github.com/googlecloudplatform/gcsfuse/v2/cmd"
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger"
)
Expand Down Expand Up @@ -68,9 +67,9 @@ func main() {
defer logPanic()
// Make logging output better.
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
if strings.ToLower(os.Getenv("ENABLE_GCSFUSE_VIPER_CONFIG")) == "true" {
if strings.ToLower(os.Getenv("ENABLE_GCSFUSE_VIPER_CONFIG")) == "false" {
// TODO: implement the mount logic instead of simply returning nil.
rootCmd, err := cmd.NewRootCmd(func(*cfg.Config, string, string) error { return nil })
rootCmd, err := cmd.NewRootCmd(cmd.Mount)
if err != nil {
log.Fatalf("Error occurred while creating the root command: %v", err)
}
Expand Down
Loading