Merge pull request #777 from elezar/add-config-fallback
Some checks are pending
CodeQL / Analyze Go code with CodeQL (push) Waiting to run
Golang / check (push) Waiting to run
Golang / Unit test (push) Waiting to run
Golang / Build (push) Waiting to run
image / packages (${{github.event_name == 'pull_request'}}, centos7-aarch64) (push) Waiting to run
image / packages (${{github.event_name == 'pull_request'}}, centos7-x86_64) (push) Waiting to run
image / packages (${{github.event_name == 'pull_request'}}, centos8-ppc64le) (push) Waiting to run
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-amd64) (push) Waiting to run
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-arm64) (push) Waiting to run
image / packages (${{github.event_name == 'pull_request'}}, ubuntu18.04-ppc64le) (push) Waiting to run
image / image (packaging, ${{github.event_name == 'pull_request'}}) (push) Blocked by required conditions
image / image (ubi8, ${{github.event_name == 'pull_request'}}) (push) Blocked by required conditions
image / image (ubuntu20.04, ${{github.event_name == 'pull_request'}}) (push) Blocked by required conditions

Fallback to file for runtime config
This commit is contained in:
Evan Lezar 2024-11-08 09:09:18 -08:00 committed by GitHub
commit b142091234
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 36 deletions

View File

@ -25,6 +25,7 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
"github.com/NVIDIA/nvidia-container-toolkit/tools/container" "github.com/NVIDIA/nvidia-container-toolkit/tools/container"
) )
@ -84,13 +85,7 @@ func Flags(opts *Options) []cli.Flag {
func Setup(c *cli.Context, o *container.Options, co *Options) error { func Setup(c *cli.Context, o *container.Options, co *Options) error {
log.Infof("Starting 'setup' for %v", c.App.Name) log.Infof("Starting 'setup' for %v", c.App.Name)
cfg, err := containerd.New( cfg, err := getRuntimeConfig(o, co)
containerd.WithPath(o.Config),
containerd.WithConfigSource(containerd.CommandLineSource(o.HostRootMount)),
containerd.WithRuntimeType(co.runtimeType),
containerd.WithUseLegacyConfig(co.useLegacyConfig),
containerd.WithContainerAnnotations(co.containerAnnotationsFromCDIPrefixes()...),
)
if err != nil { if err != nil {
return fmt.Errorf("unable to load config: %v", err) return fmt.Errorf("unable to load config: %v", err)
} }
@ -114,13 +109,7 @@ func Setup(c *cli.Context, o *container.Options, co *Options) error {
func Cleanup(c *cli.Context, o *container.Options, co *Options) error { func Cleanup(c *cli.Context, o *container.Options, co *Options) error {
log.Infof("Starting 'cleanup' for %v", c.App.Name) log.Infof("Starting 'cleanup' for %v", c.App.Name)
cfg, err := containerd.New( cfg, err := getRuntimeConfig(o, co)
containerd.WithPath(o.Config),
containerd.WithConfigSource(containerd.CommandLineSource(o.HostRootMount)),
containerd.WithRuntimeType(co.runtimeType),
containerd.WithUseLegacyConfig(co.useLegacyConfig),
containerd.WithContainerAnnotations(co.containerAnnotationsFromCDIPrefixes()...),
)
if err != nil { if err != nil {
return fmt.Errorf("unable to load config: %v", err) return fmt.Errorf("unable to load config: %v", err)
} }
@ -169,13 +158,24 @@ func (o *Options) runtimeConfigOverride() (map[string]interface{}, error) {
} }
func GetLowlevelRuntimePaths(o *container.Options, co *Options) ([]string, error) { func GetLowlevelRuntimePaths(o *container.Options, co *Options) ([]string, error) {
cfg, err := containerd.New( cfg, err := getRuntimeConfig(o, co)
containerd.WithConfigSource(containerd.CommandLineSource(o.HostRootMount)),
containerd.WithRuntimeType(co.runtimeType),
containerd.WithUseLegacyConfig(co.useLegacyConfig),
)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to load containerd config: %w", err) return nil, fmt.Errorf("unable to load containerd config: %w", err)
} }
return engine.GetBinaryPathsForRuntimes(cfg), nil return engine.GetBinaryPathsForRuntimes(cfg), nil
} }
func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, error) {
return containerd.New(
containerd.WithPath(o.Config),
containerd.WithConfigSource(
toml.LoadFirst(
containerd.CommandLineSource(o.HostRootMount),
toml.FromFile(o.Config),
),
),
containerd.WithRuntimeType(co.runtimeType),
containerd.WithUseLegacyConfig(co.useLegacyConfig),
containerd.WithContainerAnnotations(co.containerAnnotationsFromCDIPrefixes()...),
)
}

View File

@ -28,6 +28,7 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/ocihook" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/ocihook"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
"github.com/NVIDIA/nvidia-container-toolkit/tools/container" "github.com/NVIDIA/nvidia-container-toolkit/tools/container"
) )
@ -116,10 +117,7 @@ func setupHook(o *container.Options, co *Options) error {
func setupConfig(o *container.Options) error { func setupConfig(o *container.Options) error {
log.Infof("Updating config file") log.Infof("Updating config file")
cfg, err := crio.New( cfg, err := getRuntimeConfig(o)
crio.WithPath(o.Config),
crio.WithConfigSource(crio.CommandLineSource(o.HostRootMount)),
)
if err != nil { if err != nil {
return fmt.Errorf("unable to load config: %v", err) return fmt.Errorf("unable to load config: %v", err)
} }
@ -168,10 +166,7 @@ func cleanupHook(co *Options) error {
func cleanupConfig(o *container.Options) error { func cleanupConfig(o *container.Options) error {
log.Infof("Reverting config file modifications") log.Infof("Reverting config file modifications")
cfg, err := crio.New( cfg, err := getRuntimeConfig(o)
crio.WithPath(o.Config),
crio.WithConfigSource(crio.CommandLineSource(o.HostRootMount)),
)
if err != nil { if err != nil {
return fmt.Errorf("unable to load config: %v", err) return fmt.Errorf("unable to load config: %v", err)
} }
@ -195,11 +190,21 @@ func RestartCrio(o *container.Options) error {
} }
func GetLowlevelRuntimePaths(o *container.Options) ([]string, error) { func GetLowlevelRuntimePaths(o *container.Options) ([]string, error) {
cfg, err := crio.New( cfg, err := getRuntimeConfig(o)
crio.WithConfigSource(crio.CommandLineSource(o.HostRootMount)),
)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to load crio config: %w", err) return nil, fmt.Errorf("unable to load crio config: %w", err)
} }
return engine.GetBinaryPathsForRuntimes(cfg), nil return engine.GetBinaryPathsForRuntimes(cfg), nil
} }
func getRuntimeConfig(o *container.Options) (engine.Interface, error) {
return crio.New(
crio.WithPath(o.Config),
crio.WithConfigSource(
toml.LoadFirst(
crio.CommandLineSource(o.HostRootMount),
toml.FromFile(o.Config),
),
),
)
}

View File

@ -45,9 +45,7 @@ func Flags(opts *Options) []cli.Flag {
func Setup(c *cli.Context, o *container.Options) error { func Setup(c *cli.Context, o *container.Options) error {
log.Infof("Starting 'setup' for %v", c.App.Name) log.Infof("Starting 'setup' for %v", c.App.Name)
cfg, err := docker.New( cfg, err := getRuntimeConfig(o)
docker.WithPath(o.Config),
)
if err != nil { if err != nil {
return fmt.Errorf("unable to load config: %v", err) return fmt.Errorf("unable to load config: %v", err)
} }
@ -71,9 +69,7 @@ func Setup(c *cli.Context, o *container.Options) error {
func Cleanup(c *cli.Context, o *container.Options) error { func Cleanup(c *cli.Context, o *container.Options) error {
log.Infof("Starting 'cleanup' for %v", c.App.Name) log.Infof("Starting 'cleanup' for %v", c.App.Name)
cfg, err := docker.New( cfg, err := getRuntimeConfig(o)
docker.WithPath(o.Config),
)
if err != nil { if err != nil {
return fmt.Errorf("unable to load config: %v", err) return fmt.Errorf("unable to load config: %v", err)
} }
@ -107,3 +103,9 @@ func GetLowlevelRuntimePaths(o *container.Options) ([]string, error) {
} }
return engine.GetBinaryPathsForRuntimes(cfg), nil return engine.GetBinaryPathsForRuntimes(cfg), nil
} }
func getRuntimeConfig(o *container.Options) (engine.Interface, error) {
return docker.New(
docker.WithPath(o.Config),
)
}