pkg/nri: update NRI configuration.
Update NRI plugin configuration to match that of NRI. Remove option for the eliminated NRI configuration file. Add option to disable connections from externally launched plugins. Add options to override default plugin registration and request timeouts. Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
package nri
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
nri "github.com/containerd/nri/pkg/adaptation"
|
||||
)
|
||||
|
||||
@@ -24,35 +26,57 @@ import (
|
||||
type Config struct {
|
||||
// Disable this NRI plugin and containerd NRI functionality altogether.
|
||||
Disable bool `toml:"disable" json:"disable"`
|
||||
// ConfigPath is the path to the NRI configuration file to use.
|
||||
ConfigPath string `toml:"config_file" json:"configFile"`
|
||||
// SocketPath is the path to the NRI socket to create for NRI plugins to connect to.
|
||||
SocketPath string `toml:"socket_path" json:"socketPath"`
|
||||
// PluginPath is the path to search for NRI plugins to launch on startup.
|
||||
PluginPath string `toml:"plugin_path" json:"pluginPath"`
|
||||
// PluginConfigPath is the path to search for plugin-specific configuration.
|
||||
PluginConfigPath string `toml:"plugin_config_path" json:"pluginConfigPath"`
|
||||
// PluginRegistrationTimeout is the timeout for plugin registration.
|
||||
PluginRegistrationTimeout time.Duration `toml:"plugin_registration_timeout" json:"pluginRegistrationTimeout"`
|
||||
// PluginRequestTimeout is the timeout for a plugin to handle a request.
|
||||
PluginRequestTimeout time.Duration `toml:"plugin_request_timeout" json:"pluginRequestTimeout"`
|
||||
// DisableConnections disables connections from externally launched plugins.
|
||||
DisableConnections bool `toml:"disable_connections" json:"disableConnections"`
|
||||
}
|
||||
|
||||
// DefaultConfig returns the default configuration.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Disable: true,
|
||||
ConfigPath: nri.DefaultConfigPath,
|
||||
SocketPath: nri.DefaultSocketPath,
|
||||
PluginPath: nri.DefaultPluginPath,
|
||||
Disable: true,
|
||||
SocketPath: nri.DefaultSocketPath,
|
||||
PluginPath: nri.DefaultPluginPath,
|
||||
PluginConfigPath: nri.DefaultPluginConfigPath,
|
||||
|
||||
PluginRegistrationTimeout: nri.DefaultPluginRegistrationTimeout,
|
||||
PluginRequestTimeout: nri.DefaultPluginRequestTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// toOptions returns NRI options for this configuration.
|
||||
func (c *Config) toOptions() []nri.Option {
|
||||
opts := []nri.Option{}
|
||||
if c.ConfigPath != "" {
|
||||
opts = append(opts, nri.WithConfigPath(c.ConfigPath))
|
||||
}
|
||||
if c.SocketPath != "" {
|
||||
opts = append(opts, nri.WithSocketPath(c.SocketPath))
|
||||
}
|
||||
if c.PluginPath != "" {
|
||||
opts = append(opts, nri.WithPluginPath(c.PluginPath))
|
||||
}
|
||||
if c.PluginConfigPath != "" {
|
||||
opts = append(opts, nri.WithPluginConfigPath(c.PluginConfigPath))
|
||||
}
|
||||
if c.DisableConnections {
|
||||
opts = append(opts, nri.WithDisabledExternalConnections())
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
// ConfigureTimeouts sets timeout options for NRI.
|
||||
func (c *Config) ConfigureTimeouts() {
|
||||
if c.PluginRegistrationTimeout != 0 {
|
||||
nri.SetPluginRegistrationTimeout(c.PluginRegistrationTimeout)
|
||||
}
|
||||
if c.PluginRequestTimeout != 0 {
|
||||
nri.SetPluginRequestTimeout(c.PluginRequestTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,8 @@ func New(cfg *Config) (API, error) {
|
||||
err error
|
||||
)
|
||||
|
||||
cfg.ConfigureTimeouts()
|
||||
|
||||
l.nri, err = nri.New(name, version, syncFn, updateFn, opts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize NRI interface: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user