From 0b1f80655775a68c4281d312ca7caec4d42182a7 Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 15 Sep 2017 03:30:09 +0000 Subject: [PATCH] Fix nil dereference if storage id is nil --- pkg/kubelet/stats/cri_stats_provider.go | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg/kubelet/stats/cri_stats_provider.go b/pkg/kubelet/stats/cri_stats_provider.go index b340416eb21..02795b565b2 100644 --- a/pkg/kubelet/stats/cri_stats_provider.go +++ b/pkg/kubelet/stats/cri_stats_provider.go @@ -259,20 +259,22 @@ func (p *criStatsProvider) makeContainerStats( } } storageID := stats.WritableLayer.StorageId - imageFsInfo, found := uuidToFsInfo[*storageID] - if !found { - imageFsInfo = p.getFsInfo(storageID) - uuidToFsInfo[*storageID] = imageFsInfo - } - if imageFsInfo != nil { - // The image filesystem UUID is unknown to the local node or there's an - // error on retrieving the stats. In these cases, we omit those stats - // and return the best-effort partial result. See - // https://github.com/kubernetes/heapster/issues/1793. - result.Rootfs.AvailableBytes = &imageFsInfo.Available - result.Rootfs.CapacityBytes = &imageFsInfo.Capacity - result.Rootfs.InodesFree = imageFsInfo.InodesFree - result.Rootfs.Inodes = imageFsInfo.Inodes + if storageID != nil { + imageFsInfo, found := uuidToFsInfo[*storageID] + if !found { + imageFsInfo = p.getFsInfo(storageID) + uuidToFsInfo[*storageID] = imageFsInfo + } + if imageFsInfo != nil { + // The image filesystem UUID is unknown to the local node or there's an + // error on retrieving the stats. In these cases, we omit those stats + // and return the best-effort partial result. See + // https://github.com/kubernetes/heapster/issues/1793. + result.Rootfs.AvailableBytes = &imageFsInfo.Available + result.Rootfs.CapacityBytes = &imageFsInfo.Capacity + result.Rootfs.InodesFree = imageFsInfo.InodesFree + result.Rootfs.Inodes = imageFsInfo.Inodes + } } return result