|
17 | 17 | package configure
|
18 | 18 |
|
19 | 19 | import (
|
| 20 | + "encoding/json" |
20 | 21 | "fmt"
|
21 | 22 | "path/filepath"
|
22 | 23 |
|
@@ -66,6 +67,8 @@ type config struct {
|
66 | 67 | mode string
|
67 | 68 | hookFilePath string
|
68 | 69 |
|
| 70 | + runtimeConfigOverrideJSON string |
| 71 | + |
69 | 72 | nvidiaRuntime struct {
|
70 | 73 | name string
|
71 | 74 | path string
|
@@ -153,6 +156,13 @@ func (m command) build() *cli.Command {
|
153 | 156 | Usage: "Enable CDI in the configured runtime",
|
154 | 157 | Destination: &config.cdi.enabled,
|
155 | 158 | },
|
| 159 | + &cli.StringFlag{ |
| 160 | + Name: "runtime-config-override", |
| 161 | + Destination: &config.runtimeConfigOverrideJSON, |
| 162 | + Usage: "specify additional runtime options as a JSON string. The paths are relative to the runtime config.", |
| 163 | + Value: "{}", |
| 164 | + EnvVars: []string{"RUNTIME_CONFIG_OVERRIDE"}, |
| 165 | + }, |
156 | 166 | }
|
157 | 167 |
|
158 | 168 | return &configure
|
@@ -194,6 +204,11 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
|
194 | 204 | config.cdi.enabled = false
|
195 | 205 | }
|
196 | 206 |
|
| 207 | + if config.runtimeConfigOverrideJSON != "" && config.runtime != "containerd" { |
| 208 | + m.logger.Warningf("Ignoring runtime-config-override flag for %v", config.runtime) |
| 209 | + config.runtimeConfigOverrideJSON = "" |
| 210 | + } |
| 211 | + |
197 | 212 | return nil
|
198 | 213 | }
|
199 | 214 |
|
@@ -237,10 +252,16 @@ func (m command) configureConfigFile(c *cli.Context, config *config) error {
|
237 | 252 | return fmt.Errorf("unable to load config for runtime %v: %v", config.runtime, err)
|
238 | 253 | }
|
239 | 254 |
|
| 255 | + runtimeConfigOverride, err := config.runtimeConfigOverride() |
| 256 | + if err != nil { |
| 257 | + return fmt.Errorf("unable to parse config overrides: %w", err) |
| 258 | + } |
| 259 | + |
240 | 260 | err = cfg.AddRuntime(
|
241 | 261 | config.nvidiaRuntime.name,
|
242 | 262 | config.nvidiaRuntime.path,
|
243 | 263 | config.nvidiaRuntime.setAsDefault,
|
| 264 | + runtimeConfigOverride, |
244 | 265 | )
|
245 | 266 | if err != nil {
|
246 | 267 | return fmt.Errorf("unable to update config: %v", err)
|
@@ -293,6 +314,20 @@ func (c *config) getOuputConfigPath() string {
|
293 | 314 | return c.resolveConfigFilePath()
|
294 | 315 | }
|
295 | 316 |
|
| 317 | +// runtimeConfigOverride converts the specified runtimeConfigOverride JSON string to a map. |
| 318 | +func (o *config) runtimeConfigOverride() (map[string]interface{}, error) { |
| 319 | + if o.runtimeConfigOverrideJSON == "" { |
| 320 | + return nil, nil |
| 321 | + } |
| 322 | + |
| 323 | + runtimeOptions := make(map[string]interface{}) |
| 324 | + if err := json.Unmarshal([]byte(o.runtimeConfigOverrideJSON), &runtimeOptions); err != nil { |
| 325 | + return nil, fmt.Errorf("failed to read %v as JSON: %w", o.runtimeConfigOverrideJSON, err) |
| 326 | + } |
| 327 | + |
| 328 | + return runtimeOptions, nil |
| 329 | +} |
| 330 | + |
296 | 331 | // configureOCIHook creates and configures the OCI hook for the NVIDIA runtime
|
297 | 332 | func (m *command) configureOCIHook(c *cli.Context, config *config) error {
|
298 | 333 | err := ocihook.CreateHook(config.hookFilePath, config.nvidiaRuntime.hookPath)
|
|
0 commit comments