Skip to content

Commit

Permalink
Rename volumesNeedDevicePath
Browse files Browse the repository at this point in the history
To volumesNeedUpdateFromNodeStatus - because both devicePath and uncertain
attach-ability needs to be fixed from node status.
  • Loading branch information
jsafrane committed Jul 11, 2023
1 parent 7cd60df commit 1903f5a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
46 changes: 23 additions & 23 deletions pkg/kubelet/volumemanager/reconciler/reconciler_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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{}) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/volumemanager/reconciler/reconciler_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/volumemanager/reconciler/reconciler_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions pkg/kubelet/volumemanager/reconciler/reconstruct_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand All @@ -208,5 +208,5 @@ func (rc *reconciler) updateReconstructedFromAPIServer() {
}

klog.V(2).InfoS("DevicePaths of reconstructed volumes updated")
rc.volumesNeedDevicePath = nil
rc.volumesNeedUpdateFromNodeStatus = nil
}
6 changes: 3 additions & 3 deletions pkg/kubelet/volumemanager/reconciler/reconstruct_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1903f5a

Please sign in to comment.