From 1f6833bd0dfecfc80286c1fffacfc3bb1e71983a Mon Sep 17 00:00:00 2001 From: Markus Rudy Date: Wed, 26 Feb 2025 08:36:15 +0100 Subject: [PATCH] runtime: add cause to CDI errors Adding devices by CDI annotation can fail for a variety of reasons. If that happens, it's helpful to know the root cause of the issue (CDI spec missing, malformatted, requested device not present, etc.). This commit adds the root cause of the CDI device addition to the errors reported back to the caller. Since this error is bubbled up all the way back to the shimv2 task.Create handler, it will be visible in Kubernetes logs and enable fixing the root cause. Signed-off-by: Markus Rudy --- src/runtime/pkg/containerd-shim-v2/create.go | 2 +- src/runtime/virtcontainers/sandbox.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/pkg/containerd-shim-v2/create.go b/src/runtime/pkg/containerd-shim-v2/create.go index dc7f5e03e3..c272c89d4e 100644 --- a/src/runtime/pkg/containerd-shim-v2/create.go +++ b/src/runtime/pkg/containerd-shim-v2/create.go @@ -123,7 +123,7 @@ func create(ctx context.Context, s *service, r *taskAPI.CreateTaskRequest) (*con if containerType == vc.SingleContainer { _, err = config.WithCDI(ociSpec.Annotations, []string{}, ociSpec) if err != nil { - return nil, fmt.Errorf("adding CDI devices failed") + return nil, fmt.Errorf("adding CDI devices failed: %w", err) } } diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 3711da7f5e..3c9b7f33e5 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -742,7 +742,7 @@ func (s *Sandbox) coldOrHotPlugVFIO(sandboxConfig *SandboxConfig) (bool, error) // _, err := config.WithCDI(cdiSpec.Annotations, []string{}, cdiSpec) if err != nil { - return coldPlugVFIO, fmt.Errorf("adding CDI devices failed") + return coldPlugVFIO, fmt.Errorf("adding CDI devices failed: %w", err) } for _, dev := range cdiSpec.Linux.Devices {