mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Rename volumesNeedDevicePath
To volumesNeedUpdateFromNodeStatus - because both devicePath and uncertain attach-ability needs to be fixed from node status.
This commit is contained in:
parent
7cd60df4aa
commit
1903f5aa2a
@ -104,24 +104,24 @@ func NewReconciler(
|
||||
volumePluginMgr *volumepkg.VolumePluginMgr,
|
||||
kubeletPodsDir string) Reconciler {
|
||||
return &reconciler{
|
||||
kubeClient: kubeClient,
|
||||
controllerAttachDetachEnabled: controllerAttachDetachEnabled,
|
||||
loopSleepDuration: loopSleepDuration,
|
||||
waitForAttachTimeout: waitForAttachTimeout,
|
||||
nodeName: nodeName,
|
||||
desiredStateOfWorld: desiredStateOfWorld,
|
||||
actualStateOfWorld: actualStateOfWorld,
|
||||
populatorHasAddedPods: populatorHasAddedPods,
|
||||
operationExecutor: operationExecutor,
|
||||
mounter: mounter,
|
||||
hostutil: hostutil,
|
||||
skippedDuringReconstruction: map[v1.UniqueVolumeName]*globalVolumeInfo{},
|
||||
volumePluginMgr: volumePluginMgr,
|
||||
kubeletPodsDir: kubeletPodsDir,
|
||||
timeOfLastSync: time.Time{},
|
||||
volumesFailedReconstruction: make([]podVolume, 0),
|
||||
volumesNeedDevicePath: make([]v1.UniqueVolumeName, 0),
|
||||
volumesNeedReportedInUse: make([]v1.UniqueVolumeName, 0),
|
||||
kubeClient: kubeClient,
|
||||
controllerAttachDetachEnabled: controllerAttachDetachEnabled,
|
||||
loopSleepDuration: loopSleepDuration,
|
||||
waitForAttachTimeout: waitForAttachTimeout,
|
||||
nodeName: nodeName,
|
||||
desiredStateOfWorld: desiredStateOfWorld,
|
||||
actualStateOfWorld: actualStateOfWorld,
|
||||
populatorHasAddedPods: populatorHasAddedPods,
|
||||
operationExecutor: operationExecutor,
|
||||
mounter: mounter,
|
||||
hostutil: hostutil,
|
||||
skippedDuringReconstruction: map[v1.UniqueVolumeName]*globalVolumeInfo{},
|
||||
volumePluginMgr: volumePluginMgr,
|
||||
kubeletPodsDir: kubeletPodsDir,
|
||||
timeOfLastSync: time.Time{},
|
||||
volumesFailedReconstruction: make([]podVolume, 0),
|
||||
volumesNeedUpdateFromNodeStatus: make([]v1.UniqueVolumeName, 0),
|
||||
volumesNeedReportedInUse: make([]v1.UniqueVolumeName, 0),
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,11 +141,11 @@ type reconciler struct {
|
||||
skippedDuringReconstruction map[v1.UniqueVolumeName]*globalVolumeInfo
|
||||
kubeletPodsDir string
|
||||
// lock protects timeOfLastSync for updating and checking
|
||||
timeOfLastSyncLock sync.Mutex
|
||||
timeOfLastSync time.Time
|
||||
volumesFailedReconstruction []podVolume
|
||||
volumesNeedDevicePath []v1.UniqueVolumeName
|
||||
volumesNeedReportedInUse []v1.UniqueVolumeName
|
||||
timeOfLastSyncLock sync.Mutex
|
||||
timeOfLastSync time.Time
|
||||
volumesFailedReconstruction []podVolume
|
||||
volumesNeedUpdateFromNodeStatus []v1.UniqueVolumeName
|
||||
volumesNeedReportedInUse []v1.UniqueVolumeName
|
||||
}
|
||||
|
||||
func (rc *reconciler) Run(stopCh <-chan struct{}) {
|
||||
|
@ -56,10 +56,10 @@ func (rc *reconciler) reconcileNew() {
|
||||
rc.cleanOrphanVolumes()
|
||||
}
|
||||
|
||||
if len(rc.volumesNeedDevicePath) != 0 {
|
||||
if len(rc.volumesNeedUpdateFromNodeStatus) != 0 {
|
||||
rc.updateReconstructedFromAPIServer()
|
||||
}
|
||||
if len(rc.volumesNeedDevicePath) == 0 {
|
||||
if len(rc.volumesNeedUpdateFromNodeStatus) == 0 {
|
||||
// ASW is fully populated only after both devicePaths and uncertain volume attach-ability
|
||||
// were reconstructed from the API server.
|
||||
// This will start reconciliation of node.status.volumesInUse.
|
||||
|
@ -118,14 +118,14 @@ func TestReconcileWithUpdateReconstructedFromAPIServer(t *testing.T) {
|
||||
|
||||
assert.False(t, reconciler.StatesHasBeenSynced())
|
||||
|
||||
reconciler.volumesNeedDevicePath = append(reconciler.volumesNeedDevicePath, volumeName1, volumeName2)
|
||||
reconciler.volumesNeedUpdateFromNodeStatus = append(reconciler.volumesNeedUpdateFromNodeStatus, volumeName1, volumeName2)
|
||||
// Act - run reconcile loop just once.
|
||||
// "volumesNeedDevicePath" is not empty, so no unmount will be triggered.
|
||||
// "volumesNeedUpdateFromNodeStatus" is not empty, so no unmount will be triggered.
|
||||
reconciler.reconcileNew()
|
||||
|
||||
// Assert
|
||||
assert.True(t, reconciler.StatesHasBeenSynced())
|
||||
assert.Empty(t, reconciler.volumesNeedDevicePath)
|
||||
assert.Empty(t, reconciler.volumesNeedUpdateFromNodeStatus)
|
||||
|
||||
attachedVolumes := asw.GetAttachedVolumes()
|
||||
assert.Equalf(t, len(attachedVolumes), 2, "two volumes in ASW expected")
|
||||
|
@ -39,7 +39,7 @@ func (rc *reconciler) readyToUnmount() bool {
|
||||
|
||||
// Allow unmount only when ASW device paths were corrected from node.status to prevent
|
||||
// calling unmount with a wrong devicePath.
|
||||
if len(rc.volumesNeedDevicePath) != 0 {
|
||||
if len(rc.volumesNeedUpdateFromNodeStatus) != 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -97,7 +97,7 @@ func (rc *reconciler) reconstructVolumes() {
|
||||
// Remember to update DSW with this information.
|
||||
rc.volumesNeedReportedInUse = reconstructedVolumeNames
|
||||
// Remember to update devicePath from node.status.volumesAttached
|
||||
rc.volumesNeedDevicePath = reconstructedVolumeNames
|
||||
rc.volumesNeedUpdateFromNodeStatus = reconstructedVolumeNames
|
||||
}
|
||||
klog.V(2).InfoS("Volume reconstruction finished")
|
||||
}
|
||||
@ -183,18 +183,18 @@ func (rc *reconciler) updateReconstructedFromAPIServer() {
|
||||
// Skip reconstructing devicePath from node objects if kubelet is in standalone mode.
|
||||
// Such kubelet is not expected to mount any attachable volume or Secrets / ConfigMap.
|
||||
klog.V(2).InfoS("Skipped reconstruction of DevicePaths from node.status in standalone mode")
|
||||
rc.volumesNeedDevicePath = nil
|
||||
rc.volumesNeedUpdateFromNodeStatus = nil
|
||||
return
|
||||
}
|
||||
|
||||
node, fetchErr := rc.kubeClient.CoreV1().Nodes().Get(context.TODO(), string(rc.nodeName), metav1.GetOptions{})
|
||||
if fetchErr != nil {
|
||||
// This may repeat few times per second until kubelet is able to read its own status for the first time.
|
||||
klog.V(2).ErrorS(fetchErr, "Failed to get Node status to reconstruct device paths")
|
||||
klog.V(4).ErrorS(fetchErr, "Failed to get Node status to reconstruct device paths")
|
||||
return
|
||||
}
|
||||
|
||||
for _, volumeID := range rc.volumesNeedDevicePath {
|
||||
for _, volumeID := range rc.volumesNeedUpdateFromNodeStatus {
|
||||
attachable := false
|
||||
for _, attachedVolume := range node.Status.VolumesAttached {
|
||||
if volumeID != attachedVolume.Name {
|
||||
@ -208,5 +208,5 @@ func (rc *reconciler) updateReconstructedFromAPIServer() {
|
||||
}
|
||||
|
||||
klog.V(2).InfoS("DevicePaths of reconstructed volumes updated")
|
||||
rc.volumesNeedDevicePath = nil
|
||||
rc.volumesNeedUpdateFromNodeStatus = nil
|
||||
}
|
||||
|
@ -117,8 +117,8 @@ func TestReconstructVolumes(t *testing.T) {
|
||||
for i := range tc.expectedVolumesNeedDevicePath {
|
||||
expectedVolumes[i] = v1.UniqueVolumeName(tc.expectedVolumesNeedDevicePath[i])
|
||||
}
|
||||
if !reflect.DeepEqual(expectedVolumes, rcInstance.volumesNeedDevicePath) {
|
||||
t.Errorf("Expected expectedVolumesNeedDevicePath:\n%v\n got:\n%v", expectedVolumes, rcInstance.volumesNeedDevicePath)
|
||||
if !reflect.DeepEqual(expectedVolumes, rcInstance.volumesNeedUpdateFromNodeStatus) {
|
||||
t.Errorf("Expected expectedVolumesNeedDevicePath:\n%v\n got:\n%v", expectedVolumes, rcInstance.volumesNeedUpdateFromNodeStatus)
|
||||
}
|
||||
|
||||
expectedVolumes = make([]v1.UniqueVolumeName, len(tc.expectedVolumesNeedReportedInUse))
|
||||
@ -333,7 +333,7 @@ func TestReconstructVolumesMount(t *testing.T) {
|
||||
return true
|
||||
}
|
||||
// Mark devices paths as reconciled to allow unmounting of volumes.
|
||||
rcInstance.volumesNeedDevicePath = nil
|
||||
rcInstance.volumesNeedUpdateFromNodeStatus = nil
|
||||
|
||||
// Act 2 - reconcile once
|
||||
rcInstance.reconcileNew()
|
||||
|
Loading…
Reference in New Issue
Block a user