From b2b04090da74a4a5f67c223ae01417f50304b282 Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Thu, 6 Oct 2016 10:15:05 -0700 Subject: [PATCH] Fix nil pointer issue when getting metrics from volume mounter Currently it is possible that the mounter object stored in Mounted Volume data structure in the actual state of kubelet volume manager is nil if this information is recovered from state sync process. This will cause nil pointer issue when calculating stats in volume_stat_calculator. A quick fix is to not return the volume if its mounter is nil. A more complete fix is to also recover mounter object when reconstructing the volume data structure which will be addressed in PR #33616 --- pkg/kubelet/kubelet_volumes.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/kubelet/kubelet_volumes.go b/pkg/kubelet/kubelet_volumes.go index 8ffc94e446c..28b98b5dcac 100644 --- a/pkg/kubelet/kubelet_volumes.go +++ b/pkg/kubelet/kubelet_volumes.go @@ -40,6 +40,12 @@ func (kl *Kubelet) ListVolumesForPod(podUID types.UID) (map[string]volume.Volume podVolumes := kl.volumeManager.GetMountedVolumesForPod( volumetypes.UniquePodName(podUID)) for outerVolumeSpecName, volume := range podVolumes { + // TODO: volume.Mounter could be nil if volume object is recovered + // from reconciler's sync state process. PR 33616 will fix this problem + // to create Mounter object when recovering volume state. + if volume.Mounter == nil { + continue + } volumesToReturn[outerVolumeSpecName] = volume.Mounter }