|
| 1 | +/* |
| 2 | + Copyright The containerd 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 | + "os" |
| 21 | + "path/filepath" |
| 22 | + "syscall" |
| 23 | + "testing" |
| 24 | + "time" |
| 25 | + |
| 26 | + "github.com/containerd/containerd/v2/integration/images" |
| 27 | + "github.com/containerd/containerd/v2/pkg/kernelversion" |
| 28 | + "github.com/stretchr/testify/require" |
| 29 | + criruntime "k8s.io/cri-api/pkg/apis/runtime/v1" |
| 30 | +) |
| 31 | + |
| 32 | +func TestRunContainerWithVolatileOption(t *testing.T) { |
| 33 | + if ok, err := kernelversion.GreaterEqualThan(kernelversion.KernelVersion{ |
| 34 | + Kernel: 5, |
| 35 | + Major: 10, |
| 36 | + }); !ok { |
| 37 | + t.Skipf("Only test it when kernel >= 5.10: %v", err) |
| 38 | + } |
| 39 | + |
| 40 | + workDir := t.TempDir() |
| 41 | + |
| 42 | + t.Log("Prepare containerd config with volatile option") |
| 43 | + cfgPath := filepath.Join(workDir, "config.toml") |
| 44 | + err := os.WriteFile( |
| 45 | + cfgPath, |
| 46 | + []byte(` |
| 47 | +version = 3 |
| 48 | +
|
| 49 | +[plugins.'io.containerd.internal.v1.cri'] |
| 50 | + ignore_image_defined_volumes = false |
| 51 | +
|
| 52 | +[plugins."io.containerd.snapshotter.v1.overlayfs"] |
| 53 | + mount_options = ["volatile"] |
| 54 | +`), |
| 55 | + 0600) |
| 56 | + require.NoError(t, err) |
| 57 | + |
| 58 | + t.Logf("Starting containerd") |
| 59 | + currentProc := newCtrdProc(t, "containerd", workDir) |
| 60 | + require.NoError(t, currentProc.isReady()) |
| 61 | + t.Cleanup(func() { |
| 62 | + t.Log("Cleanup all the pods") |
| 63 | + cleanupPods(t, currentProc.criRuntimeService(t)) |
| 64 | + |
| 65 | + t.Log("Stopping containerd process") |
| 66 | + require.NoError(t, currentProc.kill(syscall.SIGTERM)) |
| 67 | + require.NoError(t, currentProc.wait(5*time.Minute)) |
| 68 | + }) |
| 69 | + |
| 70 | + imageName := images.Get(images.VolumeOwnership) |
| 71 | + pullImagesByCRI(t, currentProc.criImageService(t), imageName) |
| 72 | + |
| 73 | + podCtx := newPodTCtx(t, currentProc.criRuntimeService(t), "running-pod", "sandbox") |
| 74 | + |
| 75 | + podCtx.createContainer("running", imageName, |
| 76 | + criruntime.ContainerState_CONTAINER_RUNNING, |
| 77 | + WithCommand("sleep", "1d")) |
| 78 | +} |
0 commit comments