From 1684c1962cbc07cabaf6a4578a617d61588ad255 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Mon, 9 Sep 2024 20:02:57 +0800 Subject: [PATCH] runtime: Fix runtime/cdi panic with assignment to entry in nil map It will panic when users do GPU vfio passthrough with cdi in runtime. The root cause is that CustomSpec.Annotations is nil when new element added. To address this issue, initialization is introduced when it's nil. Fixes #10266 Signed-off-by: Alex Lyn --- src/runtime/virtcontainers/container.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go index 0a5e702b891b..cd599ea06960 100644 --- a/src/runtime/virtcontainers/container.go +++ b/src/runtime/virtcontainers/container.go @@ -1010,6 +1010,9 @@ func (c *Container) siblingAnnotation(devPath string, siblings []DeviceRelation) vfioNum := filepath.Base(devPath) annoKey := fmt.Sprintf("cdi.k8s.io/vfio%s", vfioNum) annoValue := fmt.Sprintf("nvidia.com/gpu=%d", sibling.Index) + if c.config.CustomSpec.Annotations == nil { + c.config.CustomSpec.Annotations = make(map[string]string) + } c.config.CustomSpec.Annotations[annoKey] = annoValue c.Logger().Infof("annotated container with %s: %s", annoKey, annoValue) }