introspection: add support for deprecations
Deprecation warnings are retrieved from the warning service and returned via the Server RPC. Signed-off-by: Samuel Karp <samuelkarp@google.com>
This commit is contained in:
parent
57c897f10d
commit
9aab446733
@ -18,11 +18,18 @@ package introspection
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"google.golang.org/genproto/googleapis/rpc/code"
|
||||||
|
rpc "google.golang.org/genproto/googleapis/rpc/status"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
api "github.com/containerd/containerd/api/services/introspection/v1"
|
api "github.com/containerd/containerd/api/services/introspection/v1"
|
||||||
"github.com/containerd/containerd/api/types"
|
"github.com/containerd/containerd/api/types"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
@ -30,25 +37,42 @@ import (
|
|||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/plugin/registry"
|
"github.com/containerd/containerd/plugin/registry"
|
||||||
"github.com/containerd/containerd/plugins"
|
"github.com/containerd/containerd/plugins"
|
||||||
|
"github.com/containerd/containerd/protobuf"
|
||||||
ptypes "github.com/containerd/containerd/protobuf/types"
|
ptypes "github.com/containerd/containerd/protobuf/types"
|
||||||
"github.com/containerd/containerd/services"
|
"github.com/containerd/containerd/services"
|
||||||
"github.com/google/uuid"
|
"github.com/containerd/containerd/services/warning"
|
||||||
"google.golang.org/genproto/googleapis/rpc/code"
|
|
||||||
rpc "google.golang.org/genproto/googleapis/rpc/status"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Register(&plugin.Registration{
|
registry.Register(&plugin.Registration{
|
||||||
Type: plugins.ServicePlugin,
|
Type: plugins.ServicePlugin,
|
||||||
ID: services.IntrospectionService,
|
ID: services.IntrospectionService,
|
||||||
Requires: []plugin.Type{},
|
Requires: []plugin.Type{plugins.WarningPlugin},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
|
sps, err := ic.GetByType(plugins.WarningPlugin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
p, ok := sps[plugins.DeprecationsPlugin]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("warning service not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
i, err := p.Instance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
warningClient, ok := i.(warning.Service)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("could not create a local client for warning service")
|
||||||
|
}
|
||||||
|
|
||||||
// this service fetches all plugins through the plugin set of the plugin context
|
// this service fetches all plugins through the plugin set of the plugin context
|
||||||
return &Local{
|
return &Local{
|
||||||
plugins: ic.Plugins(),
|
plugins: ic.Plugins(),
|
||||||
root: ic.Properties[plugins.PropertyRootDir],
|
root: ic.Properties[plugins.PropertyRootDir],
|
||||||
|
warningClient: warningClient,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -56,10 +80,11 @@ func init() {
|
|||||||
|
|
||||||
// Local is a local implementation of the introspection service
|
// Local is a local implementation of the introspection service
|
||||||
type Local struct {
|
type Local struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
root string
|
root string
|
||||||
plugins *plugin.Set
|
plugins *plugin.Set
|
||||||
pluginCache []*api.Plugin
|
pluginCache []*api.Plugin
|
||||||
|
warningClient warning.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = (api.IntrospectionClient)(&Local{})
|
var _ = (api.IntrospectionClient)(&Local{})
|
||||||
@ -117,9 +142,10 @@ func (l *Local) Server(ctx context.Context, _ *ptypes.Empty, _ ...grpc.CallOptio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &api.ServerResponse{
|
return &api.ServerResponse{
|
||||||
UUID: u,
|
UUID: u,
|
||||||
Pid: uint64(pid),
|
Pid: uint64(pid),
|
||||||
Pidns: pidns,
|
Pidns: pidns,
|
||||||
|
Deprecations: l.getWarnings(ctx),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +187,10 @@ func (l *Local) uuidPath() string {
|
|||||||
return filepath.Join(l.root, "uuid")
|
return filepath.Join(l.root, "uuid")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Local) getWarnings(ctx context.Context) []*api.DeprecationWarning {
|
||||||
|
return warningsPB(ctx, l.warningClient.Warnings())
|
||||||
|
}
|
||||||
|
|
||||||
func adaptPlugin(o interface{}) filters.Adaptor {
|
func adaptPlugin(o interface{}) filters.Adaptor {
|
||||||
obj := o.(*api.Plugin)
|
obj := o.(*api.Plugin)
|
||||||
return filters.AdapterFunc(func(fieldpath []string) (string, bool) {
|
return filters.AdapterFunc(func(fieldpath []string) (string, bool) {
|
||||||
@ -233,3 +263,16 @@ func pluginsToPB(plugins []*plugin.Plugin) []*api.Plugin {
|
|||||||
|
|
||||||
return pluginsPB
|
return pluginsPB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func warningsPB(ctx context.Context, warnings []warning.Warning) []*api.DeprecationWarning {
|
||||||
|
var pb []*api.DeprecationWarning
|
||||||
|
|
||||||
|
for _, w := range warnings {
|
||||||
|
pb = append(pb, &api.DeprecationWarning{
|
||||||
|
ID: string(w.ID),
|
||||||
|
Message: w.Message,
|
||||||
|
LastOccurrence: protobuf.ToTimestamp(w.LastOccurrence),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return pb
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user