X Tutup
Skip to content

Commit 73bec3e

Browse files
committed
client: rename rootfs to snapshot in "With" functions
Clarify terminology around functions which use and create snapshots for containers. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
1 parent 9434bf9 commit 73bec3e

File tree

12 files changed

+51
-51
lines changed

12 files changed

+51
-51
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ image, err := client.Pull(context, "docker.io/library/redis:latest", containerd.
8686
// allocate a new RW root filesystem for a container based on the image
8787
redis, err := client.NewContainer(context, "redis-master",
8888
containerd.WithSpec(spec),
89-
containerd.WithNewRootFS("redis-rootfs", image),
89+
containerd.WithNewSnapshot("redis-rootfs", image),
9090
)
9191

9292
// use a readonly filesystem with multiple containers
9393
for i := 0; i < 10; i++ {
9494
id := fmt.Sprintf("id-%s", i)
9595
container, err := client.NewContainer(ctx, id,
9696
containerd.WithSpec(spec),
97-
containerd.WithNewReadonlyRootFS(id, image),
97+
containerd.WithNewSnapshotView(id, image),
9898
)
9999
}
100100
```

benchmark_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func BenchmarkContainerCreate(b *testing.B) {
2828
var containers []Container
2929
defer func() {
3030
for _, c := range containers {
31-
if err := c.Delete(ctx, WithRootFSDeletion); err != nil {
31+
if err := c.Delete(ctx, WithSnapshotCleanup); err != nil {
3232
b.Error(err)
3333
}
3434
}
@@ -38,7 +38,7 @@ func BenchmarkContainerCreate(b *testing.B) {
3838
b.ResetTimer()
3939
for i := 0; i < b.N; i++ {
4040
id := fmt.Sprintf("%s-%d", b.Name(), i)
41-
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
41+
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewSnapshot(id, image))
4242
if err != nil {
4343
b.Error(err)
4444
return
@@ -71,15 +71,15 @@ func BenchmarkContainerStart(b *testing.B) {
7171
var containers []Container
7272
defer func() {
7373
for _, c := range containers {
74-
if err := c.Delete(ctx, WithRootFSDeletion); err != nil {
74+
if err := c.Delete(ctx, WithSnapshotCleanup); err != nil {
7575
b.Error(err)
7676
}
7777
}
7878
}()
7979

8080
for i := 0; i < b.N; i++ {
8181
id := fmt.Sprintf("%s-%d", b.Name(), i)
82-
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
82+
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewSnapshot(id, image))
8383
if err != nil {
8484
b.Error(err)
8585
return

checkpoint_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ func TestCheckpointRestore(t *testing.T) {
3333
t.Error(err)
3434
return
3535
}
36-
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
36+
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewSnapshot(id, image))
3737
if err != nil {
3838
t.Error(err)
3939
return
4040
}
41-
defer container.Delete(ctx, WithRootFSDeletion)
41+
defer container.Delete(ctx, WithSnapshotCleanup)
4242

4343
task, err := container.NewTask(ctx, empty())
4444
if err != nil {
@@ -123,12 +123,12 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
123123
t.Error(err)
124124
return
125125
}
126-
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
126+
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewSnapshot(id, image))
127127
if err != nil {
128128
t.Error(err)
129129
return
130130
}
131-
defer container.Delete(ctx, WithRootFSDeletion)
131+
defer container.Delete(ctx, WithSnapshotCleanup)
132132

133133
task, err := container.NewTask(ctx, empty())
134134
if err != nil {
@@ -163,7 +163,7 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
163163
t.Error(err)
164164
return
165165
}
166-
if err := container.Delete(ctx, WithRootFSDeletion); err != nil {
166+
if err := container.Delete(ctx, WithSnapshotCleanup); err != nil {
167167
t.Error(err)
168168
return
169169
}
@@ -226,12 +226,12 @@ func TestCheckpointLeaveRunning(t *testing.T) {
226226
t.Error(err)
227227
return
228228
}
229-
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
229+
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewSnapshot(id, image))
230230
if err != nil {
231231
t.Error(err)
232232
return
233233
}
234-
defer container.Delete(ctx, WithRootFSDeletion)
234+
defer container.Delete(ctx, WithSnapshotCleanup)
235235

236236
task, err := container.NewTask(ctx, empty())
237237
if err != nil {

client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ func WithContainerLabels(labels map[string]string) NewContainerOpts {
161161
}
162162
}
163163

164-
// WithExistingRootFS uses an existing root filesystem for the container
165-
func WithExistingRootFS(id string) NewContainerOpts {
164+
// WithSnapshot uses an existing root filesystem for the container
165+
func WithSnapshot(id string) NewContainerOpts {
166166
return func(ctx context.Context, client *Client, c *containers.Container) error {
167167
// check that the snapshot exists, if not, fail on creation
168168
if _, err := client.SnapshotService(c.Snapshotter).Mounts(ctx, id); err != nil {
@@ -173,9 +173,9 @@ func WithExistingRootFS(id string) NewContainerOpts {
173173
}
174174
}
175175

176-
// WithNewRootFS allocates a new snapshot to be used by the container as the
176+
// WithNewSnapshot allocates a new snapshot to be used by the container as the
177177
// root filesystem in read-write mode
178-
func WithNewRootFS(id string, i Image) NewContainerOpts {
178+
func WithNewSnapshot(id string, i Image) NewContainerOpts {
179179
return func(ctx context.Context, client *Client, c *containers.Container) error {
180180
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore())
181181
if err != nil {
@@ -190,9 +190,9 @@ func WithNewRootFS(id string, i Image) NewContainerOpts {
190190
}
191191
}
192192

193-
// WithNewReadonlyRootFS allocates a new snapshot to be used by the container as the
193+
// WithNewSnapshotView allocates a new snapshot to be used by the container as the
194194
// root filesystem in read-only mode
195-
func WithNewReadonlyRootFS(id string, i Image) NewContainerOpts {
195+
func WithNewSnapshotView(id string, i Image) NewContainerOpts {
196196
return func(ctx context.Context, client *Client, c *containers.Container) error {
197197
diffIDs, err := i.(*image).i.RootFS(ctx, client.ContentStore())
198198
if err != nil {

cmd/ctr/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var deleteCommand = cli.Command{
2626
}
2727
deleteOpts := []containerd.DeleteOpts{}
2828
if !context.Bool("keep-snapshot") {
29-
deleteOpts = append(deleteOpts, containerd.WithRootFSDeletion)
29+
deleteOpts = append(deleteOpts, containerd.WithSnapshotCleanup)
3030
}
3131
container, err := client.LoadContainer(ctx, context.Args().First())
3232
if err != nil {

cmd/ctr/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ var runCommand = cli.Command{
119119
return err
120120
}
121121
if context.Bool("rm") {
122-
defer container.Delete(ctx, containerd.WithRootFSDeletion)
122+
defer container.Delete(ctx, containerd.WithSnapshotCleanup)
123123
}
124124
task, err := newTask(ctx, container, checkpointIndex, tty)
125125
if err != nil {

cmd/ctr/run_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
9797
}
9898
var rootfs containerd.NewContainerOpts
9999
if context.Bool("readonly") {
100-
rootfs = containerd.WithNewReadonlyRootFS(id, image)
100+
rootfs = containerd.WithNewSnapshotView(id, image)
101101
} else {
102-
rootfs = containerd.WithNewRootFS(id, image)
102+
rootfs = containerd.WithNewSnapshot(id, image)
103103
}
104104

105105
return client.NewContainer(ctx, id,

container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ func (c *container) Spec() (*specs.Spec, error) {
107107
return &s, nil
108108
}
109109

110-
// WithRootFSDeletion deletes the rootfs allocated for the container
111-
func WithRootFSDeletion(ctx context.Context, client *Client, c containers.Container) error {
110+
// WithSnapshotCleanup deletes the rootfs allocated for the container
111+
func WithSnapshotCleanup(ctx context.Context, client *Client, c containers.Container) error {
112112
if c.RootFS != "" {
113113
return client.SnapshotService(c.Snapshotter).Remove(ctx, c.RootFS)
114114
}

container_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func TestContainerUpdate(t *testing.T) {
3737
spec.Linux.Resources.Memory = &specs.LinuxMemory{
3838
Limit: &limit,
3939
}
40-
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewRootFS(id, image))
40+
container, err := client.NewContainer(ctx, id, WithSpec(spec), WithNewSnapshot(id, image))
4141
if err != nil {
4242
t.Error(err)
4343
return
4444
}
45-
defer container.Delete(ctx, WithRootFSDeletion)
45+
defer container.Delete(ctx, WithSnapshotCleanup)
4646

4747
task, err := container.NewTask(ctx, empty())
4848
if err != nil {

container_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ func TestContainerStart(t *testing.T) {
106106
t.Error(err)
107107
return
108108
}
109-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
109+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
110110
if err != nil {
111111
t.Error(err)
112112
return
113113
}
114-
defer container.Delete(ctx, WithRootFSDeletion)
114+
defer container.Delete(ctx, WithSnapshotCleanup)
115115

116116
task, err := container.NewTask(ctx, Stdio)
117117
if err != nil {
@@ -178,12 +178,12 @@ func TestContainerOutput(t *testing.T) {
178178
t.Error(err)
179179
return
180180
}
181-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
181+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
182182
if err != nil {
183183
t.Error(err)
184184
return
185185
}
186-
defer container.Delete(ctx, WithRootFSDeletion)
186+
defer container.Delete(ctx, WithSnapshotCleanup)
187187

188188
stdout := bytes.NewBuffer(nil)
189189
task, err := container.NewTask(ctx, NewIO(bytes.NewBuffer(nil), stdout, bytes.NewBuffer(nil)))
@@ -251,12 +251,12 @@ func TestContainerExec(t *testing.T) {
251251
t.Error(err)
252252
return
253253
}
254-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
254+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
255255
if err != nil {
256256
t.Error(err)
257257
return
258258
}
259-
defer container.Delete(ctx, WithRootFSDeletion)
259+
defer container.Delete(ctx, WithSnapshotCleanup)
260260

261261
task, err := container.NewTask(ctx, empty())
262262
if err != nil {
@@ -348,12 +348,12 @@ func TestContainerPids(t *testing.T) {
348348
t.Error(err)
349349
return
350350
}
351-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
351+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
352352
if err != nil {
353353
t.Error(err)
354354
return
355355
}
356-
defer container.Delete(ctx, WithRootFSDeletion)
356+
defer container.Delete(ctx, WithSnapshotCleanup)
357357

358358
task, err := container.NewTask(ctx, empty())
359359
if err != nil {
@@ -427,12 +427,12 @@ func TestContainerCloseIO(t *testing.T) {
427427
t.Error(err)
428428
return
429429
}
430-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
430+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
431431
if err != nil {
432432
t.Error(err)
433433
return
434434
}
435-
defer container.Delete(ctx, WithRootFSDeletion)
435+
defer container.Delete(ctx, WithSnapshotCleanup)
436436

437437
const expected = "hello" + newLine
438438
stdout := bytes.NewBuffer(nil)
@@ -525,12 +525,12 @@ func TestContainerAttach(t *testing.T) {
525525
t.Error(err)
526526
return
527527
}
528-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
528+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
529529
if err != nil {
530530
t.Error(err)
531531
return
532532
}
533-
defer container.Delete(ctx, WithRootFSDeletion)
533+
defer container.Delete(ctx, WithSnapshotCleanup)
534534

535535
expected := "hello" + newLine
536536
stdout := bytes.NewBuffer(nil)
@@ -651,12 +651,12 @@ func TestDeleteRunningContainer(t *testing.T) {
651651
t.Error(err)
652652
return
653653
}
654-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
654+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
655655
if err != nil {
656656
t.Error(err)
657657
return
658658
}
659-
defer container.Delete(ctx, WithRootFSDeletion)
659+
defer container.Delete(ctx, WithSnapshotCleanup)
660660

661661
task, err := container.NewTask(ctx, empty())
662662
if err != nil {
@@ -679,7 +679,7 @@ func TestDeleteRunningContainer(t *testing.T) {
679679
return
680680
}
681681

682-
err = container.Delete(ctx, WithRootFSDeletion)
682+
err = container.Delete(ctx, WithSnapshotCleanup)
683683
if err == nil {
684684
t.Error("delete did not error with running task")
685685
}
@@ -720,7 +720,7 @@ func TestContainerKill(t *testing.T) {
720720
t.Error(err)
721721
return
722722
}
723-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
723+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
724724
if err != nil {
725725
t.Error(err)
726726
return
@@ -790,12 +790,12 @@ func TestContainerNoBinaryExists(t *testing.T) {
790790
t.Error(err)
791791
return
792792
}
793-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
793+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
794794
if err != nil {
795795
t.Error(err)
796796
return
797797
}
798-
defer container.Delete(ctx, WithRootFSDeletion)
798+
defer container.Delete(ctx, WithSnapshotCleanup)
799799

800800
task, err := container.NewTask(ctx, Stdio)
801801
switch runtime.GOOS {
@@ -842,12 +842,12 @@ func TestContainerExecNoBinaryExists(t *testing.T) {
842842
t.Error(err)
843843
return
844844
}
845-
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewRootFS(id, image))
845+
container, err := client.NewContainer(ctx, id, WithSpec(spec), withNewSnapshot(id, image))
846846
if err != nil {
847847
t.Error(err)
848848
return
849849
}
850-
defer container.Delete(ctx, WithRootFSDeletion)
850+
defer container.Delete(ctx, WithSnapshotCleanup)
851851

852852
task, err := container.NewTask(ctx, empty())
853853
if err != nil {

0 commit comments

Comments
 (0)
X Tutup