Skip to content

Commit

Permalink
Fallback to file for runtime config
Browse files Browse the repository at this point in the history
This change ensures that we fall back to the previous behaviour of
reading the existing config from the specified config file if extracting
the current config from the command line fails. This fixes use cases where
the containerd / crio executables are not available.

Signed-off-by: Evan Lezar <[email protected]>
  • Loading branch information
elezar committed Nov 7, 2024
1 parent 8328180 commit f6f6282
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tools/container/runtime/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"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/toml"
"github.com/NVIDIA/nvidia-container-toolkit/tools/container"
)

Expand Down Expand Up @@ -116,7 +117,12 @@ func Cleanup(c *cli.Context, o *container.Options, co *Options) error {

cfg, err := containerd.New(
containerd.WithPath(o.Config),
containerd.WithConfigSource(containerd.CommandLineSource(o.HostRootMount)),
containerd.WithConfigSource(
toml.LoadFirst(
containerd.CommandLineSource(o.HostRootMount),
toml.FromFile(o.Config),
),
),
containerd.WithRuntimeType(co.runtimeType),
containerd.WithUseLegacyConfig(co.useLegacyConfig),
containerd.WithContainerAnnotations(co.containerAnnotationsFromCDIPrefixes()...),
Expand Down
8 changes: 7 additions & 1 deletion tools/container/runtime/crio/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"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/ocihook"
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/toml"
"github.com/NVIDIA/nvidia-container-toolkit/tools/container"
)

Expand Down Expand Up @@ -170,7 +171,12 @@ func cleanupConfig(o *container.Options) error {

cfg, err := crio.New(
crio.WithPath(o.Config),
crio.WithConfigSource(crio.CommandLineSource(o.HostRootMount)),
crio.WithConfigSource(
toml.LoadFirst(
crio.CommandLineSource(o.HostRootMount),
toml.FromFile(o.Config),
),
),
)
if err != nil {
return fmt.Errorf("unable to load config: %v", err)
Expand Down

0 comments on commit f6f6282

Please sign in to comment.