mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
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:
parent
a6d37f7ead
commit
b9157b7524
@ -322,15 +322,26 @@ func (dsw *desiredStateOfWorld) GetVolumesToAttach() []VolumeToAttach {
|
|||||||
volumesToAttach = append(volumesToAttach,
|
volumesToAttach = append(volumesToAttach,
|
||||||
VolumeToAttach{
|
VolumeToAttach{
|
||||||
VolumeToAttach: operationexecutor.VolumeToAttach{
|
VolumeToAttach: operationexecutor.VolumeToAttach{
|
||||||
VolumeName: volumeName,
|
VolumeName: volumeName,
|
||||||
VolumeSpec: volumeObj.spec,
|
VolumeSpec: volumeObj.spec,
|
||||||
NodeName: nodeName}})
|
NodeName: nodeName,
|
||||||
|
ScheduledPods: getPodsFromMap(volumeObj.scheduledPods),
|
||||||
|
}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return volumesToAttach
|
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 {
|
func (dsw *desiredStateOfWorld) GetPodToAdd() map[types.UniquePodName]PodToAdd {
|
||||||
dsw.RLock()
|
dsw.RLock()
|
||||||
defer dsw.RUnlock()
|
defer dsw.RUnlock()
|
||||||
|
@ -168,6 +168,12 @@ type VolumeToAttach struct {
|
|||||||
// NodeName is the identifier for the node that the volume should be
|
// NodeName is the identifier for the node that the volume should be
|
||||||
// attached to.
|
// attached to.
|
||||||
NodeName string
|
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
|
// VolumeToMount represents a volume that should be attached to this node and
|
||||||
@ -483,12 +489,15 @@ func (oe *operationExecutor) generateAttachVolumeFunc(
|
|||||||
|
|
||||||
if attachErr != nil {
|
if attachErr != nil {
|
||||||
// On failure, return error. Caller will log and retry.
|
// On failure, return error. Caller will log and retry.
|
||||||
return fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"AttachVolume.Attach failed for volume %q (spec.Name: %q) from node %q with: %v",
|
"Failed to attach volume %q on node %q with: %v",
|
||||||
volumeToAttach.VolumeName,
|
|
||||||
volumeToAttach.VolumeSpec.Name(),
|
volumeToAttach.VolumeSpec.Name(),
|
||||||
volumeToAttach.NodeName,
|
volumeToAttach.NodeName,
|
||||||
attachErr)
|
attachErr)
|
||||||
|
for _, pod := range volumeToAttach.ScheduledPods {
|
||||||
|
oe.recorder.Eventf(pod, api.EventTypeWarning, kevents.FailedMountVolume, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof(
|
glog.Infof(
|
||||||
|
Loading…
Reference in New Issue
Block a user