pkg/cri: split out NRI API from pkg/cri/server.
Split out the criService-agnostic bits of nri-api* from pkg/cri/server to pkg/cri/nri to allow sharing a single implementation betwen the server and sbserver versions. Rework the interfaces to not require access to package internals. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
This commit is contained in:
@@ -24,8 +24,9 @@ import (
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/cri/nri"
|
||||
"github.com/containerd/containerd/pkg/cri/sbserver"
|
||||
"github.com/containerd/containerd/pkg/nri"
|
||||
nriservice "github.com/containerd/containerd/pkg/nri"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@@ -87,19 +88,12 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
}
|
||||
|
||||
var s server.CRIService
|
||||
var nrip nri.API
|
||||
if os.Getenv("ENABLE_CRI_SANDBOXES") != "" {
|
||||
log.G(ctx).Info("using experimental CRI Sandbox server - unset ENABLE_CRI_SANDBOXES to disable")
|
||||
s, err = sbserver.NewCRIService(c, client)
|
||||
} else {
|
||||
log.G(ctx).Info("using legacy CRI server")
|
||||
|
||||
nrip, err = getNRIPlugin(ic)
|
||||
if err != nil {
|
||||
log.G(ctx).Info("NRI service not found, disabling NRI support")
|
||||
}
|
||||
|
||||
s, err = server.NewCRIService(c, client, nrip)
|
||||
s, err = server.NewCRIService(c, client, getNRIAPI(ic))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create CRI service: %w", err)
|
||||
@@ -112,13 +106,6 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
// TODO(random-liu): Whether and how we can stop containerd.
|
||||
}()
|
||||
|
||||
if nrip != nil {
|
||||
log.G(ctx).Info("using experimental NRI integration - disable nri plugin to prevent this")
|
||||
if err = nrip.Start(); err != nil {
|
||||
log.G(ctx).WithError(err).Fatal("Failed to start NRI service")
|
||||
}
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -146,23 +133,29 @@ func setGLogLevel() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get the NRI plugin and verify its type.
|
||||
func getNRIPlugin(ic *plugin.InitContext) (nri.API, error) {
|
||||
// Get the NRI plugin, and set up our NRI API for it.
|
||||
func getNRIAPI(ic *plugin.InitContext) *nri.API {
|
||||
const (
|
||||
pluginType = plugin.NRIApiPlugin
|
||||
pluginName = "nri"
|
||||
)
|
||||
|
||||
ctx := ic.Context
|
||||
|
||||
p, err := ic.GetByID(pluginType, pluginName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
log.G(ctx).Info("NRI service not found, NRI support disabled")
|
||||
return nil
|
||||
}
|
||||
|
||||
api, ok := p.(nri.API)
|
||||
api, ok := p.(nriservice.API)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("NRI plugin (%s, %q) has incompatible type %T",
|
||||
log.G(ctx).Infof("NRI plugin (%s, %q) has incorrect type %T, NRI support disabled",
|
||||
pluginType, pluginName, api)
|
||||
return nil
|
||||
}
|
||||
|
||||
return api, nil
|
||||
log.G(ctx).Info("using experimental NRI integration - disable nri plugin to prevent this")
|
||||
|
||||
return nri.NewAPI(api)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user