Split streaming config from runtime config
Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
@@ -35,6 +35,7 @@ import (
|
||||
"github.com/containerd/containerd/v2/pkg/cri/server"
|
||||
nriservice "github.com/containerd/containerd/v2/pkg/nri"
|
||||
"github.com/containerd/containerd/v2/plugins"
|
||||
"github.com/containerd/containerd/v2/plugins/services/warning"
|
||||
"github.com/containerd/platforms"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
@@ -44,6 +45,7 @@ import (
|
||||
|
||||
// Register CRI service plugin
|
||||
func init() {
|
||||
defaultConfig := criconfig.DefaultServerConfig()
|
||||
registry.Register(&plugin.Registration{
|
||||
Type: plugins.GRPCPlugin,
|
||||
ID: "cri",
|
||||
@@ -56,10 +58,9 @@ func init() {
|
||||
plugins.LeasePlugin,
|
||||
plugins.SandboxStorePlugin,
|
||||
plugins.TransferPlugin,
|
||||
plugins.WarningPlugin,
|
||||
},
|
||||
Config: &criconfig.ServiceConfig{
|
||||
DisableTCPService: true,
|
||||
},
|
||||
Config: &defaultConfig,
|
||||
ConfigMigration: func(ctx context.Context, version int, pluginConfigs map[string]interface{}) error {
|
||||
if version >= srvconfig.CurrentConfigVersion {
|
||||
return nil
|
||||
@@ -87,7 +88,7 @@ func init() {
|
||||
|
||||
func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
ctx := ic.Context
|
||||
config := ic.Config.(*criconfig.ServiceConfig)
|
||||
config := ic.Config.(*criconfig.ServerConfig)
|
||||
|
||||
// Get runtime service.
|
||||
criRuntimePlugin, err := ic.GetByID(plugins.CRIServicePlugin, "runtime")
|
||||
@@ -101,6 +102,19 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
return nil, fmt.Errorf("unable to load CRI image service plugin dependency: %w", err)
|
||||
}
|
||||
|
||||
if warnings, err := criconfig.ValidateServerConfig(ic.Context, config); err != nil {
|
||||
return nil, fmt.Errorf("invalid cri image config: %w", err)
|
||||
} else if len(warnings) > 0 {
|
||||
ws, err := ic.GetSingle(plugins.WarningPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
warn := ws.(warning.Service)
|
||||
for _, w := range warnings {
|
||||
warn.Emit(ic.Context, w)
|
||||
}
|
||||
}
|
||||
|
||||
log.G(ctx).Info("Connect containerd service")
|
||||
client, err := containerd.New(
|
||||
"",
|
||||
@@ -119,16 +133,21 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) {
|
||||
string(criconfig.ModeShim): client.SandboxController(string(criconfig.ModeShim)),
|
||||
}
|
||||
|
||||
streamingConfig, err := config.StreamingConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get streaming config: %w", err)
|
||||
}
|
||||
|
||||
options := &server.CRIServiceOptions{
|
||||
RuntimeService: criRuntimePlugin.(server.RuntimeService),
|
||||
ImageService: criImagePlugin.(server.ImageService),
|
||||
StreamingConfig: streamingConfig,
|
||||
NRI: getNRIAPI(ic),
|
||||
Client: client,
|
||||
SandboxControllers: sbControllers,
|
||||
}
|
||||
is := criImagePlugin.(imageService).GRPCService()
|
||||
|
||||
// TODO: More options specifically for grpc service?
|
||||
s, rs, err := server.NewCRIService(options)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create CRI service: %w", err)
|
||||
|
||||
@@ -41,7 +41,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
config := criconfig.DefaultConfig()
|
||||
config := criconfig.DefaultRuntimeConfig()
|
||||
|
||||
// Base plugin that other CRI services depend on.
|
||||
registry.Register(&plugin.Registration{
|
||||
@@ -72,8 +72,8 @@ func initCRIRuntime(ic *plugin.InitContext) (interface{}, error) {
|
||||
ic.Meta.Platforms = []imagespec.Platform{platforms.DefaultSpec()}
|
||||
ic.Meta.Exports = map[string]string{"CRIVersion": constants.CRIVersion}
|
||||
ctx := ic.Context
|
||||
pluginConfig := ic.Config.(*criconfig.PluginConfig)
|
||||
if warnings, err := criconfig.ValidatePluginConfig(ctx, pluginConfig); err != nil {
|
||||
pluginConfig := ic.Config.(*criconfig.RuntimeConfig)
|
||||
if warnings, err := criconfig.ValidateRuntimeConfig(ctx, pluginConfig); err != nil {
|
||||
return nil, fmt.Errorf("invalid plugin config: %w", err)
|
||||
} else if len(warnings) > 0 {
|
||||
ws, err := ic.GetSingle(plugins.WarningPlugin)
|
||||
@@ -92,7 +92,7 @@ func initCRIRuntime(ic *plugin.InitContext) (interface{}, error) {
|
||||
containerdStateDir := filepath.Dir(ic.Properties[plugins.PropertyStateDir])
|
||||
stateDir := filepath.Join(containerdStateDir, "io.containerd.grpc.v1.cri")
|
||||
c := criconfig.Config{
|
||||
PluginConfig: *pluginConfig,
|
||||
RuntimeConfig: *pluginConfig,
|
||||
ContainerdRootDir: containerdRootDir,
|
||||
ContainerdEndpoint: ic.Properties[plugins.PropertyGRPCAddress],
|
||||
RootDir: rootDir,
|
||||
|
||||
Reference in New Issue
Block a user