From b520428b5a4f6815bb66f6eb538e203ec2597935 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Wed, 11 Nov 2020 21:37:39 -0800 Subject: [PATCH 1/2] Fix CRIU - process.Init#io could be nil - Make sure CreateTaskRequest#Options is not empty before unmarshaling Signed-off-by: Kazuyoshi Kato --- pkg/process/init.go | 6 +++++- runtime/v2/runc/container.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/process/init.go b/pkg/process/init.go index 28ca5ac6a..1bf5e7e45 100644 --- a/pkg/process/init.go +++ b/pkg/process/init.go @@ -193,11 +193,15 @@ func (p *Init) createCheckpointedState(r *CreateConfig, pidFile *pidFile) error ParentPath: r.ParentCheckpoint, }, PidFile: pidFile.Path(), - IO: p.io.IO(), NoPivot: p.NoPivotRoot, Detach: true, NoSubreaper: true, } + + if p.io != nil { + opts.IO = p.io.IO() + } + p.initState = &createdCheckpointState{ p: p, opts: opts, diff --git a/runtime/v2/runc/container.go b/runtime/v2/runc/container.go index 27d434a29..9b65e44c8 100644 --- a/runtime/v2/runc/container.go +++ b/runtime/v2/runc/container.go @@ -49,7 +49,7 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa } var opts options.Options - if r.Options != nil { + if r.Options != nil && r.Options.GetTypeUrl() != "" { v, err := typeurl.UnmarshalAny(r.Options) if err != nil { return nil, err From 8731888ec0bd93032490dfb3964ddbe9c723e208 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Mon, 9 Nov 2020 13:47:53 -0800 Subject: [PATCH 2/2] Re-enable CRIU tests by not using overlayfs snapshotter While the issue hasn't been fixed in the kernel yet, we can workaround the issue by not using overlayfs snapshotter. The newly added step runs all tests that match /TestCheckpoint/. So, TestCRWithImagePath has been renamed to match the regexp. Fixes #3930. Signed-off-by: Kazuyoshi Kato --- .github/workflows/ci.yml | 16 +++++++++++ integration/client/client_test.go | 28 ++++++++++++++++--- .../client/container_checkpoint_test.go | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f653399d2..a38c01519 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -322,6 +322,22 @@ jobs: sudo GOPATH=$GOPATH GOPROXY=$GOPROXY TEST_RUNTIME=$TEST_RUNTIME RUNC_FLAVOR=$RUNC_FLAVOR TESTFLAGS_PARALLEL=1 make integration EXTRA_TESTFLAGS=-no-criu working-directory: src/github.com/containerd/containerd + # CRIU wouldn't work with overlay snapshotter yet. + # See https://github.com/containerd/containerd/pull/4708#issuecomment-724322294. + - name: CRIU Integration + env: + GOPROXY: direct + TEST_RUNTIME: ${{ matrix.runtime }} + RUNC_FLAVOR: ${{ matrix.runc }} + # crun doesn't have "checkpoint" command. + if: ${{ matrix.runc == 'runc' }} + run: | + sudo GOPATH=$GOPATH GOPROXY=$GOPROXY \ + TEST_RUNTIME=$TEST_RUNTIME RUNC_FLAVOR=$RUNC_FLAVOR TESTFLAGS_PARALLEL=1 \ + TEST_SNAPSHOTTER=native \ + make integration EXTRA_TESTFLAGS='-run TestCheckpoint' + working-directory: src/github.com/containerd/containerd + - name: CRI Integration Test env: TEST_RUNTIME: ${{ matrix.runtime }} diff --git a/integration/client/client_test.go b/integration/client/client_test.go index 2ad73c001..ddb6889a5 100644 --- a/integration/client/client_test.go +++ b/integration/client/client_test.go @@ -50,6 +50,7 @@ var ( noCriu bool supportsCriu bool testNamespace = "testing" + testSnapshotter = DefaultSnapshotter ctrdStdioFilePath string ctrd = &daemon{} @@ -132,11 +133,30 @@ func TestMain(m *testing.M) { // allow comparison with containerd under test log.G(ctx).WithFields(logrus.Fields{ - "version": version.Version, - "revision": version.Revision, - "runtime": os.Getenv("TEST_RUNTIME"), + "version": version.Version, + "revision": version.Revision, + "runtime": os.Getenv("TEST_RUNTIME"), + "snapshotter": os.Getenv("TEST_SNAPSHOTTER"), }).Info("running tests against containerd") + snapshotter := DefaultSnapshotter + if ss := os.Getenv("TEST_SNAPSHOTTER"); ss != "" { + snapshotter = ss + } + + ns, ok := namespaces.Namespace(ctx) + if !ok { + fmt.Fprintln(os.Stderr, "error getting namespace") + os.Exit(1) + } + err = client.NamespaceService().SetLabel(ctx, ns, defaults.DefaultSnapshotterNSLabel, snapshotter) + if err != nil { + fmt.Fprintf(os.Stderr, "error setting %s's default snapshotter as %s: %s\n", ns, snapshotter, err) + os.Exit(1) + } + + testSnapshotter = snapshotter + // pull a seed image log.G(ctx).WithField("image", testImage).Info("start to pull seed image") if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil { @@ -285,7 +305,7 @@ func TestImagePullWithDiscardContent(t *testing.T) { t.Fatalf("there is no layers in the target image(parent: %v)", img.Target()) } var ( - sn = client.SnapshotService("") + sn = client.SnapshotService(testSnapshotter) chain []digest.Digest ) for i, dgst := range layers { diff --git a/integration/client/container_checkpoint_test.go b/integration/client/container_checkpoint_test.go index 193ceaee7..930b6991b 100644 --- a/integration/client/container_checkpoint_test.go +++ b/integration/client/container_checkpoint_test.go @@ -414,7 +414,7 @@ func TestCheckpointLeaveRunning(t *testing.T) { <-statusC } -func TestCRWithImagePath(t *testing.T) { +func TestCheckpointRestoreWithImagePath(t *testing.T) { if !supportsCriu { t.Skip("system does not have criu installed") }