Skip to content

Commit d6f4f64

Browse files
committed
limayaml: do not default containerd.user=true on non-Linux guests
FillDefault enabled containerd.user=true whenever the guest arch was x86_64 or aarch64, with no check on the guest OS. macOS (os: Darwin) and FreeBSD guests therefore defaulted to containerd.user=true even though nerdctl is a Linux-only runtime, causing the ~250 MiB nerdctl archive to be downloaded unnecessarily. Gate the true default on *y.OS == limatype.LINUX. Behavior for Linux guests is unchanged; non-Linux guests now default to containerd.user=false on every architecture. Explicit containerd.user=true in user YAML is preserved. Add TestContainerdUserDefaultPerOS covering the Linux/Darwin/FreeBSD matrix and TestContainerdUserExplicitOverride to lock the override path. Fixes #5037 Signed-off-by: gaurav0107 <gauravdubey0107@gmail.com>
1 parent 3569ecb commit d6f4f64

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

pkg/limayaml/defaults.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,17 @@ func FillDefault(ctx context.Context, y, d, o *limatype.LimaYAML, filePath strin
528528
y.Containerd.User = o.Containerd.User
529529
}
530530
if y.Containerd.User == nil {
531-
switch *y.Arch {
532-
case limatype.X8664, limatype.AARCH64:
533-
y.Containerd.User = ptr.Of(true)
534-
default:
531+
// nerdctl is a Linux-only container runtime; only default
532+
// containerd.user=true when the guest OS is Linux. Otherwise
533+
// downloading the nerdctl archive (~250 MiB) is wasted I/O.
534+
if *y.OS == limatype.LINUX {
535+
switch *y.Arch {
536+
case limatype.X8664, limatype.AARCH64:
537+
y.Containerd.User = ptr.Of(true)
538+
default:
539+
y.Containerd.User = ptr.Of(false)
540+
}
541+
} else {
535542
y.Containerd.User = ptr.Of(false)
536543
}
537544
}

pkg/limayaml/defaults_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,3 +887,54 @@ func TestMountTagDuplicateLocation(t *testing.T) {
887887
tag2 := MountTag(location, "/mnt/home-writable")
888888
assert.Assert(t, tag1 != tag2)
889889
}
890+
891+
// TestContainerdUserDefaultPerOS verifies that FillDefault only enables
892+
// containerd.user=true on Linux guests. nerdctl is a Linux-only runtime,
893+
// so non-Linux guests (Darwin, FreeBSD) must default to false regardless
894+
// of the host architecture. Regression test for issue #5037.
895+
func TestContainerdUserDefaultPerOS(t *testing.T) {
896+
cases := []struct {
897+
os limatype.OS
898+
arch limatype.Arch
899+
want bool
900+
}{
901+
{limatype.LINUX, limatype.X8664, true},
902+
{limatype.LINUX, limatype.AARCH64, true},
903+
{limatype.LINUX, limatype.RISCV64, false},
904+
{limatype.LINUX, limatype.ARMV7L, false},
905+
{limatype.DARWIN, limatype.AARCH64, false},
906+
{limatype.DARWIN, limatype.X8664, false},
907+
{limatype.FREEBSD, limatype.X8664, false},
908+
{limatype.FREEBSD, limatype.AARCH64, false},
909+
}
910+
for _, tc := range cases {
911+
t.Run(fmt.Sprintf("%s/%s", tc.os, tc.arch), func(t *testing.T) {
912+
y := limatype.LimaYAML{
913+
OS: ptr.Of(tc.os),
914+
Arch: ptr.Of(tc.arch),
915+
}
916+
var d, o limatype.LimaYAML
917+
FillDefault(t.Context(), &y, &d, &o, "", false)
918+
assert.Assert(t, y.Containerd.User != nil, "Containerd.User must be set after FillDefault")
919+
assert.Equal(t, *y.Containerd.User, tc.want,
920+
"Containerd.User default for OS=%s Arch=%s", tc.os, tc.arch)
921+
})
922+
}
923+
}
924+
925+
// TestContainerdUserExplicitOverride verifies FillDefault respects an
926+
// explicit containerd.user=true value even on non-Linux guests.
927+
func TestContainerdUserExplicitOverride(t *testing.T) {
928+
y := limatype.LimaYAML{
929+
OS: ptr.Of(limatype.DARWIN),
930+
Arch: ptr.Of(limatype.AARCH64),
931+
Containerd: limatype.Containerd{
932+
User: ptr.Of(true),
933+
},
934+
}
935+
var d, o limatype.LimaYAML
936+
FillDefault(t.Context(), &y, &d, &o, "", false)
937+
assert.Assert(t, y.Containerd.User != nil)
938+
assert.Equal(t, *y.Containerd.User, true,
939+
"explicit Containerd.User=true must be preserved on non-Linux guests")
940+
}

0 commit comments

Comments
 (0)