diff --git a/pkg/limayaml/containerd.yaml b/pkg/limayaml/containerd.yaml new file mode 100644 index 00000000000..fe4afe6e32f --- /dev/null +++ b/pkg/limayaml/containerd.yaml @@ -0,0 +1,9 @@ +archives: +- location: https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-full-1.7.6-linux-amd64.tar.gz + arch: x86_64 + digest: sha256:2c841e097fcfb5a1760bd354b3778cb695b44cd01f9f271c17507dc4a0b25606 +- location: https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-full-1.7.6-linux-arm64.tar.gz + arch: aarch64 + digest: sha256:77c747f09853ee3d229d77e8de0dd3c85622537d82be57433dc1fca4493bab95 +# No arm-v7 +# No riscv64 diff --git a/pkg/limayaml/defaults.go b/pkg/limayaml/defaults.go index 160cb9787ca..8ac8c26c7bd 100644 --- a/pkg/limayaml/defaults.go +++ b/pkg/limayaml/defaults.go @@ -3,6 +3,7 @@ package limayaml import ( "bytes" "crypto/sha256" + _ "embed" "errors" "fmt" "net" @@ -16,6 +17,7 @@ import ( "github.com/coreos/go-semver/semver" "github.com/docker/go-units" + "github.com/goccy/go-yaml" "github.com/pbnjay/memory" "github.com/sirupsen/logrus" "golang.org/x/sys/cpu" @@ -70,25 +72,20 @@ func defaultCPUType() CPUType { return cpuType } +//go:embed containerd.yaml +var defaultContainerdYAML []byte + +type ContainerdYAML struct { + Archives []File +} + func defaultContainerdArchives() []File { - const nerdctlVersion = "1.7.6" - location := func(goos string, goarch string) string { - return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-" + goos + "-" + goarch + ".tar.gz" - } - return []File{ - { - Location: location("linux", "amd64"), - Arch: X8664, - Digest: "sha256:2c841e097fcfb5a1760bd354b3778cb695b44cd01f9f271c17507dc4a0b25606", - }, - { - Location: location("linux", "arm64"), - Arch: AARCH64, - Digest: "sha256:77c747f09853ee3d229d77e8de0dd3c85622537d82be57433dc1fca4493bab95", - }, - // No arm-v7 - // No riscv64 + var containerd ContainerdYAML + err := yaml.UnmarshalWithOptions(defaultContainerdYAML, &containerd, yaml.Strict()) + if err != nil { + panic(fmt.Errorf("failed to unmarshal as YAML: %w", err)) } + return containerd.Archives } // FirstUsernetIndex gets the index of first usernet network under l.Network[]. Returns -1 if no usernet network found. diff --git a/pkg/limayaml/defaults_test.go b/pkg/limayaml/defaults_test.go index 9c4ffd9f88b..7571baa2c2f 100644 --- a/pkg/limayaml/defaults_test.go +++ b/pkg/limayaml/defaults_test.go @@ -673,3 +673,8 @@ func TestFillDefault(t *testing.T) { FillDefault(&y, &d, &o, filePath) assert.DeepEqual(t, &y, &expect, opts...) } + +func TestContainerdDefault(t *testing.T) { + archives := defaultContainerdArchives() + assert.Assert(t, len(archives) > 0) +} diff --git a/pkg/limayaml/validate.go b/pkg/limayaml/validate.go index 3ceb777182a..8eb719ede32 100644 --- a/pkg/limayaml/validate.go +++ b/pkg/limayaml/validate.go @@ -194,8 +194,15 @@ func Validate(y *LimaYAML, warn bool) error { } } needsContainerdArchives := (y.Containerd.User != nil && *y.Containerd.User) || (y.Containerd.System != nil && *y.Containerd.System) - if needsContainerdArchives && len(y.Containerd.Archives) == 0 { - return fmt.Errorf("field `containerd.archives` must be provided") + if needsContainerdArchives { + if len(y.Containerd.Archives) == 0 { + return fmt.Errorf("field `containerd.archives` must be provided") + } + for i, f := range y.Containerd.Archives { + if err := validateFileObject(f, fmt.Sprintf("containerd.archives[%d]", i)); err != nil { + return err + } + } } for i, p := range y.Probes { switch p.Mode {