Skip to content

Commit 9aab446

Browse files
committed
introspection: add support for deprecations
Deprecation warnings are retrieved from the warning service and returned via the Server RPC. Signed-off-by: Samuel Karp <[email protected]>
1 parent 57c897f commit 9aab446

1 file changed

Lines changed: 58 additions & 15 deletions

File tree

services/introspection/local.go

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,73 @@ package introspection
1818

1919
import (
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"
3138
"github.com/containerd/containerd/plugin/registry"
3239
"github.com/containerd/containerd/plugins"
40+
"github.com/containerd/containerd/protobuf"
3341
ptypes "github.com/containerd/containerd/protobuf/types"
3442
"github.com/containerd/containerd/services"
35-
"github.com/google/uuid"
36-
"google.golang.org/genproto/googleapis/rpc/code"
37-
rpc "google.golang.org/genproto/googleapis/rpc/status"
38-
"google.golang.org/grpc"
39-
"google.golang.org/grpc/status"
43+
"github.com/containerd/containerd/services/warning"
4044
)
4145

4246
func init() {
4347
registry.Register(&plugin.Registration{
4448
Type: plugins.ServicePlugin,
4549
ID: services.IntrospectionService,
46-
Requires: []plugin.Type{},
50+
Requires: []plugin.Type{plugins.WarningPlugin},
4751
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
52+
sps, err := ic.GetByType(plugins.WarningPlugin)
53+
if err != nil {
54+
return nil, err
55+
}
56+
p, ok := sps[plugins.DeprecationsPlugin]
57+
if !ok {
58+
return nil, errors.New("warning service not found")
59+
}
60+
61+
i, err := p.Instance()
62+
if err != nil {
63+
return nil, err
64+
}
65+
66+
warningClient, ok := i.(warning.Service)
67+
if !ok {
68+
return nil, errors.New("could not create a local client for warning service")
69+
}
70+
4871
// this service fetches all plugins through the plugin set of the plugin context
4972
return &Local{
50-
plugins: ic.Plugins(),
51-
root: ic.Properties[plugins.PropertyRootDir],
73+
plugins: ic.Plugins(),
74+
root: ic.Properties[plugins.PropertyRootDir],
75+
warningClient: warningClient,
5276
}, nil
5377
},
5478
})
5579
}
5680

5781
// Local is a local implementation of the introspection service
5882
type Local struct {
59-
mu sync.Mutex
60-
root string
61-
plugins *plugin.Set
62-
pluginCache []*api.Plugin
83+
mu sync.Mutex
84+
root string
85+
plugins *plugin.Set
86+
pluginCache []*api.Plugin
87+
warningClient warning.Service
6388
}
6489

6590
var _ = (api.IntrospectionClient)(&Local{})
@@ -117,9 +142,10 @@ func (l *Local) Server(ctx context.Context, _ *ptypes.Empty, _ ...grpc.CallOptio
117142
}
118143
}
119144
return &api.ServerResponse{
120-
UUID: u,
121-
Pid: uint64(pid),
122-
Pidns: pidns,
145+
UUID: u,
146+
Pid: uint64(pid),
147+
Pidns: pidns,
148+
Deprecations: l.getWarnings(ctx),
123149
}, nil
124150
}
125151

@@ -161,6 +187,10 @@ func (l *Local) uuidPath() string {
161187
return filepath.Join(l.root, "uuid")
162188
}
163189

190+
func (l *Local) getWarnings(ctx context.Context) []*api.DeprecationWarning {
191+
return warningsPB(ctx, l.warningClient.Warnings())
192+
}
193+
164194
func adaptPlugin(o interface{}) filters.Adaptor {
165195
obj := o.(*api.Plugin)
166196
return filters.AdapterFunc(func(fieldpath []string) (string, bool) {
@@ -233,3 +263,16 @@ func pluginsToPB(plugins []*plugin.Plugin) []*api.Plugin {
233263

234264
return pluginsPB
235265
}
266+
267+
func warningsPB(ctx context.Context, warnings []warning.Warning) []*api.DeprecationWarning {
268+
var pb []*api.DeprecationWarning
269+
270+
for _, w := range warnings {
271+
pb = append(pb, &api.DeprecationWarning{
272+
ID: string(w.ID),
273+
Message: w.Message,
274+
LastOccurrence: protobuf.ToTimestamp(w.LastOccurrence),
275+
})
276+
}
277+
return pb
278+
}

0 commit comments

Comments
 (0)