Commit b9157b75 authored by Jing Xu's avatar Jing Xu

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.
parent a6d37f7e
......@@ -322,15 +322,26 @@ func (dsw *desiredStateOfWorld) GetVolumesToAttach() []VolumeToAttach {
volumesToAttach = append(volumesToAttach,
VolumeToAttach{
VolumeToAttach: operationexecutor.VolumeToAttach{
VolumeName: volumeName,
VolumeSpec: volumeObj.spec,
NodeName: nodeName}})
VolumeName: volumeName,
VolumeSpec: volumeObj.spec,
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()
......
......@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment