Skip to content

Commit 3bf0d1c

Browse files
committed
Update containerd config tests
1 parent 56b5786 commit 3bf0d1c

5 files changed

Lines changed: 507 additions & 1 deletion

File tree

nodeup/pkg/model/containerd_test.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func TestContainerdBuilder_Complex(t *testing.T) {
4848
runContainerdBuilderTest(t, "complex", distributions.DistributionUbuntu2604)
4949
}
5050

51+
func TestContainerdBuilder_V3(t *testing.T) {
52+
runContainerdBuilderTest(t, "v3", distributions.DistributionUbuntu2604)
53+
}
54+
5155
func TestContainerdBuilder_BuildFlags(t *testing.T) {
5256
grid := []struct {
5357
config kops.ContainerdConfig
@@ -177,6 +181,41 @@ func runContainerdBuilderTest(t *testing.T, key string, distro distributions.Dis
177181
testutils.ValidateTasks(t, filepath.Join(basedir, "tasks.yaml"), context)
178182
}
179183

184+
func TestUseContainerdConfigV3(t *testing.T) {
185+
tests := []struct {
186+
name string
187+
version string
188+
want bool
189+
wantErr bool
190+
}{
191+
{name: "empty defaults to v2", version: "", want: false},
192+
{name: "1.7.0 is v2", version: "1.7.0", want: false},
193+
{name: "1.999.999 is v2", version: "1.999.999", want: false},
194+
{name: "2.0.0 boundary is v3", version: "2.0.0", want: true},
195+
{name: "2.0.0 with v prefix is v3", version: "v2.0.0", want: true},
196+
{name: "2.1.6 is v3", version: "2.1.6", want: true},
197+
{name: "3.0.0 is v3", version: "3.0.0", want: true},
198+
{name: "unparseable returns error", version: "not-a-semver", wantErr: true},
199+
}
200+
for _, tc := range tests {
201+
t.Run(tc.name, func(t *testing.T) {
202+
got, err := useContainerdConfigV3(tc.version)
203+
if tc.wantErr {
204+
if err == nil {
205+
t.Fatalf("useContainerdConfigV3(%q) error = nil, want non-nil", tc.version)
206+
}
207+
return
208+
}
209+
if err != nil {
210+
t.Fatalf("useContainerdConfigV3(%q) error = %v, want nil", tc.version, err)
211+
}
212+
if got != tc.want {
213+
t.Errorf("useContainerdConfigV3(%q) = %v, want %v", tc.version, got, tc.want)
214+
}
215+
})
216+
}
217+
}
218+
180219
func TestContainerdConfig(t *testing.T) {
181220
b := &ContainerdBuilder{
182221
NodeupModelContext: &NodeupModelContext{
@@ -241,7 +280,8 @@ func TestAppendGPURuntimeContainerdConfig(t *testing.T) {
241280
t.Fatalf("Unexpected error: %v", err)
242281
}
243282

244-
if err := appendNvidiaGPURuntimeConfig(config); err != nil {
283+
runtimesPath := []string{"plugins", "io.containerd.grpc.v1.cri", "containerd", "runtimes"}
284+
if err := appendNvidiaGPURuntimeConfig(config, runtimesPath); err != nil {
245285
t.Errorf("unexpected error: %v", err)
246286
}
247287

nodeup/pkg/model/tests/containerdbuilder/complex/cluster.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ spec:
1717
plugins."io.containerd.grpc.v1.cri".containerd.runtimes.test-handler.test_int: 1
1818
plugins."io.containerd.grpc.v1.cri".containerd.runtimes.test-handler.test_intstr: "1"
1919
plugins."io.containerd.grpc.v1.cri".containerd.runtimes.test-handler.test_str: test
20+
registryMirrors:
21+
docker.io:
22+
- https://registry-1.docker.io
23+
registry.k8s.io:
24+
- https://mirror.example.com
25+
- https://backup.example.com
2026
etcdClusters:
2127
- etcdMembers:
2228
- instanceGroup: master-us-test-1a

nodeup/pkg/model/tests/containerdbuilder/complex/tasks.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
contents: |2
2+
3+
[host]
4+
5+
[host."https://registry-1.docker.io"]
6+
capabilities = ["pull", "resolve"]
7+
path: /etc/containerd/certs.d/docker.io/hosts.toml
8+
type: file
9+
---
10+
contents: |2
11+
12+
[host]
13+
14+
[host."https://backup.example.com"]
15+
capabilities = ["pull", "resolve"]
16+
17+
[host."https://mirror.example.com"]
18+
capabilities = ["pull", "resolve"]
19+
path: /etc/containerd/certs.d/registry.k8s.io/hosts.toml
20+
type: file
21+
---
122
contents: |
223
{
324
"cniVersion": "1.0.0",
@@ -48,6 +69,9 @@ contents: |
4869
test_int = 1
4970
test_intstr = "1"
5071
test_str = "test"
72+
73+
[plugins."io.containerd.grpc.v1.cri".registry]
74+
config_path = "/etc/containerd/certs.d"
5175
path: /etc/containerd/config.toml
5276
type: file
5377
---
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apiVersion: kops.k8s.io/v1alpha2
2+
kind: Cluster
3+
metadata:
4+
name: minimal.example.com
5+
spec:
6+
kubernetesApiAccess:
7+
- 0.0.0.0/0
8+
channel: stable
9+
cloudProvider: aws
10+
configBase: memfs://clusters.example.com/minimal.example.com
11+
containerRuntime: containerd
12+
containerd:
13+
version: 2.1.6
14+
sandboxImage: registry.k8s.io/pause:3.10.1
15+
selinuxEnabled: true
16+
nri:
17+
enabled: true
18+
configAdditions:
19+
plugins."io.containerd.cri.v1.runtime".containerd.runtimes.test-handler.test_str: test
20+
registryMirrors:
21+
docker.io:
22+
- https://registry-1.docker.io
23+
etcdClusters:
24+
- etcdMembers:
25+
- instanceGroup: master-us-test-1a
26+
name: master-us-test-1a
27+
name: main
28+
- etcdMembers:
29+
- instanceGroup: master-us-test-1a
30+
name: master-us-test-1a
31+
name: events
32+
iam:
33+
legacy: false
34+
kubernetesVersion: v1.32.0
35+
masterPublicName: api.minimal.example.com
36+
networkCIDR: 172.20.0.0/16
37+
networking:
38+
kubenet: {}
39+
nonMasqueradeCIDR: 100.64.0.0/10
40+
sshAccess:
41+
- 0.0.0.0/0
42+
subnets:
43+
- cidr: 172.20.32.0/19
44+
name: us-test-1a
45+
type: Public
46+
zone: us-test-1a

0 commit comments

Comments
 (0)