Skip to content

Commit

Permalink
Wire the new configuration into mount pipeline. (#2414)
Browse files Browse the repository at this point in the history
* Wire the new configuration into mount pipeline.

Trigger the mount pipeline when Viper-based new configuration is
enabled.

* Set up profile handlers for the new config.
  • Loading branch information
kislaykishore authored Aug 29, 2024
1 parent 6a197d6 commit 1957032
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 55 deletions.
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
25 changes: 7 additions & 18 deletions cmd/legacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger"
"github.com/googlecloudplatform/gcsfuse/v2/internal/monitor"
"github.com/googlecloudplatform/gcsfuse/v2/internal/mount"
"github.com/googlecloudplatform/gcsfuse/v2/internal/perf"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage"
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/storageutil"
"github.com/googlecloudplatform/gcsfuse/v2/internal/util"
Expand Down Expand Up @@ -255,32 +254,27 @@ func runCLIApp(c *cli.Context) (err error) {
if err != nil {
return fmt.Errorf("error resolving flags and configs: %w", err)
}
var bucketName, mountPoint string
if bucketName, mountPoint, err = populateArgs(c.Args()); err != nil {
return err
}
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 Expand Up @@ -478,11 +472,6 @@ func run() (err error) {
}

func ExecuteLegacyMain() {
// Set up profiling handlers.
go perf.HandleCPUProfileSignals()
go perf.HandleMemoryProfileSignals()

// Run.
err := run()
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import (
"github.com/spf13/viper"
)

type mountFn func(c *cfg.Config, bucketName, mountPoint string) error

// NewRootCmd accepts the mountFn that it executes with the parsed configuration
func NewRootCmd(mountFn func(*cfg.Config, string, string) error) (*cobra.Command, error) {
func NewRootCmd(m mountFn) (*cobra.Command, error) {
var (
configObj cfg.Config
cfgFile string
Expand All @@ -48,7 +50,7 @@ of Cloud Storage FUSE, see https://cloud.google.com/storage/docs/gcs-fuse.`,
if err != nil {
return fmt.Errorf("error occurred while extracting the bucket and mountPoint: %w", err)
}
return mountFn(&configObj, bucket, mountPoint)
return m(&configObj, bucket, mountPoint)
},
}
initConfig := func() {
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"os"
"strings"

"github.com/googlecloudplatform/gcsfuse/v2/cfg"
"github.com/googlecloudplatform/gcsfuse/v2/cmd"
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger"
"github.com/googlecloudplatform/gcsfuse/v2/internal/perf"
)

func logPanic() {
Expand Down Expand Up @@ -68,9 +68,12 @@ func main() {
defer logPanic()
// Make logging output better.
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
// Set up profiling handlers.
go perf.HandleCPUProfileSignals()
go perf.HandleMemoryProfileSignals()
if strings.ToLower(os.Getenv("ENABLE_GCSFUSE_VIPER_CONFIG")) == "true" {
// 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

0 comments on commit 1957032

Please sign in to comment.