Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move containerd archives from code to yaml #2403

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/limayaml/containerd.yaml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 14 additions & 17 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package limayaml
import (
"bytes"
"crypto/sha256"
_ "embed"
"errors"
"fmt"
"net"
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
11 changes: 9 additions & 2 deletions pkg/limayaml/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading