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,20 @@ type Config map[string]interface{}
var _ engine.Interface = (*Config)(nil)
type dockerRuntime map[string]interface{}
var _ engine.RuntimeConfig = (*dockerRuntime)(nil)
// GetBinaryPath retrieves the path to the actual low-level runtime binary invoked by the runtime handler
func (d dockerRuntime) GetBinaryPath() string {
if d == nil {
return ""
}
path, _ := d["path"].(string)
return path
}
// New creates a docker config with the specified options
func New(opts ...Option) (engine.Interface, error) {
b := &builder{}
@@ -132,3 +146,22 @@ func (c Config) Save(path string) (int64, error) {
n, err := config.Raw(path).Write(output)
return int64(n), err
}
// GetRuntimeConfig returns the runtime info of the runtime passed as input
func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
if c == nil {
return nil, fmt.Errorf("config is nil")
}
cfg := *c
var runtimes map[string]interface{}
if _, ok := cfg["runtimes"]; ok {
runtimes = cfg["runtimes"].(map[string]interface{})
if r, ok := runtimes[name]; ok {
dr := dockerRuntime(r.(map[string]interface{}))
return &dr, nil
}
}
return &dockerRuntime{}, nil
}

View File

@@ -213,3 +213,37 @@ func TestUpdateConfigRuntimes(t *testing.T) {
}
}
func TestGetRuntimeConfig(t *testing.T) {
c := map[string]interface{}{
"runtimes": map[string]interface{}{
"nvidia": map[string]interface{}{
"path": "nvidia-container-runtime",
"args": []string{},
},
},
}
cfg := Config(c)
testCases := []struct {
description string
runtime string
expected string
}{
{
description: "existing runtime",
runtime: "nvidia",
expected: "nvidia-container-runtime",
},
{
description: "non-existent runtime",
runtime: "some-other-runtime",
expected: "",
},
}
for _, tc := range testCases {
rc, err := cfg.GetRuntimeConfig(tc.runtime)
require.NoError(t, err)
require.Equal(t, tc.expected, rc.GetBinaryPath())
}
}