mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-15 13:58:55 +00:00
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 <alex.lyn@antgroup.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user