Skip to content

Commit 28b990b

Browse files
prafgupsondavidb
authored andcommitted
Add minimal crictl integration test + setup
Signed-off-by: Praful Gupta <prafulgupta6@gmail.com>
1 parent 9442946 commit 28b990b

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ARG CONTAINERD_VERSION=1.7.30
1717
ARG RUNC_VERSION=1.3.3
1818
ARG NERDCTL_VERSION=2.1.6
19+
ARG CRICTL_VERSION=1.36.0
1920
ARG IGZIP_VERSION=2.31.1
2021
ARG RAPIDGZIP_VERSION=0.14.3
2122

@@ -101,6 +102,7 @@ FROM public.ecr.aws/amazonlinux/amazonlinux:2023 AS containerd-snapshotter-base
101102
ARG CONTAINERD_VERSION
102103
ARG RUNC_VERSION
103104
ARG NERDCTL_VERSION
105+
ARG CRICTL_VERSION
104106
ARG TARGETARCH
105107
ENV GOPROXY=direct
106108
ENV GOCOVERDIR=/test_coverage
@@ -141,3 +143,6 @@ RUN curl -sSL --output /tmp/runc https://github.com/opencontainers/runc/releases
141143
RUN curl -sSL --output /tmp/nerdctl.tgz https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-${TARGETARCH:-amd64}.tar.gz \
142144
&& tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin/ \
143145
&& rm -f /tmp/nerdctl.tgz
146+
RUN curl -sSL --output /tmp/crictl.tgz https://github.com/kubernetes-sigs/cri-tools/releases/download/v${CRICTL_VERSION}/crictl-v${CRICTL_VERSION}-linux-${TARGETARCH:-amd64}.tar.gz \
147+
&& tar zxvf /tmp/crictl.tgz -C /usr/local/bin/ \
148+
&& rm -f /tmp/crictl.tgz

integration/cri_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright The Soci Snapshotter Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package integration
18+
19+
import (
20+
"testing"
21+
22+
"github.com/awslabs/soci-snapshotter/util/testutil"
23+
)
24+
25+
// TestCRIImagePull pulls a SOCI-converted image through containerd's CRI image endpoint
26+
// and asserts that the layers are mounted as remote SOCI snapshots.
27+
func TestCRIImagePull(t *testing.T) {
28+
regConfig := newRegistryConfig()
29+
sh, done := newShellWithRegistry(t, regConfig)
30+
defer done()
31+
32+
image := alpineImage
33+
34+
rebootContainerd(t, sh, getContainerdConfigToml(t, false), getSnapshotterConfigToml(t))
35+
copyImage(sh, dockerhub(image), regConfig.mirror(image))
36+
buildIndex(sh, regConfig.mirror(image), withMinLayerSize(0))
37+
sh.X("soci", "push", "--user", regConfig.creds(), regConfig.mirror(image).ref)
38+
39+
rsm := testutil.NewRemoteSnapshotMonitor()
40+
m := rebootContainerd(t, sh, getCRIContainerdConfigToml(t, false), getSnapshotterConfigToml(t, withCRIKeychain), rsm.MonitorFunc)
41+
defer m.Cleanup(t)
42+
43+
sh.X(append(crictlCmd, "pull", "--creds", regConfig.creds(), regConfig.mirror(image).ref)...)
44+
45+
rsm.CheckAllRemoteSnapshots(t)
46+
}

integration/util_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ const (
8484
var (
8585
runSociCmd = []string{"nerdctl", "run", "--pull", "never", "--net", "none", "--snapshotter", "soci"}
8686
imagePullCmd = []string{"nerdctl", "pull", "-q", "--snapshotter", "soci"}
87+
crictlCmd = []string{
88+
"crictl",
89+
"--runtime-endpoint", "unix:///run/containerd/containerd.sock",
90+
"--image-endpoint", "unix:///run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock",
91+
}
8792
)
8893

8994
// These are images that we use in our integration tests
@@ -140,6 +145,44 @@ level = "{{.LogLevel}}"
140145
{{.AdditionalConfig}}
141146
`
142147

148+
// criContainerdConfigTemplate is the CRI counterpart to `containerdConfigTemplate`: it
149+
// leaves the containerd CRI plugin enabled and points it at the SOCI snapshotter.
150+
const criContainerdConfigTemplate = `
151+
version = 2
152+
153+
disabled_plugins = [
154+
"io.containerd.snapshotter.v1.aufs",
155+
"io.containerd.snapshotter.v1.btrfs",
156+
"io.containerd.snapshotter.v1.devmapper",
157+
"io.containerd.snapshotter.v1.zfs",
158+
"io.containerd.tracing.processor.v1.otlp",
159+
"io.containerd.internal.v1.tracing",
160+
]
161+
162+
# containerd 1.7.x
163+
[plugins."io.containerd.grpc.v1.cri".containerd]
164+
snapshotter = "soci"
165+
disable_snapshot_annotations = false
166+
167+
# containerd 2.x
168+
[plugins."io.containerd.cri.v1.images"]
169+
snapshotter = "soci"
170+
disable_snapshot_annotations = false
171+
172+
[plugins."io.containerd.snapshotter.v1.soci"]
173+
root_path = "/var/lib/soci-snapshotter-grpc/"
174+
disable_verification = {{.DisableVerification}}
175+
176+
[plugins."io.containerd.snapshotter.v1.soci".blob]
177+
check_always = true
178+
179+
[debug]
180+
format = "json"
181+
level = "{{.LogLevel}}"
182+
183+
{{.AdditionalConfig}}
184+
`
185+
143186
type composeDefaultTemplateArgs struct {
144187
Entrypoint string
145188
ImageContextDir string
@@ -314,6 +357,27 @@ func getContainerdConfigToml(t *testing.T, disableVerification bool, additionalC
314357
return s
315358
}
316359

360+
// getCRIContainerdConfigToml is the CRI counterpart to `getContainerdConfigToml`,
361+
// rendering `criContainerdConfigTemplate` instead.
362+
func getCRIContainerdConfigToml(t *testing.T, disableVerification bool, additionalConfigs ...string) string {
363+
if !isTestingBuiltinSnapshotter() {
364+
additionalConfigs = append(additionalConfigs, proxySnapshotterConfig)
365+
}
366+
s, err := testutil.ApplyTextTemplate(criContainerdConfigTemplate, struct {
367+
LogLevel string
368+
DisableVerification bool
369+
AdditionalConfig string
370+
}{
371+
LogLevel: containerdLogLevel,
372+
DisableVerification: disableVerification,
373+
AdditionalConfig: strings.Join(additionalConfigs, "\n"),
374+
})
375+
if err != nil {
376+
t.Fatal(err)
377+
}
378+
return s
379+
}
380+
317381
type snapshotterConfigOpt func(*config.Config)
318382

319383
func withTCPMetrics(cfg *config.Config) {
@@ -335,6 +399,10 @@ func withDisableBgFetcher(cfg *config.Config) {
335399
cfg.ServiceConfig.FSConfig.BackgroundFetchConfig.Disable = true
336400
}
337401

402+
func withCRIKeychain(cfg *config.Config) {
403+
cfg.ServiceConfig.CRIKeychainConfig.EnableKeychain = true
404+
}
405+
338406
func withMinLayerSizeConfig(minLayerSize int64) snapshotterConfigOpt {
339407
return func(c *config.Config) {
340408
c.ServiceConfig.SnapshotterConfig.MinLayerSize = minLayerSize

0 commit comments

Comments
 (0)