X Tutup
Skip to content

Commit e9434a1

Browse files
authored
Merge pull request containerd#2341 from dmcgowan/move-client-content-snapshot
Move client implementations for content store and snapshotter
2 parents 195aec2 + 7c80d0a commit e9434a1

File tree

5 files changed

+67
-64
lines changed

5 files changed

+67
-64
lines changed

client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
versionservice "github.com/containerd/containerd/api/services/version/v1"
3939
"github.com/containerd/containerd/containers"
4040
"github.com/containerd/containerd/content"
41+
contentproxy "github.com/containerd/containerd/content/proxy"
4142
"github.com/containerd/containerd/defaults"
4243
"github.com/containerd/containerd/errdefs"
4344
"github.com/containerd/containerd/events"
@@ -49,6 +50,7 @@ import (
4950
"github.com/containerd/containerd/remotes/docker"
5051
"github.com/containerd/containerd/remotes/docker/schema1"
5152
"github.com/containerd/containerd/snapshots"
53+
snproxy "github.com/containerd/containerd/snapshots/proxy"
5254
"github.com/containerd/typeurl"
5355
ptypes "github.com/gogo/protobuf/types"
5456
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -464,15 +466,15 @@ func (c *Client) ContentStore() content.Store {
464466
if c.contentStore != nil {
465467
return c.contentStore
466468
}
467-
return NewContentStoreFromClient(contentapi.NewContentClient(c.conn))
469+
return contentproxy.NewContentStore(contentapi.NewContentClient(c.conn))
468470
}
469471

470472
// SnapshotService returns the underlying snapshotter for the provided snapshotter name
471473
func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter {
472474
if c.snapshotters != nil {
473475
return c.snapshotters[snapshotterName]
474476
}
475-
return NewSnapshotterFromClient(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName)
477+
return snproxy.NewSnapshotter(snapshotsapi.NewSnapshotsClient(c.conn), snapshotterName)
476478
}
477479

478480
// TaskService returns the underlying TasksClient
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package containerd
17+
package proxy
1818

1919
import (
2020
"context"
Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package containerd
17+
package proxy
1818

1919
import (
2020
"context"
@@ -27,19 +27,20 @@ import (
2727
digest "github.com/opencontainers/go-digest"
2828
)
2929

30-
type remoteContent struct {
30+
type proxyContentStore struct {
3131
client contentapi.ContentClient
3232
}
3333

34-
// NewContentStoreFromClient returns a new content store
35-
func NewContentStoreFromClient(client contentapi.ContentClient) content.Store {
36-
return &remoteContent{
34+
// NewContentStore returns a new content store which communicates over a GRPC
35+
// connection using the containerd content GRPC API.
36+
func NewContentStore(client contentapi.ContentClient) content.Store {
37+
return &proxyContentStore{
3738
client: client,
3839
}
3940
}
4041

41-
func (rs *remoteContent) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
42-
resp, err := rs.client.Info(ctx, &contentapi.InfoRequest{
42+
func (pcs *proxyContentStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
43+
resp, err := pcs.client.Info(ctx, &contentapi.InfoRequest{
4344
Digest: dgst,
4445
})
4546
if err != nil {
@@ -49,8 +50,8 @@ func (rs *remoteContent) Info(ctx context.Context, dgst digest.Digest) (content.
4950
return infoFromGRPC(resp.Info), nil
5051
}
5152

52-
func (rs *remoteContent) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
53-
session, err := rs.client.List(ctx, &contentapi.ListContentRequest{
53+
func (pcs *proxyContentStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
54+
session, err := pcs.client.List(ctx, &contentapi.ListContentRequest{
5455
Filters: filters,
5556
})
5657
if err != nil {
@@ -77,8 +78,8 @@ func (rs *remoteContent) Walk(ctx context.Context, fn content.WalkFunc, filters
7778
return nil
7879
}
7980

80-
func (rs *remoteContent) Delete(ctx context.Context, dgst digest.Digest) error {
81-
if _, err := rs.client.Delete(ctx, &contentapi.DeleteContentRequest{
81+
func (pcs *proxyContentStore) Delete(ctx context.Context, dgst digest.Digest) error {
82+
if _, err := pcs.client.Delete(ctx, &contentapi.DeleteContentRequest{
8283
Digest: dgst,
8384
}); err != nil {
8485
return errdefs.FromGRPC(err)
@@ -87,8 +88,8 @@ func (rs *remoteContent) Delete(ctx context.Context, dgst digest.Digest) error {
8788
return nil
8889
}
8990

90-
func (rs *remoteContent) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) {
91-
i, err := rs.Info(ctx, dgst)
91+
func (pcs *proxyContentStore) ReaderAt(ctx context.Context, dgst digest.Digest) (content.ReaderAt, error) {
92+
i, err := pcs.Info(ctx, dgst)
9293
if err != nil {
9394
return nil, err
9495
}
@@ -97,12 +98,12 @@ func (rs *remoteContent) ReaderAt(ctx context.Context, dgst digest.Digest) (cont
9798
ctx: ctx,
9899
digest: dgst,
99100
size: i.Size,
100-
client: rs.client,
101+
client: pcs.client,
101102
}, nil
102103
}
103104

104-
func (rs *remoteContent) Status(ctx context.Context, ref string) (content.Status, error) {
105-
resp, err := rs.client.Status(ctx, &contentapi.StatusRequest{
105+
func (pcs *proxyContentStore) Status(ctx context.Context, ref string) (content.Status, error) {
106+
resp, err := pcs.client.Status(ctx, &contentapi.StatusRequest{
106107
Ref: ref,
107108
})
108109
if err != nil {
@@ -120,8 +121,8 @@ func (rs *remoteContent) Status(ctx context.Context, ref string) (content.Status
120121
}, nil
121122
}
122123

123-
func (rs *remoteContent) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
124-
resp, err := rs.client.Update(ctx, &contentapi.UpdateRequest{
124+
func (pcs *proxyContentStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
125+
resp, err := pcs.client.Update(ctx, &contentapi.UpdateRequest{
125126
Info: infoToGRPC(info),
126127
UpdateMask: &protobuftypes.FieldMask{
127128
Paths: fieldpaths,
@@ -133,8 +134,8 @@ func (rs *remoteContent) Update(ctx context.Context, info content.Info, fieldpat
133134
return infoFromGRPC(resp.Info), nil
134135
}
135136

136-
func (rs *remoteContent) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
137-
resp, err := rs.client.ListStatuses(ctx, &contentapi.ListStatusesRequest{
137+
func (pcs *proxyContentStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
138+
resp, err := pcs.client.ListStatuses(ctx, &contentapi.ListStatusesRequest{
138139
Filters: filters,
139140
})
140141
if err != nil {
@@ -156,8 +157,8 @@ func (rs *remoteContent) ListStatuses(ctx context.Context, filters ...string) ([
156157
return statuses, nil
157158
}
158159

159-
func (rs *remoteContent) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) {
160-
wrclient, offset, err := rs.negotiate(ctx, ref, size, expected)
160+
func (pcs *proxyContentStore) Writer(ctx context.Context, ref string, size int64, expected digest.Digest) (content.Writer, error) {
161+
wrclient, offset, err := pcs.negotiate(ctx, ref, size, expected)
161162
if err != nil {
162163
return nil, errdefs.FromGRPC(err)
163164
}
@@ -170,8 +171,8 @@ func (rs *remoteContent) Writer(ctx context.Context, ref string, size int64, exp
170171
}
171172

172173
// Abort implements asynchronous abort. It starts a new write session on the ref l
173-
func (rs *remoteContent) Abort(ctx context.Context, ref string) error {
174-
if _, err := rs.client.Abort(ctx, &contentapi.AbortRequest{
174+
func (pcs *proxyContentStore) Abort(ctx context.Context, ref string) error {
175+
if _, err := pcs.client.Abort(ctx, &contentapi.AbortRequest{
175176
Ref: ref,
176177
}); err != nil {
177178
return errdefs.FromGRPC(err)
@@ -180,8 +181,8 @@ func (rs *remoteContent) Abort(ctx context.Context, ref string) error {
180181
return nil
181182
}
182183

183-
func (rs *remoteContent) negotiate(ctx context.Context, ref string, size int64, expected digest.Digest) (contentapi.Content_WriteClient, int64, error) {
184-
wrclient, err := rs.client.Write(ctx)
184+
func (pcs *proxyContentStore) negotiate(ctx context.Context, ref string, size int64, expected digest.Digest) (contentapi.Content_WriteClient, int64, error) {
185+
wrclient, err := pcs.client.Write(ctx)
185186
if err != nil {
186187
return nil, 0, err
187188
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package containerd
17+
package proxy
1818

1919
import (
2020
"context"

snapshot.go renamed to snapshots/proxy/proxy.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package containerd
17+
package proxy
1818

1919
import (
2020
"context"
@@ -28,24 +28,24 @@ import (
2828
protobuftypes "github.com/gogo/protobuf/types"
2929
)
3030

31-
// NewSnapshotterFromClient returns a new Snapshotter which communicates
32-
// over a GRPC connection.
33-
func NewSnapshotterFromClient(client snapshotsapi.SnapshotsClient, snapshotterName string) snapshots.Snapshotter {
34-
return &remoteSnapshotter{
31+
// NewSnapshotter returns a new Snapshotter which communicates over a GRPC
32+
// connection using the containerd snapshot GRPC API.
33+
func NewSnapshotter(client snapshotsapi.SnapshotsClient, snapshotterName string) snapshots.Snapshotter {
34+
return &proxySnapshotter{
3535
client: client,
3636
snapshotterName: snapshotterName,
3737
}
3838
}
3939

40-
type remoteSnapshotter struct {
40+
type proxySnapshotter struct {
4141
client snapshotsapi.SnapshotsClient
4242
snapshotterName string
4343
}
4444

45-
func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
46-
resp, err := r.client.Stat(ctx,
45+
func (p *proxySnapshotter) Stat(ctx context.Context, key string) (snapshots.Info, error) {
46+
resp, err := p.client.Stat(ctx,
4747
&snapshotsapi.StatSnapshotRequest{
48-
Snapshotter: r.snapshotterName,
48+
Snapshotter: p.snapshotterName,
4949
Key: key,
5050
})
5151
if err != nil {
@@ -54,10 +54,10 @@ func (r *remoteSnapshotter) Stat(ctx context.Context, key string) (snapshots.Inf
5454
return toInfo(resp.Info), nil
5555
}
5656

57-
func (r *remoteSnapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
58-
resp, err := r.client.Update(ctx,
57+
func (p *proxySnapshotter) Update(ctx context.Context, info snapshots.Info, fieldpaths ...string) (snapshots.Info, error) {
58+
resp, err := p.client.Update(ctx,
5959
&snapshotsapi.UpdateSnapshotRequest{
60-
Snapshotter: r.snapshotterName,
60+
Snapshotter: p.snapshotterName,
6161
Info: fromInfo(info),
6262
UpdateMask: &protobuftypes.FieldMask{
6363
Paths: fieldpaths,
@@ -69,9 +69,9 @@ func (r *remoteSnapshotter) Update(ctx context.Context, info snapshots.Info, fie
6969
return toInfo(resp.Info), nil
7070
}
7171

72-
func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
73-
resp, err := r.client.Usage(ctx, &snapshotsapi.UsageRequest{
74-
Snapshotter: r.snapshotterName,
72+
func (p *proxySnapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {
73+
resp, err := p.client.Usage(ctx, &snapshotsapi.UsageRequest{
74+
Snapshotter: p.snapshotterName,
7575
Key: key,
7676
})
7777
if err != nil {
@@ -80,9 +80,9 @@ func (r *remoteSnapshotter) Usage(ctx context.Context, key string) (snapshots.Us
8080
return toUsage(resp), nil
8181
}
8282

83-
func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
84-
resp, err := r.client.Mounts(ctx, &snapshotsapi.MountsRequest{
85-
Snapshotter: r.snapshotterName,
83+
func (p *proxySnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, error) {
84+
resp, err := p.client.Mounts(ctx, &snapshotsapi.MountsRequest{
85+
Snapshotter: p.snapshotterName,
8686
Key: key,
8787
})
8888
if err != nil {
@@ -91,15 +91,15 @@ func (r *remoteSnapshotter) Mounts(ctx context.Context, key string) ([]mount.Mou
9191
return toMounts(resp.Mounts), nil
9292
}
9393

94-
func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
94+
func (p *proxySnapshotter) Prepare(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
9595
var local snapshots.Info
9696
for _, opt := range opts {
9797
if err := opt(&local); err != nil {
9898
return nil, err
9999
}
100100
}
101-
resp, err := r.client.Prepare(ctx, &snapshotsapi.PrepareSnapshotRequest{
102-
Snapshotter: r.snapshotterName,
101+
resp, err := p.client.Prepare(ctx, &snapshotsapi.PrepareSnapshotRequest{
102+
Snapshotter: p.snapshotterName,
103103
Key: key,
104104
Parent: parent,
105105
Labels: local.Labels,
@@ -110,15 +110,15 @@ func (r *remoteSnapshotter) Prepare(ctx context.Context, key, parent string, opt
110110
return toMounts(resp.Mounts), nil
111111
}
112112

113-
func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
113+
func (p *proxySnapshotter) View(ctx context.Context, key, parent string, opts ...snapshots.Opt) ([]mount.Mount, error) {
114114
var local snapshots.Info
115115
for _, opt := range opts {
116116
if err := opt(&local); err != nil {
117117
return nil, err
118118
}
119119
}
120-
resp, err := r.client.View(ctx, &snapshotsapi.ViewSnapshotRequest{
121-
Snapshotter: r.snapshotterName,
120+
resp, err := p.client.View(ctx, &snapshotsapi.ViewSnapshotRequest{
121+
Snapshotter: p.snapshotterName,
122122
Key: key,
123123
Parent: parent,
124124
Labels: local.Labels,
@@ -129,33 +129,33 @@ func (r *remoteSnapshotter) View(ctx context.Context, key, parent string, opts .
129129
return toMounts(resp.Mounts), nil
130130
}
131131

132-
func (r *remoteSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
132+
func (p *proxySnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error {
133133
var local snapshots.Info
134134
for _, opt := range opts {
135135
if err := opt(&local); err != nil {
136136
return err
137137
}
138138
}
139-
_, err := r.client.Commit(ctx, &snapshotsapi.CommitSnapshotRequest{
140-
Snapshotter: r.snapshotterName,
139+
_, err := p.client.Commit(ctx, &snapshotsapi.CommitSnapshotRequest{
140+
Snapshotter: p.snapshotterName,
141141
Name: name,
142142
Key: key,
143143
Labels: local.Labels,
144144
})
145145
return errdefs.FromGRPC(err)
146146
}
147147

148-
func (r *remoteSnapshotter) Remove(ctx context.Context, key string) error {
149-
_, err := r.client.Remove(ctx, &snapshotsapi.RemoveSnapshotRequest{
150-
Snapshotter: r.snapshotterName,
148+
func (p *proxySnapshotter) Remove(ctx context.Context, key string) error {
149+
_, err := p.client.Remove(ctx, &snapshotsapi.RemoveSnapshotRequest{
150+
Snapshotter: p.snapshotterName,
151151
Key: key,
152152
})
153153
return errdefs.FromGRPC(err)
154154
}
155155

156-
func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
157-
sc, err := r.client.List(ctx, &snapshotsapi.ListSnapshotsRequest{
158-
Snapshotter: r.snapshotterName,
156+
func (p *proxySnapshotter) Walk(ctx context.Context, fn func(context.Context, snapshots.Info) error) error {
157+
sc, err := p.client.List(ctx, &snapshotsapi.ListSnapshotsRequest{
158+
Snapshotter: p.snapshotterName,
159159
})
160160
if err != nil {
161161
return errdefs.FromGRPC(err)
@@ -179,7 +179,7 @@ func (r *remoteSnapshotter) Walk(ctx context.Context, fn func(context.Context, s
179179
}
180180
}
181181

182-
func (r *remoteSnapshotter) Close() error {
182+
func (p *proxySnapshotter) Close() error {
183183
return nil
184184
}
185185

0 commit comments

Comments
 (0)
X Tutup