Skip to content

Commit 31d0070

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 3abd2ae commit 31d0070

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

pkg/limayaml/containerd.yaml

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

pkg/limayaml/defaults.go

+15-17
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,21 @@ func defaultCPUType() CPUType {
6870
return cpuType
6971
}
7072

73+
//go:embed containerd.yaml
74+
var defaultContainerdYAML []byte
75+
76+
type ContainerdYAML struct {
77+
Version string
78+
Archives []File
79+
}
80+
7181
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
82+
var containerd ContainerdYAML
83+
err := yaml.UnmarshalWithOptions(defaultContainerdYAML, &containerd, yaml.Strict())
84+
if err != nil {
85+
panic(fmt.Errorf("failed to unmarshal as YAML: %w", err))
8986
}
87+
return containerd.Archives
9088
}
9189

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

pkg/limayaml/defaults_test.go

+5
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

+9-2
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)