From 0b1f80655775a68c4281d312ca7caec4d42182a7 Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 15 Sep 2017 03:30:09 +0000 Subject: [PATCH 1/2] 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 b340416eb2..02795b565b 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 From aee1e58d581588011caa5f0f0697cb1834bb4cb8 Mon Sep 17 00:00:00 2001 From: David Porter Date: Fri, 15 Sep 2017 21:30:00 +0000 Subject: [PATCH 2/2] Handle nil WritableLayer --- pkg/kubelet/stats/cri_stats_provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubelet/stats/cri_stats_provider.go b/pkg/kubelet/stats/cri_stats_provider.go index 02795b565b..fb65b6dede 100644 --- a/pkg/kubelet/stats/cri_stats_provider.go +++ b/pkg/kubelet/stats/cri_stats_provider.go @@ -258,7 +258,7 @@ func (p *criStatsProvider) makeContainerStats( result.Rootfs.InodesUsed = &stats.WritableLayer.InodesUsed.Value } } - storageID := stats.WritableLayer.StorageId + storageID := stats.GetWritableLayer().GetStorageId() if storageID != nil { imageFsInfo, found := uuidToFsInfo[*storageID] if !found {