@@ -19,23 +19,26 @@ package images
1919import (
2020 "context"
2121
22+ "github.com/containerd/log"
23+ "google.golang.org/grpc"
24+ "google.golang.org/grpc/codes"
25+ "google.golang.org/grpc/status"
26+
2227 eventstypes "github.com/containerd/containerd/api/events"
2328 imagesapi "github.com/containerd/containerd/api/services/images/v1"
2429 "github.com/containerd/containerd/errdefs"
2530 "github.com/containerd/containerd/events"
2631 "github.com/containerd/containerd/gc"
2732 "github.com/containerd/containerd/images"
2833 "github.com/containerd/containerd/metadata"
34+ "github.com/containerd/containerd/pkg/deprecation"
2935 "github.com/containerd/containerd/pkg/epoch"
3036 "github.com/containerd/containerd/plugin"
3137 "github.com/containerd/containerd/plugin/registry"
3238 "github.com/containerd/containerd/plugins"
3339 ptypes "github.com/containerd/containerd/protobuf/types"
3440 "github.com/containerd/containerd/services"
35- "github.com/containerd/log"
36- "google.golang.org/grpc"
37- "google.golang.org/grpc/codes"
38- "google.golang.org/grpc/status"
41+ "github.com/containerd/containerd/services/warning"
3942)
4043
4144func init () {
@@ -46,6 +49,7 @@ func init() {
4649 plugins .EventPlugin ,
4750 plugins .MetadataPlugin ,
4851 plugins .GCPlugin ,
52+ plugins .WarningPlugin ,
4953 },
5054 InitFn : func (ic * plugin.InitContext ) (interface {}, error ) {
5155 m , err := ic .Get (plugins .MetadataPlugin )
@@ -56,16 +60,20 @@ func init() {
5660 if err != nil {
5761 return nil , err
5862 }
59-
6063 ep , err := ic .Get (plugins .EventPlugin )
6164 if err != nil {
6265 return nil , err
6366 }
67+ w , err := ic .Get (plugins .WarningPlugin )
68+ if err != nil {
69+ return nil , err
70+ }
6471
6572 return & local {
6673 store : metadata .NewImageStore (m .(* metadata.DB )),
6774 publisher : ep .(events.Publisher ),
6875 gc : g .(gcScheduler ),
76+ warnings : w .(warning.Service ),
6977 }, nil
7078 },
7179 })
@@ -79,6 +87,7 @@ type local struct {
7987 store images.Store
8088 gc gcScheduler
8189 publisher events.Publisher
90+ warnings warning.Service
8291}
8392
8493var _ imagesapi.ImagesClient = & local {}
@@ -134,6 +143,7 @@ func (l *local) Create(ctx context.Context, req *imagesapi.CreateImageRequest, _
134143 return nil , err
135144 }
136145
146+ l .emitSchema1DeprecationWarning (ctx , & image )
137147 return & resp , nil
138148
139149}
@@ -172,6 +182,7 @@ func (l *local) Update(ctx context.Context, req *imagesapi.UpdateImageRequest, _
172182 return nil , err
173183 }
174184
185+ l .emitSchema1DeprecationWarning (ctx , & image )
175186 return & resp , nil
176187}
177188
@@ -203,3 +214,15 @@ func (l *local) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest, _
203214
204215 return & ptypes.Empty {}, nil
205216}
217+
218+ func (l * local ) emitSchema1DeprecationWarning (ctx context.Context , image * images.Image ) {
219+ if image == nil {
220+ return
221+ }
222+ dgst , ok := image .Labels [images .ConvertedDockerSchema1LabelKey ]
223+ if ! ok {
224+ return
225+ }
226+ log .G (ctx ).WithField ("name" , image .Name ).WithField ("schema1digest" , dgst ).Warn ("conversion from schema 1 images is deprecated" )
227+ l .warnings .Emit (ctx , deprecation .PullSchema1Image )
228+ }
0 commit comments