Fixed kubelet error message to be more descriptive. Added Attach success event for help in debugging.

This commit is contained in:
David Zhu 2017-12-15 15:36:59 -08:00
parent 68c857e207
commit fffd152e0d
3 changed files with 25 additions and 2 deletions

View File

@ -59,6 +59,7 @@ const (
FailedUnmapDevice = "FailedUnmapDevice" FailedUnmapDevice = "FailedUnmapDevice"
WarnAlreadyMountedVolume = "AlreadyMountedVolume" WarnAlreadyMountedVolume = "AlreadyMountedVolume"
SuccessfulDetachVolume = "SuccessfulDetachVolume" SuccessfulDetachVolume = "SuccessfulDetachVolume"
SuccessfulAttachVolume = "SuccessfulAttachVolume"
SuccessfulMountVolume = "SuccessfulMountVolume" SuccessfulMountVolume = "SuccessfulMountVolume"
SuccessfulUnMountVolume = "SuccessfulUnMountVolume" SuccessfulUnMountVolume = "SuccessfulUnMountVolume"
HostPortConflict = "HostPortConflict" HostPortConflict = "HostPortConflict"

View File

@ -357,21 +357,38 @@ func (vm *volumeManager) WaitForAttachAndMount(pod *v1.Pod) error {
// Timeout expired // Timeout expired
unmountedVolumes := unmountedVolumes :=
vm.getUnmountedVolumes(uniquePodName, expectedVolumes) vm.getUnmountedVolumes(uniquePodName, expectedVolumes)
// Also get unattached volumes for error message
unattachedVolumes :=
vm.getUnattachedVolumes(expectedVolumes)
if len(unmountedVolumes) == 0 { if len(unmountedVolumes) == 0 {
return nil return nil
} }
return fmt.Errorf( return fmt.Errorf(
"timeout expired waiting for volumes to attach/mount for pod %q/%q. list of unattached/unmounted volumes=%v", "timeout expired waiting for volumes to attach or mount for pod %q/%q. list of unmounted volumes=%v. list of unattached volumes=%v",
pod.Namespace, pod.Namespace,
pod.Name, pod.Name,
unmountedVolumes) unmountedVolumes,
unattachedVolumes)
} }
glog.V(3).Infof("All volumes are attached and mounted for pod %q", format.Pod(pod)) glog.V(3).Infof("All volumes are attached and mounted for pod %q", format.Pod(pod))
return nil return nil
} }
// getUnattachedVolumes returns a list of the volumes that are expected to be attached but
// are not currently attached to the node
func (vm *volumeManager) getUnattachedVolumes(expectedVolumes []string) []string {
unattachedVolumes := []string{}
for _, volume := range expectedVolumes {
if !vm.actualStateOfWorld.VolumeExists(v1.UniqueVolumeName(volume)) {
unattachedVolumes = append(unattachedVolumes, volume)
}
}
return unattachedVolumes
}
// verifyVolumesMountedFunc returns a method that returns true when all expected // verifyVolumesMountedFunc returns a method that returns true when all expected
// volumes are mounted. // volumes are mounted.
func (vm *volumeManager) verifyVolumesMountedFunc(podName types.UniquePodName, expectedVolumes []string) wait.ConditionFunc { func (vm *volumeManager) verifyVolumesMountedFunc(podName types.UniquePodName, expectedVolumes []string) wait.ConditionFunc {

View File

@ -305,6 +305,11 @@ func (og *operationGenerator) GenerateAttachVolumeFunc(
return detailedErr return detailedErr
} }
// Successful attach event is useful for user debugging
simpleMsg, _ := volumeToAttach.GenerateMsg("AttachVolume.Attach succeeded", "")
for _, pod := range volumeToAttach.ScheduledPods {
og.recorder.Eventf(pod, v1.EventTypeNormal, kevents.SuccessfulAttachVolume, simpleMsg)
}
glog.Infof(volumeToAttach.GenerateMsgDetailed("AttachVolume.Attach succeeded", "")) glog.Infof(volumeToAttach.GenerateMsgDetailed("AttachVolume.Attach succeeded", ""))
// Update actual state of world // Update actual state of world