From f6f6282549af1365105fee325cce15f8a596d1da Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 7 Nov 2024 09:03:08 -0800 Subject: [PATCH] Fallback to file for runtime config 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 --- tools/container/runtime/containerd/containerd.go | 8 +++++++- tools/container/runtime/crio/crio.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/container/runtime/containerd/containerd.go b/tools/container/runtime/containerd/containerd.go index 6a5df5ad..14b0a5d3 100644 --- a/tools/container/runtime/containerd/containerd.go +++ b/tools/container/runtime/containerd/containerd.go @@ -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" ) @@ -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()...), diff --git a/tools/container/runtime/crio/crio.go b/tools/container/runtime/crio/crio.go index e3fa77f6..68b36f45 100644 --- a/tools/container/runtime/crio/crio.go +++ b/tools/container/runtime/crio/crio.go @@ -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" ) @@ -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)