csi: fix panic in serializing nil allocs in volume API (#8735)

- fix panic in serializing nil allocs in volume API
- prevent potential panic in serializing plugin allocs
This commit is contained in:
Tim Gross 2020-08-25 10:13:05 -04:00 committed by GitHub
parent 95bae2e6ca
commit f9b6c8153c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -296,7 +296,9 @@ func structsCSIPluginToApi(plug *structs.CSIPlugin) *api.CSIPlugin {
}
for _, a := range plug.Allocations {
out.Allocations = append(out.Allocations, structsAllocListStubToApi(a))
if a != nil {
out.Allocations = append(out.Allocations, structsAllocListStubToApi(a))
}
}
return out
@ -341,11 +343,15 @@ func structsCSIVolumeToApi(vol *structs.CSIVolume) *api.CSIVolume {
}
for _, a := range vol.WriteAllocs {
out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub()))
if a != nil {
out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub()))
}
}
for _, a := range vol.ReadAllocs {
out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub()))
if a != nil {
out.Allocations = append(out.Allocations, structsAllocListStubToApi(a.Stub()))
}
}
return out