From b9157b7524f51635761f11b875800e15552fbb5a Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Wed, 31 Aug 2016 16:14:56 -0700 Subject: [PATCH] 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. --- .../cache/desired_state_of_world.go | 17 ++++++++++++++--- .../operationexecutor/operation_executor.go | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go b/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go index d53a4423680..de24611c74e 100644 --- a/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go +++ b/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go @@ -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() diff --git a/pkg/volume/util/operationexecutor/operation_executor.go b/pkg/volume/util/operationexecutor/operation_executor.go index 28ebd631300..bb57f99e79b 100644 --- a/pkg/volume/util/operationexecutor/operation_executor.go +++ b/pkg/volume/util/operationexecutor/operation_executor.go @@ -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(