fetch current container runtime config through the command line

Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>

add default runtime binary path to runtimes field of toolkit config toml

Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>

[no-relnote] Get low-level runtimes consistently

We ensure that we use the same low-level runtimes regardless
of the runtime engine being configured. This ensures consistent
behaviour.

Signed-off-by: Evan Lezar <elezar@nvidia.com>

Co-authored-by: Evan Lezar <elezar@nvidia.com>

address review comment

Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>
This commit is contained in:
Tariq Ibrahim
2024-08-08 15:40:00 -07:00
parent 4604e3b6c8
commit f477dc0df1
21 changed files with 596 additions and 48 deletions

View File

@@ -35,6 +35,22 @@ type Config struct {
var _ engine.Interface = (*Config)(nil)
type containerdCfgRuntime struct {
tree *toml.Tree
}
var _ engine.RuntimeConfig = (*containerdCfgRuntime)(nil)
// GetBinaryPath retrieves the path to the actual low-level runtime binary invoked by the runtime handler
func (c *containerdCfgRuntime) GetBinaryPath() string {
if c == nil || c.tree == nil {
return ""
}
binPath, _ := c.tree.GetPath([]string{"options", "BinaryName"}).(string)
return binPath
}
// New creates a containerd config with the specified options
func New(opts ...Option) (engine.Interface, error) {
b := &builder{
@@ -98,3 +114,27 @@ func (c *Config) parseVersion(useLegacyConfig bool) (int, error) {
return -1, fmt.Errorf("unsupported type for version field: %v", v)
}
}
func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
if c == nil || c.Tree == nil {
return nil, fmt.Errorf("config is nil")
}
runtimeData := c.GetSubtreeByPath([]string{"plugins", "io.containerd.grpc.v1.cri", "containerd", "runtimes", name})
return &containerdCfgRuntime{
tree: runtimeData,
}, nil
}
// CommandLineSource returns the CLI-based containerd config loader
func CommandLineSource(hostRoot string) toml.Loader {
commandLine := chrootIfRequired(hostRoot, "containerd", "config", "dump")
return toml.FromCommandLine(commandLine[0], commandLine[1:]...)
}
func chrootIfRequired(hostRoot string, commandLine ...string) []string {
if hostRoot == "" || hostRoot == "/" {
return commandLine
}
return append([]string{"chroot", hostRoot}, commandLine...)
}