Skip to content

Commit 8590963

Browse files
committed
Move containerd archives from code to yaml
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 <[email protected]>
1 parent fe9f17b commit 8590963

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

pkg/limayaml/containerd.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
archives:
2+
- location: https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-full-1.7.6-linux-amd64.tar.gz
3+
arch: x86_64
4+
digest: sha256:2c841e097fcfb5a1760bd354b3778cb695b44cd01f9f271c17507dc4a0b25606
5+
- location: https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-full-1.7.6-linux-arm64.tar.gz
6+
arch: aarch64
7+
digest: sha256:77c747f09853ee3d229d77e8de0dd3c85622537d82be57433dc1fca4493bab95
8+
# No arm-v7
9+
# No riscv64

pkg/limayaml/defaults.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package limayaml
33
import (
44
"bytes"
55
"crypto/sha256"
6+
_ "embed"
67
"fmt"
78
"net"
89
"os"
@@ -14,6 +15,7 @@ import (
1415
"text/template"
1516

1617
"github.com/docker/go-units"
18+
"github.com/goccy/go-yaml"
1719
"github.com/pbnjay/memory"
1820
"github.com/sirupsen/logrus"
1921
"golang.org/x/sys/cpu"
@@ -68,25 +70,20 @@ func defaultCPUType() CPUType {
6870
return cpuType
6971
}
7072

73+
//go:embed containerd.yaml
74+
var defaultContainerdYAML []byte
75+
76+
type containerdYAML struct {
77+
Archives []File
78+
}
79+
7180
func defaultContainerdArchives() []File {
72-
const nerdctlVersion = "1.7.6"
73-
location := func(goos string, goarch string) string {
74-
return "https://github.com/containerd/nerdctl/releases/download/v" + nerdctlVersion + "/nerdctl-full-" + nerdctlVersion + "-" + goos + "-" + goarch + ".tar.gz"
75-
}
76-
return []File{
77-
{
78-
Location: location("linux", "amd64"),
79-
Arch: X8664,
80-
Digest: "sha256:2c841e097fcfb5a1760bd354b3778cb695b44cd01f9f271c17507dc4a0b25606",
81-
},
82-
{
83-
Location: location("linux", "arm64"),
84-
Arch: AARCH64,
85-
Digest: "sha256:77c747f09853ee3d229d77e8de0dd3c85622537d82be57433dc1fca4493bab95",
86-
},
87-
// No arm-v7
88-
// No riscv64
81+
var containerd containerdYAML
82+
err := yaml.UnmarshalWithOptions(defaultContainerdYAML, &containerd, yaml.Strict())
83+
if err != nil {
84+
panic(fmt.Errorf("failed to unmarshal as YAML: %w", err))
8985
}
86+
return containerd.Archives
9087
}
9188

9289
// FirstUsernetIndex gets the index of first usernet network under l.Network[]. Returns -1 if no usernet network found

pkg/limayaml/defaults_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,8 @@ func TestFillDefault(t *testing.T) {
647647
FillDefault(&y, &d, &o, filePath)
648648
assert.DeepEqual(t, &y, &expect, opts...)
649649
}
650+
651+
func TestContainerdDefault(t *testing.T) {
652+
archives := defaultContainerdArchives()
653+
assert.Assert(t, len(archives) > 0)
654+
}

pkg/limayaml/validate.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ func Validate(y *LimaYAML, warn bool) error {
192192
}
193193
}
194194
needsContainerdArchives := (y.Containerd.User != nil && *y.Containerd.User) || (y.Containerd.System != nil && *y.Containerd.System)
195-
if needsContainerdArchives && len(y.Containerd.Archives) == 0 {
196-
return fmt.Errorf("field `containerd.archives` must be provided")
195+
if needsContainerdArchives {
196+
if len(y.Containerd.Archives) == 0 {
197+
return fmt.Errorf("field `containerd.archives` must be provided")
198+
}
199+
for i, f := range y.Containerd.Archives {
200+
if err := validateFileObject(f, fmt.Sprintf("containerd.archives[%d]", i)); err != nil {
201+
return err
202+
}
203+
}
197204
}
198205
for i, p := range y.Probes {
199206
switch p.Mode {

0 commit comments

Comments
 (0)