Skip to content

Commit d7f8ca9

Browse files
author
Ramkumar Chinchani
committed
feat: initial commit
This PR starts to implement the containerd "snapshot" which will call into atomfs APIs Signed-off-by: Ramkumar Chinchani <[email protected]>
1 parent fc2c26d commit d7f8ca9

File tree

6 files changed

+179
-1
lines changed

6 files changed

+179
-1
lines changed

Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ ifneq ($(STATIC),)
2626
endif
2727
GO_LD_FLAGS+='
2828

29-
.PHONY: all build clean
29+
# helper tools
30+
TOOLSDIR := $(shell pwd)/hack/tools
31+
NERDCTL := $(TOOLSDIR)/bin/nerdctl
32+
NERDCTL_VERSION := 2.0.0
33+
34+
.PHONY: all build clean tools
3035

3136
all: build
3237

@@ -39,3 +44,12 @@ atomfs-snapshotter-grpc:
3944

4045
clean:
4146
rm -rf $(OUTDIR)
47+
48+
# tools
49+
tools: $(NERDCTL)
50+
51+
$(NERDCTL):
52+
mkdir -p $(TOOLSDIR)/bin
53+
curl -Lo nerdctl.tar.gz https://github.com/containerd/nerdctl/releases/download/v$(NERDCTL_VERSION)/nerdctl-$(NERDCTL_VERSION)-linux-amd64.tar.gz
54+
tar xvzf nerdctl.tar.gz -C $(TOOLSDIR)/bin nerdctl
55+
rm nerdctl.tar.gz

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ address = "/run/atomfs-snapshotter-grpc/atomfs-snapshotter-grpc.sock"
2727
# tells containerd to use atomfs by default.
2828
snapshotter = "atomfs"
2929
```
30+
31+
## Run/test snapshotter
32+
33+
```
34+
bin/atomfs-snapshotter-grpc /run/atomfs-snapshotter-grpc/atomfs-snapshotter-grpc.sock /tmp/atomfs/
35+
36+
sudo containerd -c tests/containerd.toml
37+
38+
hack/tools/bin/nerdctl --snapshotter atomfs run public.ecr.aws/docker/library/busybox:stable
39+
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/Microsoft/go-winio v0.6.2 // indirect
1515
github.com/Microsoft/hcsshim v0.12.9 // indirect
1616
github.com/containerd/cgroups/v3 v3.0.3 // indirect
17+
github.com/containerd/containerd v1.7.24 // indirect
1718
github.com/containerd/continuity v0.4.4 // indirect
1819
github.com/containerd/errdefs v1.0.0 // indirect
1920
github.com/containerd/errdefs/pkg v0.3.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
99
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
1010
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
1111
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
12+
github.com/containerd/containerd v1.7.24 h1:zxszGrGjrra1yYJW/6rhm9cJ1ZQ8rkKBR48brqsa7nA=
13+
github.com/containerd/containerd v1.7.24/go.mod h1:7QUzfURqZWCZV7RLNEn1XjUCQLEf0bkaK4GjUaZehxw=
1214
github.com/containerd/containerd/api v1.8.0 h1:hVTNJKR8fMc/2Tiw60ZRijntNMd1U+JVMyTRdsD2bS0=
1315
github.com/containerd/containerd/api v1.8.0/go.mod h1:dFv4lt6S20wTu/hMcP4350RL87qPWLVa/OHOwmmdnYc=
1416
github.com/containerd/containerd/v2 v2.0.0 h1:qLDdFaAykQrIyLiqwQrNLLz95wiC36bAZVwioUwqShM=

snapshot/snapshot.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package snapshot
2+
3+
import (
4+
"context"
5+
6+
"github.com/containerd/containerd/snapshots"
7+
"github.com/containerd/containerd/v2/core/mount"
8+
)
9+
10+
var _ snapshots.Snapshotter = &snapshotter{}
11+
12+
type snapshotter struct {
13+
}
14+
15+
func NewSnapshotter(ctx context.Context) (snapshots.Snapshotter, error) {
16+
return &snapshotter{}, nil
17+
}
18+
19+
// Should be used for parent resolution, existence checks and to discern
20+
// the kind of snapshot.
21+
func (o *snapshotter) Stat(ctx context.Context, key string) (Info, error) {
22+
return nil
23+
}
24+
25+
// Update updates the info for a snapshot.
26+
//
27+
// Only mutable properties of a snapshot may be updated.
28+
func (o *snapshotter) Update(ctx context.Context, info Info, fieldpaths ...string) (Info, error) {
29+
return nil, nil
30+
}
31+
32+
// Usage returns the resource usage of an active or committed snapshot
33+
// excluding the usage of parent snapshots.
34+
//
35+
// The running time of this call for active snapshots is dependent on
36+
// implementation, but may be proportional to the size of the resource.
37+
// Callers should take this into consideration. Implementations should
38+
// attempt to honor context cancellation and avoid taking locks when making
39+
// the calculation.
40+
func (o *snapshotter) Usage(ctx context.Context, key string) (Usage, error) {
41+
return nil, nil
42+
}
43+
44+
// Mounts returns the mounts for the active snapshot transaction identified
45+
// by key. Can be called on a read-write or readonly transaction. This is
46+
// available only for active snapshots.
47+
//
48+
// This can be used to recover mounts after calling View or Prepare.
49+
func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
50+
return nil, nil
51+
}
52+
53+
// Prepare creates an active snapshot identified by key descending from the
54+
// provided parent. The returned mounts can be used to mount the snapshot
55+
// to capture changes.
56+
//
57+
// If a parent is provided, after performing the mounts, the destination
58+
// will start with the content of the parent. The parent must be a
59+
// committed snapshot. Changes to the mounted destination will be captured
60+
// in relation to the parent. The default parent, "", is an empty
61+
// directory.
62+
//
63+
// The changes may be saved to a committed snapshot by calling Commit. When
64+
// one is done with the transaction, Remove should be called on the key.
65+
//
66+
// Multiple calls to Prepare or View with the same key should fail.
67+
func (o *snapshotter) Prepare(ctx context.Context, key, parent string, opts ...Opt) ([]mount.Mount, error) {
68+
return nil, nil
69+
}
70+
71+
// View behaves identically to Prepare except the result may not be
72+
// committed back to the snapshot snapshotter. View returns a readonly view on
73+
// the parent, with the active snapshot being tracked by the given key.
74+
//
75+
// This method operates identically to Prepare, except the mounts returned
76+
// may have the readonly flag set. Any modifications to the underlying
77+
// filesystem will be ignored. Implementations may perform this in a more
78+
// efficient manner that differs from what would be attempted with
79+
// `Prepare`.
80+
//
81+
// Commit may not be called on the provided key and will return an error.
82+
// To collect the resources associated with key, Remove must be called with
83+
// key as the argument.
84+
func (o *snapshotter) View(ctx context.Context, key, parent string, opts ...Opt) ([]mount.Mount, error) {
85+
return nil, nil
86+
}
87+
88+
// Commit captures the changes between key and its parent into a snapshot
89+
// identified by name. The name can then be used with the snapshotter's other
90+
// methods to create subsequent snapshots.
91+
//
92+
// A committed snapshot will be created under name with the parent of the
93+
// active snapshot.
94+
//
95+
// After commit, the snapshot identified by key is removed.
96+
func (o *snapshotter) Commit(ctx context.Context, name, key string, opts ...Opt) error {
97+
return nil
98+
}
99+
100+
// Remove the committed or active snapshot by the provided key.
101+
//
102+
// All resources associated with the key will be removed.
103+
//
104+
// If the snapshot is a parent of another snapshot, its children must be
105+
// removed before proceeding.
106+
func (o *snapshotter) Remove(ctx context.Context, key string) error {
107+
return nil
108+
}
109+
110+
// Walk will call the provided function for each snapshot in the
111+
// snapshotter which match the provided filters. If no filters are
112+
// given all items will be walked.
113+
// Filters:
114+
//
115+
// name
116+
// parent
117+
// kind (active,view,committed)
118+
// labels.(label)
119+
func (o *snapshotter) Walk(ctx context.Context, fn WalkFunc, filters ...string) error {
120+
return nil
121+
}
122+
123+
// Close releases the internal resources.
124+
//
125+
// Close is expected to be called on the end of the lifecycle of the snapshotter,
126+
// but not mandatory.
127+
//
128+
// Close returns nil when it is already closed.
129+
func (o *snapshotter) Close() error {
130+
return nil
131+
}

tests/containerd.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version = 3
2+
[plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runc.options]
3+
SystemdCgroup = true
4+
[plugins.'io.containerd.cri.v1.images']
5+
snapshotter = "overlayfs"
6+
[proxy_plugins]
7+
[proxy_plugins.atomfs]
8+
# tells containerd that the atomfs plugin is a snapshotter and implements the snapshotter API
9+
type = "snapshot"
10+
# tells containerd where to connect to the atomfs snapshotter
11+
address = "/run/atomfs-snapshotter-grpc/atomfs-snapshotter-grpc.sock"
12+
[proxy_plugins.atomfs.exports]
13+
# defines the root data directory for the atomfs snapshotter. Kubernetes uses
14+
# this to calculate disk utilization, enforce storage limits, and trigger
15+
# garbage collection.
16+
root = "/var/lib/atomfs-snapshotter-grpc"
17+
18+
[plugins."io.containerd.grpc.v1.cri".containerd]
19+
# tells containerd to use atomfs by default.
20+
snapshotter = "atomfs"

0 commit comments

Comments
 (0)