Skip to content

Commit 90b42da

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]> (cherry picked from commit 9aab446) Signed-off-by: Samuel Karp <[email protected]>
1 parent 0b6766b commit 90b42da

1 file changed

Lines changed: 56 additions & 13 deletions

File tree

services/introspection/local.go

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,68 @@ package introspection
1818

1919
import (
2020
context "context"
21+
"errors"
2122
"os"
2223
"path/filepath"
2324
"sync"
2425

26+
"github.com/gogo/googleapis/google/rpc"
27+
ptypes "github.com/gogo/protobuf/types"
28+
"github.com/google/uuid"
29+
"google.golang.org/grpc"
30+
"google.golang.org/grpc/status"
31+
2532
api "github.com/containerd/containerd/api/services/introspection/v1"
2633
"github.com/containerd/containerd/api/types"
2734
"github.com/containerd/containerd/errdefs"
2835
"github.com/containerd/containerd/filters"
2936
"github.com/containerd/containerd/plugin"
3037
"github.com/containerd/containerd/services"
31-
"github.com/gogo/googleapis/google/rpc"
32-
ptypes "github.com/gogo/protobuf/types"
33-
"github.com/google/uuid"
34-
"google.golang.org/grpc"
35-
"google.golang.org/grpc/status"
38+
"github.com/containerd/containerd/services/warning"
3639
)
3740

3841
func init() {
3942
plugin.Register(&plugin.Registration{
4043
Type: plugin.ServicePlugin,
4144
ID: services.IntrospectionService,
42-
Requires: []plugin.Type{},
45+
Requires: []plugin.Type{plugin.WarningPlugin},
4346
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
47+
sps, err := ic.GetByType(plugin.WarningPlugin)
48+
if err != nil {
49+
return nil, err
50+
}
51+
p, ok := sps[plugin.DeprecationsPlugin]
52+
if !ok {
53+
return nil, errors.New("warning service not found")
54+
}
55+
56+
i, err := p.Instance()
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
warningClient, ok := i.(warning.Service)
62+
if !ok {
63+
return nil, errors.New("could not create a local client for warning service")
64+
}
65+
4466
// this service fetches all plugins through the plugin set of the plugin context
4567
return &Local{
46-
plugins: ic.Plugins(),
47-
root: ic.Root,
68+
plugins: ic.Plugins(),
69+
root: ic.Root,
70+
warningClient: warningClient,
4871
}, nil
4972
},
5073
})
5174
}
5275

5376
// Local is a local implementation of the introspection service
5477
type Local struct {
55-
mu sync.Mutex
56-
root string
57-
plugins *plugin.Set
58-
pluginCache []api.Plugin
78+
mu sync.Mutex
79+
root string
80+
plugins *plugin.Set
81+
pluginCache []api.Plugin
82+
warningClient warning.Service
5983
}
6084

6185
var _ = (api.IntrospectionClient)(&Local{})
@@ -106,7 +130,8 @@ func (l *Local) Server(ctx context.Context, _ *ptypes.Empty, _ ...grpc.CallOptio
106130
return nil, errdefs.ToGRPC(err)
107131
}
108132
return &api.ServerResponse{
109-
UUID: u,
133+
UUID: u,
134+
Deprecations: l.getWarnings(ctx),
110135
}, nil
111136
}
112137

@@ -148,6 +173,10 @@ func (l *Local) uuidPath() string {
148173
return filepath.Join(l.root, "uuid")
149174
}
150175

176+
func (l *Local) getWarnings(ctx context.Context) []*api.DeprecationWarning {
177+
return warningsPB(ctx, l.warningClient.Warnings())
178+
}
179+
151180
func adaptPlugin(o interface{}) filters.Adaptor {
152181
obj := o.(api.Plugin)
153182
return filters.AdapterFunc(func(fieldpath []string) (string, bool) {
@@ -229,3 +258,17 @@ func pluginsToPB(plugins []*plugin.Plugin) []api.Plugin {
229258

230259
return pluginsPB
231260
}
261+
262+
func warningsPB(ctx context.Context, warnings []warning.Warning) []*api.DeprecationWarning {
263+
var pb []*api.DeprecationWarning
264+
265+
for _, w := range warnings {
266+
ts, _ := ptypes.TimestampProto(w.LastOccurrence)
267+
pb = append(pb, &api.DeprecationWarning{
268+
ID: string(w.ID),
269+
Message: w.Message,
270+
LastOccurrence: ts,
271+
})
272+
}
273+
return pb
274+
}

0 commit comments

Comments
 (0)