Post event message for volume attachment

This PR is to add event message when attaching volume fails to help
users to debug. For detach failure, may address in a different PR since
it requires more data structure change.
This commit is contained in:
Jing Xu 2016-08-31 16:14:56 -07:00
parent a6d37f7ead
commit b9157b7524
2 changed files with 26 additions and 6 deletions

View File

@ -324,13 +324,24 @@ func (dsw *desiredStateOfWorld) GetVolumesToAttach() []VolumeToAttach {
VolumeToAttach: operationexecutor.VolumeToAttach{
VolumeName: volumeName,
VolumeSpec: volumeObj.spec,
NodeName: nodeName}})
NodeName: nodeName,
ScheduledPods: getPodsFromMap(volumeObj.scheduledPods),
}})
}
}
return volumesToAttach
}
// Construct a list of api.Pod objects from the given pod map
func getPodsFromMap(podMap map[types.UniquePodName]pod) []*api.Pod {
pods := make([]*api.Pod, 0, len(podMap))
for _, pod := range podMap {
pods = append(pods, pod.podObj)
}
return pods
}
func (dsw *desiredStateOfWorld) GetPodToAdd() map[types.UniquePodName]PodToAdd {
dsw.RLock()
defer dsw.RUnlock()

View File

@ -168,6 +168,12 @@ type VolumeToAttach struct {
// NodeName is the identifier for the node that the volume should be
// attached to.
NodeName string
// scheduledPods is a map containing the set of pods that reference this
// volume and are scheduled to the underlying node. The key in the map is
// the name of the pod and the value is a pod object containing more
// information about the pod.
ScheduledPods []*api.Pod
}
// VolumeToMount represents a volume that should be attached to this node and
@ -483,12 +489,15 @@ func (oe *operationExecutor) generateAttachVolumeFunc(
if attachErr != nil {
// On failure, return error. Caller will log and retry.
return fmt.Errorf(
"AttachVolume.Attach failed for volume %q (spec.Name: %q) from node %q with: %v",
volumeToAttach.VolumeName,
err := fmt.Errorf(
"Failed to attach volume %q on node %q with: %v",
volumeToAttach.VolumeSpec.Name(),
volumeToAttach.NodeName,
attachErr)
for _, pod := range volumeToAttach.ScheduledPods {
oe.recorder.Eventf(pod, api.EventTypeWarning, kevents.FailedMountVolume, err.Error())
}
return err
}
glog.Infof(