Merge pull request #52588 from bobbypage/cristatsprovider-fixes

Automatic merge from submit-queue (batch tested with PRs 52486, 52588, 52524). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>..

Fix nil pointer dereference in cri stats provider when there are no image file systems

**What this PR does / why we need it**:

This PR fixes a nil pointer dereference in CRI stats provider when there are no image filesystems. See https://github.com/kubernetes/kubernetes/pull/51152 for discussion.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
```

/cc yujuhong yguo0905
This commit is contained in:
Kubernetes Submit Queue 2017-09-16 06:34:23 -07:00 committed by GitHub
commit 02731cc767

View File

@ -258,21 +258,23 @@ func (p *criStatsProvider) makeContainerStats(
result.Rootfs.InodesUsed = &stats.WritableLayer.InodesUsed.Value result.Rootfs.InodesUsed = &stats.WritableLayer.InodesUsed.Value
} }
} }
storageID := stats.WritableLayer.StorageId storageID := stats.GetWritableLayer().GetStorageId()
imageFsInfo, found := uuidToFsInfo[*storageID] if storageID != nil {
if !found { imageFsInfo, found := uuidToFsInfo[*storageID]
imageFsInfo = p.getFsInfo(storageID) if !found {
uuidToFsInfo[*storageID] = imageFsInfo imageFsInfo = p.getFsInfo(storageID)
} uuidToFsInfo[*storageID] = imageFsInfo
if imageFsInfo != nil { }
// The image filesystem UUID is unknown to the local node or there's an if imageFsInfo != nil {
// error on retrieving the stats. In these cases, we omit those stats // The image filesystem UUID is unknown to the local node or there's an
// and return the best-effort partial result. See // error on retrieving the stats. In these cases, we omit those stats
// https://github.com/kubernetes/heapster/issues/1793. // and return the best-effort partial result. See
result.Rootfs.AvailableBytes = &imageFsInfo.Available // https://github.com/kubernetes/heapster/issues/1793.
result.Rootfs.CapacityBytes = &imageFsInfo.Capacity result.Rootfs.AvailableBytes = &imageFsInfo.Available
result.Rootfs.InodesFree = imageFsInfo.InodesFree result.Rootfs.CapacityBytes = &imageFsInfo.Capacity
result.Rootfs.Inodes = imageFsInfo.Inodes result.Rootfs.InodesFree = imageFsInfo.InodesFree
result.Rootfs.Inodes = imageFsInfo.Inodes
}
} }
return result return result