Skip to content

Commit bb4c757

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 726f61d commit bb4c757

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
"errors"
78
"fmt"
89
"net"
@@ -16,6 +17,7 @@ import (
1617

1718
"github.com/coreos/go-semver/semver"
1819
"github.com/docker/go-units"
20+
"github.com/goccy/go-yaml"
1921
"github.com/pbnjay/memory"
2022
"github.com/sirupsen/logrus"
2123
"golang.org/x/sys/cpu"
@@ -70,25 +72,20 @@ func defaultCPUType() CPUType {
7072
return cpuType
7173
}
7274

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

9491
// 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
@@ -673,3 +673,8 @@ func TestFillDefault(t *testing.T) {
673673
FillDefault(&y, &d, &o, filePath)
674674
assert.DeepEqual(t, &y, &expect, opts...)
675675
}
676+
677+
func TestContainerdDefault(t *testing.T) {
678+
archives := defaultContainerdArchives()
679+
assert.Assert(t, len(archives) > 0)
680+
}

pkg/limayaml/validate.go

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

0 commit comments

Comments
 (0)