|
|
|
@@ -169,7 +169,7 @@ func (rc *reconciler) reconcile() {
|
|
|
|
|
// attach if kubelet is responsible for attaching volumes.
|
|
|
|
|
// If underlying PVC was resized while in-use then this function also handles volume
|
|
|
|
|
// resizing.
|
|
|
|
|
rc.mountAttachVolumes()
|
|
|
|
|
rc.mountOrAttachVolumes()
|
|
|
|
|
|
|
|
|
|
// Ensure devices that should be detached/unmounted are detached/unmounted.
|
|
|
|
|
rc.unmountDetachDevices()
|
|
|
|
@@ -193,17 +193,65 @@ func (rc *reconciler) unmountVolumes() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rc *reconciler) mountAttachVolumes() {
|
|
|
|
|
func (rc *reconciler) mountOrAttachVolumes() {
|
|
|
|
|
// Ensure volumes that should be attached/mounted are attached/mounted.
|
|
|
|
|
for _, volumeToMount := range rc.desiredStateOfWorld.GetVolumesToMount() {
|
|
|
|
|
volMounted, devicePath, err := rc.actualStateOfWorld.PodExistsInVolume(volumeToMount.PodName, volumeToMount.VolumeName)
|
|
|
|
|
volumeToMount.DevicePath = devicePath
|
|
|
|
|
if cache.IsVolumeNotAttachedError(err) {
|
|
|
|
|
rc.waitForVolumeAttach(volumeToMount)
|
|
|
|
|
} else if !volMounted || cache.IsRemountRequiredError(err) {
|
|
|
|
|
rc.mountAttachedVolumes(volumeToMount, err)
|
|
|
|
|
} else if cache.IsFSResizeRequiredError(err) {
|
|
|
|
|
rc.expandVolume(volumeToMount)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rc *reconciler) expandVolume(volumeToMount cache.VolumeToMount) {
|
|
|
|
|
klog.V(4).InfoS(volumeToMount.GenerateMsgDetailed("Starting operationExecutor.ExpandInUseVolume", ""), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
err := rc.operationExecutor.ExpandInUseVolume(volumeToMount.VolumeToMount, rc.actualStateOfWorld)
|
|
|
|
|
|
|
|
|
|
if err != nil && !isExpectedError(err) {
|
|
|
|
|
klog.ErrorS(err, volumeToMount.GenerateErrorDetailed("operationExecutor.ExpandInUseVolume failed", err).Error(), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
klog.V(4).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.ExpandInUseVolume started", ""), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rc *reconciler) mountAttachedVolumes(volumeToMount cache.VolumeToMount, podExistError error) {
|
|
|
|
|
// Volume is not mounted, or is already mounted, but requires remounting
|
|
|
|
|
remountingLogStr := ""
|
|
|
|
|
isRemount := cache.IsRemountRequiredError(podExistError)
|
|
|
|
|
if isRemount {
|
|
|
|
|
remountingLogStr = "Volume is already mounted to pod, but remount was requested."
|
|
|
|
|
}
|
|
|
|
|
klog.V(4).InfoS(volumeToMount.GenerateMsgDetailed("Starting operationExecutor.MountVolume", remountingLogStr), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
err := rc.operationExecutor.MountVolume(
|
|
|
|
|
rc.waitForAttachTimeout,
|
|
|
|
|
volumeToMount.VolumeToMount,
|
|
|
|
|
rc.actualStateOfWorld,
|
|
|
|
|
isRemount)
|
|
|
|
|
if err != nil && !isExpectedError(err) {
|
|
|
|
|
klog.ErrorS(err, volumeToMount.GenerateErrorDetailed(fmt.Sprintf("operationExecutor.MountVolume failed (controllerAttachDetachEnabled %v)", rc.controllerAttachDetachEnabled), err).Error(), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
if err == nil {
|
|
|
|
|
if remountingLogStr == "" {
|
|
|
|
|
klog.V(1).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.MountVolume started", remountingLogStr), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
} else {
|
|
|
|
|
klog.V(5).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.MountVolume started", remountingLogStr), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rc *reconciler) waitForVolumeAttach(volumeToMount cache.VolumeToMount) {
|
|
|
|
|
if rc.controllerAttachDetachEnabled || !volumeToMount.PluginIsAttachable {
|
|
|
|
|
//// lets not spin a goroutine and unnecessarily trigger exponential backoff if this happens
|
|
|
|
|
if volumeToMount.PluginIsAttachable && !volumeToMount.ReportedInUse {
|
|
|
|
|
klog.V(5).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.VerifyControllerAttachedVolume failed", " volume not marked in-use"), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
continue
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// Volume is not attached (or doesn't implement attacher), kubelet attach is disabled, wait
|
|
|
|
|
// for controller to finish attaching volume.
|
|
|
|
@@ -235,42 +283,6 @@ func (rc *reconciler) mountAttachVolumes() {
|
|
|
|
|
klog.InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.AttachVolume started", ""), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if !volMounted || cache.IsRemountRequiredError(err) {
|
|
|
|
|
// Volume is not mounted, or is already mounted, but requires remounting
|
|
|
|
|
remountingLogStr := ""
|
|
|
|
|
isRemount := cache.IsRemountRequiredError(err)
|
|
|
|
|
if isRemount {
|
|
|
|
|
remountingLogStr = "Volume is already mounted to pod, but remount was requested."
|
|
|
|
|
}
|
|
|
|
|
klog.V(4).InfoS(volumeToMount.GenerateMsgDetailed("Starting operationExecutor.MountVolume", remountingLogStr), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
err := rc.operationExecutor.MountVolume(
|
|
|
|
|
rc.waitForAttachTimeout,
|
|
|
|
|
volumeToMount.VolumeToMount,
|
|
|
|
|
rc.actualStateOfWorld,
|
|
|
|
|
isRemount)
|
|
|
|
|
if err != nil && !isExpectedError(err) {
|
|
|
|
|
klog.ErrorS(err, volumeToMount.GenerateErrorDetailed(fmt.Sprintf("operationExecutor.MountVolume failed (controllerAttachDetachEnabled %v)", rc.controllerAttachDetachEnabled), err).Error(), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
if err == nil {
|
|
|
|
|
if remountingLogStr == "" {
|
|
|
|
|
klog.V(1).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.MountVolume started", remountingLogStr), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
} else {
|
|
|
|
|
klog.V(5).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.MountVolume started", remountingLogStr), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if cache.IsFSResizeRequiredError(err) {
|
|
|
|
|
klog.V(4).InfoS(volumeToMount.GenerateMsgDetailed("Starting operationExecutor.ExpandInUseVolume", ""), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
err := rc.operationExecutor.ExpandInUseVolume(
|
|
|
|
|
volumeToMount.VolumeToMount,
|
|
|
|
|
rc.actualStateOfWorld)
|
|
|
|
|
if err != nil && !isExpectedError(err) {
|
|
|
|
|
klog.ErrorS(err, volumeToMount.GenerateErrorDetailed("operationExecutor.ExpandInUseVolume failed", err).Error(), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
if err == nil {
|
|
|
|
|
klog.V(4).InfoS(volumeToMount.GenerateMsgDetailed("operationExecutor.ExpandInUseVolume started", ""), "pod", klog.KObj(volumeToMount.Pod))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rc *reconciler) unmountDetachDevices() {
|
|
|
|
|