(t *testing.T, runtime string)
| 188 | } |
| 189 | |
| 190 | func testVolumeFrom(t *testing.T, runtime string) { |
| 191 | const vmID = 0 |
| 192 | |
| 193 | ctx := namespaces.WithNamespace(context.Background(), "default") |
| 194 | |
| 195 | client, err := containerd.New(integtest.ContainerdSockPath, containerd.WithDefaultRuntime(runtime)) |
| 196 | require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", integtest.ContainerdSockPath) |
| 197 | defer client.Close() |
| 198 | |
| 199 | image, err := alpineImage(ctx, client, defaultSnapshotterName) |
| 200 | require.NoError(t, err, "failed to get alpine image") |
| 201 | |
| 202 | fcClient, err := integtest.NewFCControlClient(integtest.ContainerdSockPath) |
| 203 | require.NoError(t, err, "failed to create fccontrol client") |
| 204 | |
| 205 | // TODO: Create and host own images with non-empty volumes. |
| 206 | ref := "docker.io/library/postgres:14.3" |
| 207 | vs := volume.NewSet(runtime) |
| 208 | provider := volume.FromImage(client, ref, "vfc-snapshot", volume.WithSnapshotter(defaultSnapshotterName)) |
| 209 | defer func() { |
| 210 | err := provider.Delete(ctx) |
| 211 | require.NoError(t, err) |
| 212 | }() |
| 213 | err = vs.AddFrom(ctx, provider) |
| 214 | require.NoError(t, err) |
| 215 | |
| 216 | containers := []string{"c1", "c2"} |
| 217 | |
| 218 | if runtime == firecrackerRuntime { |
| 219 | mount, err := vs.PrepareDriveMount(ctx, 10*mib) |
| 220 | require.NoError(t, err) |
| 221 | |
| 222 | _, err = fcClient.CreateVM(ctx, &proto.CreateVMRequest{ |
| 223 | VMID: strconv.Itoa(vmID), |
| 224 | ContainerCount: int32(len(containers)), |
| 225 | DriveMounts: []*proto.FirecrackerDriveMount{mount}, |
| 226 | }) |
| 227 | require.NoError(t, err, "failed to create VM") |
| 228 | } else { |
| 229 | err := vs.PrepareDirectory(ctx) |
| 230 | require.NoError(t, err) |
| 231 | } |
| 232 | |
| 233 | // Make volmes from a container. |
| 234 | volumesFromContainerImage, err := vs.WithMountsFromProvider(ref) |
| 235 | require.NoError(t, err) |
| 236 | |
| 237 | dir := "/var/lib/postgresql/data" |
| 238 | |
| 239 | for _, name := range containers { |
| 240 | snapshotName := fmt.Sprintf("%s-snapshot", name) |
| 241 | |
| 242 | sh := fmt.Sprintf("echo hello from %s >> %s/hello.txt", name, dir) |
| 243 | container, err := client.NewContainer(ctx, |
| 244 | name, |
| 245 | containerd.WithSnapshotter(defaultSnapshotterName), |
| 246 | containerd.WithNewSnapshot(snapshotName, image), |
| 247 | containerd.WithNewSpec( |
no test coverage detected