From 32e7a54f7f413ba83af8217b9bc0a367e3c30f94 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Wed, 26 Aug 2020 20:22:39 -0700 Subject: Make flag propagation automatic Use reflection and tags to provide automatic conversion from Config to flags. This makes adding new flags less error-prone, skips flags using default values (easier to read), and makes tests correctly use default flag values for test Configs. Updates #3494 PiperOrigin-RevId: 328662070 --- runsc/boot/loader_test.go | 20 ++++++++++++-------- runsc/boot/strace.go | 4 +++- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'runsc/boot') diff --git a/runsc/boot/loader_test.go b/runsc/boot/loader_test.go index 03cbaec33..2343ce76c 100644 --- a/runsc/boot/loader_test.go +++ b/runsc/boot/loader_test.go @@ -44,15 +44,19 @@ func init() { if err := fsgofer.OpenProcSelfFD(); err != nil { panic(err) } + config.RegisterFlags() } func testConfig() *config.Config { - return &config.Config{ - RootDir: "unused_root_dir", - Network: config.NetworkNone, - DisableSeccomp: true, - Platform: "ptrace", + conf, err := config.NewFromFlags() + if err != nil { + panic(err) } + // Change test defaults. + conf.RootDir = "unused_root_dir" + conf.Network = config.NetworkNone + conf.DisableSeccomp = true + return conf } // testSpec returns a simple spec that can be used in tests. @@ -546,7 +550,7 @@ func TestRestoreEnvironment(t *testing.T) { { Dev: "9pfs-/", Flags: fs.MountSourceFlags{ReadOnly: true}, - DataString: "trans=fd,rfdno=0,wfdno=0,privateunixsocket=true,cache=remote_revalidating", + DataString: "trans=fd,rfdno=0,wfdno=0,privateunixsocket=true", }, }, "tmpfs": { @@ -600,7 +604,7 @@ func TestRestoreEnvironment(t *testing.T) { { Dev: "9pfs-/", Flags: fs.MountSourceFlags{ReadOnly: true}, - DataString: "trans=fd,rfdno=0,wfdno=0,privateunixsocket=true,cache=remote_revalidating", + DataString: "trans=fd,rfdno=0,wfdno=0,privateunixsocket=true", }, { Dev: "9pfs-/dev/fd-foo", @@ -658,7 +662,7 @@ func TestRestoreEnvironment(t *testing.T) { { Dev: "9pfs-/", Flags: fs.MountSourceFlags{ReadOnly: true}, - DataString: "trans=fd,rfdno=0,wfdno=0,privateunixsocket=true,cache=remote_revalidating", + DataString: "trans=fd,rfdno=0,wfdno=0,privateunixsocket=true", }, }, "tmpfs": { diff --git a/runsc/boot/strace.go b/runsc/boot/strace.go index 176981f74..c21648a32 100644 --- a/runsc/boot/strace.go +++ b/runsc/boot/strace.go @@ -15,6 +15,8 @@ package boot import ( + "strings" + "gvisor.dev/gvisor/pkg/sentry/strace" "gvisor.dev/gvisor/runsc/config" ) @@ -37,5 +39,5 @@ func enableStrace(conf *config.Config) error { strace.EnableAll(strace.SinkTypeLog) return nil } - return strace.Enable(conf.StraceSyscalls, strace.SinkTypeLog) + return strace.Enable(strings.Split(conf.StraceSyscalls, ","), strace.SinkTypeLog) } -- cgit v1.2.3