Skip to content

Commit 1957032

Browse files
Wire the new configuration into mount pipeline. (#2414)
* 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.
1 parent 6a197d6 commit 1957032

File tree

5 files changed

+16
-55
lines changed

5 files changed

+16
-55
lines changed

cmd/flags.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -573,18 +573,6 @@ func resolvePathForTheFlagsInContext(c *cli.Context) (err error) {
573573
return
574574
}
575575

576-
// resolveConfigFilePaths resolves the config file paths specified in the config file.
577-
func resolveConfigFilePaths(mountConfig *config.MountConfig) (err error) {
578-
// Resolve cache-dir path
579-
resolvedPath, err := resolveFilePath(string(mountConfig.CacheDir), "cache-dir")
580-
mountConfig.CacheDir = resolvedPath
581-
if err != nil {
582-
return
583-
}
584-
585-
return
586-
}
587-
588576
// Add the flags accepted by run to the supplied flag set, returning the
589577
// variables into which the flags will parse.
590578
func populateFlags(c *cli.Context) (flags *flagStorage, err error) {

cmd/flags_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -298,27 +298,6 @@ func (t *FlagsTest) TestResolvePathForTheFlagsInContext() {
298298
assert.Equal(t.T(), nil, err)
299299
}
300300

301-
func (t *FlagsTest) Test_resolveConfigFilePaths() {
302-
mountConfig := &config.MountConfig{}
303-
mountConfig.CacheDir = "~/cache-dir"
304-
305-
err := resolveConfigFilePaths(mountConfig)
306-
307-
assert.Equal(t.T(), nil, err)
308-
homeDir, err := os.UserHomeDir()
309-
assert.Equal(t.T(), nil, err)
310-
assert.EqualValues(t.T(), filepath.Join(homeDir, "cache-dir"), mountConfig.CacheDir)
311-
}
312-
313-
func (t *FlagsTest) Test_resolveConfigFilePaths_WithoutSettingPaths() {
314-
mountConfig := &config.MountConfig{}
315-
316-
err := resolveConfigFilePaths(mountConfig)
317-
318-
assert.Equal(t.T(), nil, err)
319-
assert.EqualValues(t.T(), "", mountConfig.CacheDir)
320-
}
321-
322301
func (t *FlagsTest) Test_KernelListCacheTtlSecs() {
323302
args := []string{
324303
"--kernel-list-cache-ttl-secs=-1",

cmd/legacy_main.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger"
3636
"github.com/googlecloudplatform/gcsfuse/v2/internal/monitor"
3737
"github.com/googlecloudplatform/gcsfuse/v2/internal/mount"
38-
"github.com/googlecloudplatform/gcsfuse/v2/internal/perf"
3938
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage"
4039
"github.com/googlecloudplatform/gcsfuse/v2/internal/storage/storageutil"
4140
"github.com/googlecloudplatform/gcsfuse/v2/internal/util"
@@ -255,32 +254,27 @@ func runCLIApp(c *cli.Context) (err error) {
255254
if err != nil {
256255
return fmt.Errorf("error resolving flags and configs: %w", err)
257256
}
257+
var bucketName, mountPoint string
258+
if bucketName, mountPoint, err = populateArgs(c.Args()); err != nil {
259+
return err
260+
}
261+
return Mount(newConfig, bucketName, mountPoint)
262+
}
258263

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

265-
err = resolveConfigFilePaths(mountConfig)
266-
if err != nil {
267-
return fmt.Errorf("Resolving path: %w", err)
268-
}
269-
270271
if newConfig.Foreground {
271272
err = logger.InitLogFile(newConfig.Logging)
272273
if err != nil {
273274
return fmt.Errorf("init log file: %w", err)
274275
}
275276
}
276277

277-
var bucketName string
278-
var mountPoint string
279-
bucketName, mountPoint, err = populateArgs(c.Args())
280-
if err != nil {
281-
return
282-
}
283-
284278
logger.Infof("Start gcsfuse/%s for app %q using mount point: %s\n", getVersion(), newConfig.AppName, mountPoint)
285279

286280
// Log mount-config and the CLI flags in the log-file.
@@ -478,11 +472,6 @@ func run() (err error) {
478472
}
479473

480474
func ExecuteLegacyMain() {
481-
// Set up profiling handlers.
482-
go perf.HandleCPUProfileSignals()
483-
go perf.HandleMemoryProfileSignals()
484-
485-
// Run.
486475
err := run()
487476
if err != nil {
488477
fmt.Fprintln(os.Stderr, err)

cmd/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"github.com/spf13/viper"
2525
)
2626

27+
type mountFn func(c *cfg.Config, bucketName, mountPoint string) error
28+
2729
// NewRootCmd accepts the mountFn that it executes with the parsed configuration
28-
func NewRootCmd(mountFn func(*cfg.Config, string, string) error) (*cobra.Command, error) {
30+
func NewRootCmd(m mountFn) (*cobra.Command, error) {
2931
var (
3032
configObj cfg.Config
3133
cfgFile string
@@ -48,7 +50,7 @@ of Cloud Storage FUSE, see https://cloud.google.com/storage/docs/gcs-fuse.`,
4850
if err != nil {
4951
return fmt.Errorf("error occurred while extracting the bucket and mountPoint: %w", err)
5052
}
51-
return mountFn(&configObj, bucket, mountPoint)
53+
return m(&configObj, bucket, mountPoint)
5254
},
5355
}
5456
initConfig := func() {

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
"os"
2525
"strings"
2626

27-
"github.com/googlecloudplatform/gcsfuse/v2/cfg"
2827
"github.com/googlecloudplatform/gcsfuse/v2/cmd"
2928
"github.com/googlecloudplatform/gcsfuse/v2/internal/logger"
29+
"github.com/googlecloudplatform/gcsfuse/v2/internal/perf"
3030
)
3131

3232
func logPanic() {
@@ -68,9 +68,12 @@ func main() {
6868
defer logPanic()
6969
// Make logging output better.
7070
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
71+
// Set up profiling handlers.
72+
go perf.HandleCPUProfileSignals()
73+
go perf.HandleMemoryProfileSignals()
7174
if strings.ToLower(os.Getenv("ENABLE_GCSFUSE_VIPER_CONFIG")) == "true" {
7275
// TODO: implement the mount logic instead of simply returning nil.
73-
rootCmd, err := cmd.NewRootCmd(func(*cfg.Config, string, string) error { return nil })
76+
rootCmd, err := cmd.NewRootCmd(cmd.Mount)
7477
if err != nil {
7578
log.Fatalf("Error occurred while creating the root command: %v", err)
7679
}

0 commit comments

Comments
 (0)