Skip to content

Commit

Permalink
Move containerd archives from code to yaml
Browse files Browse the repository at this point in the history
This makes it more similar to update compared to the images,
and allows for integrating with other archives in the future.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed Jul 17, 2024
1 parent 7295d3b commit 772e420
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
10 changes: 10 additions & 0 deletions pkg/limayaml/containerd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 1.7.6
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
32 changes: 15 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"
"fmt"
"net"
"os"
Expand All @@ -14,6 +15,7 @@ import (
"text/template"

"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 @@ -68,25 +70,21 @@ func defaultCPUType() CPUType {
return cpuType
}

//go:embed containerd.yaml
var defaultContainerdYAML []byte

type ContainerdYAML struct {
Version string
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 @@ -647,3 +647,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 @@ -193,8 +193,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

0 comments on commit 772e420

Please sign in to comment.