From 807e59f15cfad4f8dab0ad8772e2b318f1570917 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Thu, 12 Oct 2023 12:52:34 -0700 Subject: [PATCH] Add some units tests around lifecycle annotation. PiperOrigin-RevId: 572986759 --- runsc/boot/mount_hints_test.go | 15 +++++++++++---- runsc/boot/vfs_test.go | 19 +++++++++++++++++++ runsc/container/multi_container_test.go | 1 + 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/runsc/boot/mount_hints_test.go b/runsc/boot/mount_hints_test.go index 682e03f36..bd59f756c 100644 --- a/runsc/boot/mount_hints_test.go +++ b/runsc/boot/mount_hints_test.go @@ -29,10 +29,11 @@ func TestPodMountHintsHappy(t *testing.T) { MountPrefix + "mount1.type": "tmpfs", MountPrefix + "mount1.share": "pod", - MountPrefix + "mount2.source": "bar", - MountPrefix + "mount2.type": "bind", - MountPrefix + "mount2.share": "container", - MountPrefix + "mount2.options": "rw,private", + MountPrefix + "mount2.source": "bar", + MountPrefix + "mount2.type": "bind", + MountPrefix + "mount2.share": "container", + MountPrefix + "mount2.options": "rw,private", + MountPrefix + "mount2.lifecycle": "pod", }, } podHints, err := NewPodMountHints(spec) @@ -57,6 +58,9 @@ func TestPodMountHintsHappy(t *testing.T) { if want := []string(nil); !reflect.DeepEqual(want, mount1.Mount.Options) { t.Errorf("mount1 type, want: %q, got: %q", want, mount1.Mount.Options) } + if want := sharedLife; want != mount1.Lifecycle { + t.Errorf("mount1 lifecycle, want: %q, got: %q", want, mount1.Lifecycle) + } mount2 := podHints.Mounts["mount2"] if want := "mount2"; want != mount2.Name { @@ -74,6 +78,9 @@ func TestPodMountHintsHappy(t *testing.T) { if want := []string{"rw", "private"}; !reflect.DeepEqual(want, mount2.Mount.Options) { t.Errorf("mount2 type, want: %q, got: %q", want, mount2.Mount.Options) } + if want := podLife; want != mount2.Lifecycle { + t.Errorf("mount2 lifecycle, want: %q, got: %q", want, mount2.Lifecycle) + } } func TestPodMountHintsErrors(t *testing.T) { diff --git a/runsc/boot/vfs_test.go b/runsc/boot/vfs_test.go index 96b5d5d40..2d568f984 100644 --- a/runsc/boot/vfs_test.go +++ b/runsc/boot/vfs_test.go @@ -46,6 +46,16 @@ func TestGetMountAccessType(t *testing.T) { }, want: config.FileAccessShared, }, + { + name: "pod+podLife=shared", + annotations: map[string]string{ + MountPrefix + "mount1.source": source, + MountPrefix + "mount1.type": "bind", + MountPrefix + "mount1.share": "pod", + MountPrefix + "mount1.lifecycle": "pod", + }, + want: config.FileAccessShared, + }, { name: "shared=shared", annotations: map[string]string{ @@ -64,6 +74,15 @@ func TestGetMountAccessType(t *testing.T) { }, want: config.FileAccessShared, }, + { + name: "tmpfs+pod=exclusive", + annotations: map[string]string{ + MountPrefix + "mount1.source": source, + MountPrefix + "mount1.type": "tmpfs", + MountPrefix + "mount1.share": "pod", + }, + want: config.FileAccessExclusive, + }, } { t.Run(tst.name, func(t *testing.T) { spec := &specs.Spec{Annotations: tst.annotations} diff --git a/runsc/container/multi_container_test.go b/runsc/container/multi_container_test.go index 790a96c75..d8cc7e612 100644 --- a/runsc/container/multi_container_test.go +++ b/runsc/container/multi_container_test.go @@ -129,6 +129,7 @@ func createSharedMount(mount specs.Mount, name string, pod ...*specs.Spec) { spec.Annotations[boot.MountPrefix+name+".source"] = mount.Source spec.Annotations[boot.MountPrefix+name+".type"] = mount.Type spec.Annotations[boot.MountPrefix+name+".share"] = "pod" + spec.Annotations[boot.MountPrefix+name+".lifecycle"] = "pod" if len(mount.Options) > 0 { spec.Annotations[boot.MountPrefix+name+".options"] = strings.Join(mount.Options, ",") }