@@ -18,46 +18,71 @@ package introspection
1818
1919import (
2020 context "context"
21+ "errors"
2122 "os"
2223 "path/filepath"
2324 "runtime"
2425 "sync"
2526
27+ "github.com/google/uuid"
28+ "google.golang.org/genproto/googleapis/rpc/code"
29+ rpc "google.golang.org/genproto/googleapis/rpc/status"
30+ "google.golang.org/grpc"
31+ "google.golang.org/grpc/status"
32+
2633 api "github.com/containerd/containerd/api/services/introspection/v1"
2734 "github.com/containerd/containerd/api/types"
2835 "github.com/containerd/containerd/errdefs"
2936 "github.com/containerd/containerd/filters"
3037 "github.com/containerd/containerd/plugin"
38+ "github.com/containerd/containerd/protobuf"
3139 ptypes "github.com/containerd/containerd/protobuf/types"
3240 "github.com/containerd/containerd/services"
33- "github.com/google/uuid"
34- "google.golang.org/genproto/googleapis/rpc/code"
35- rpc "google.golang.org/genproto/googleapis/rpc/status"
36- "google.golang.org/grpc"
37- "google.golang.org/grpc/status"
41+ "github.com/containerd/containerd/services/warning"
3842)
3943
4044func init () {
4145 plugin .Register (& plugin.Registration {
4246 Type : plugin .ServicePlugin ,
4347 ID : services .IntrospectionService ,
44- Requires : []plugin.Type {},
48+ Requires : []plugin.Type {plugin . WarningPlugin },
4549 InitFn : func (ic * plugin.InitContext ) (interface {}, error ) {
50+ sps , err := ic .GetByType (plugin .WarningPlugin )
51+ if err != nil {
52+ return nil , err
53+ }
54+ p , ok := sps [plugin .DeprecationsPlugin ]
55+ if ! ok {
56+ return nil , errors .New ("warning service not found" )
57+ }
58+
59+ i , err := p .Instance ()
60+ if err != nil {
61+ return nil , err
62+ }
63+
64+ warningClient , ok := i .(warning.Service )
65+ if ! ok {
66+ return nil , errors .New ("could not create a local client for warning service" )
67+ }
68+
4669 // this service fetches all plugins through the plugin set of the plugin context
4770 return & Local {
48- plugins : ic .Plugins (),
49- root : ic .Root ,
71+ plugins : ic .Plugins (),
72+ root : ic .Root ,
73+ warningClient : warningClient ,
5074 }, nil
5175 },
5276 })
5377}
5478
5579// Local is a local implementation of the introspection service
5680type Local struct {
57- mu sync.Mutex
58- root string
59- plugins * plugin.Set
60- pluginCache []* api.Plugin
81+ mu sync.Mutex
82+ root string
83+ plugins * plugin.Set
84+ pluginCache []* api.Plugin
85+ warningClient warning.Service
6186}
6287
6388var _ = (api .IntrospectionClient )(& Local {})
@@ -115,9 +140,10 @@ func (l *Local) Server(ctx context.Context, _ *ptypes.Empty, _ ...grpc.CallOptio
115140 }
116141 }
117142 return & api.ServerResponse {
118- UUID : u ,
119- Pid : uint64 (pid ),
120- Pidns : pidns ,
143+ UUID : u ,
144+ Pid : uint64 (pid ),
145+ Pidns : pidns ,
146+ Deprecations : l .getWarnings (ctx ),
121147 }, nil
122148}
123149
@@ -159,6 +185,10 @@ func (l *Local) uuidPath() string {
159185 return filepath .Join (l .root , "uuid" )
160186}
161187
188+ func (l * Local ) getWarnings (ctx context.Context ) []* api.DeprecationWarning {
189+ return warningsPB (ctx , l .warningClient .Warnings ())
190+ }
191+
162192func adaptPlugin (o interface {}) filters.Adaptor {
163193 obj := o .(* api.Plugin )
164194 return filters .AdapterFunc (func (fieldpath []string ) (string , bool ) {
@@ -240,3 +270,16 @@ func pluginsToPB(plugins []*plugin.Plugin) []*api.Plugin {
240270
241271 return pluginsPB
242272}
273+
274+ func warningsPB (ctx context.Context , warnings []warning.Warning ) []* api.DeprecationWarning {
275+ var pb []* api.DeprecationWarning
276+
277+ for _ , w := range warnings {
278+ pb = append (pb , & api.DeprecationWarning {
279+ ID : string (w .ID ),
280+ Message : w .Message ,
281+ LastOccurrence : protobuf .ToTimestamp (w .LastOccurrence ),
282+ })
283+ }
284+ return pb
285+ }
0 commit comments