Update volumesInUse after attachability is confirmed

node.status.volumesInUse should report only attachable volumes, therefore
it needs to wait for the reconciler to update uncertain attachability of
volumes from the API server.
This commit is contained in:
Jan Safranek 2023-05-11 17:11:23 +02:00
parent 0a2272dc68
commit 7cd60df4aa
3 changed files with 12 additions and 5 deletions

View File

@ -57,7 +57,13 @@ func (rc *reconciler) reconcileNew() {
}
if len(rc.volumesNeedDevicePath) != 0 {
rc.updateReconstructedDevicePaths()
rc.updateReconstructedFromAPIServer()
}
if len(rc.volumesNeedDevicePath) == 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.
rc.updateLastSyncTime()
}
if len(rc.volumesNeedReportedInUse) != 0 && rc.populatorHasAddedPods() {

View File

@ -116,13 +116,15 @@ func TestReconcileWithUpdateReconstructedFromAPIServer(t *testing.T) {
assert.NoError(t, asw.AddAttachUncertainReconstructedVolume(volumeName2, volumeSpec2, nodeName, ""))
assert.NoError(t, asw.MarkDeviceAsUncertain(volumeName2, "/dev/reconstructed", "/var/lib/kubelet/plugins/global2", ""))
reconciler.volumesNeedDevicePath = append(reconciler.volumesNeedDevicePath, volumeName1, volumeName2)
assert.False(t, reconciler.StatesHasBeenSynced())
reconciler.volumesNeedDevicePath = append(reconciler.volumesNeedDevicePath, volumeName1, volumeName2)
// Act - run reconcile loop just once.
// "volumesNeedDevicePath" is not empty, so no unmount will be triggered.
reconciler.reconcileNew()
// Assert
assert.True(t, reconciler.StatesHasBeenSynced())
assert.Empty(t, reconciler.volumesNeedDevicePath)
attachedVolumes := asw.GetAttachedVolumes()

View File

@ -50,7 +50,6 @@ func (rc *reconciler) readyToUnmount() bool {
// put the volumes to volumesFailedReconstruction to be cleaned up later when DesiredStateOfWorld
// is populated.
func (rc *reconciler) reconstructVolumes() {
defer rc.updateLastSyncTime()
// Get volumes information by reading the pod's directory
podVolumes, err := getVolumesFromPodDir(rc.kubeletPodsDir)
if err != nil {
@ -174,10 +173,10 @@ func (rc *reconciler) cleanOrphanVolumes() {
rc.volumesFailedReconstruction = make([]podVolume, 0)
}
// updateReconstructedDevicePaths tries to file devicePaths of reconstructed volumes from
// updateReconstructedFromAPIServer tries to file devicePaths of reconstructed volumes from
// node.Status.VolumesAttached. This can be done only after connection to the API
// server is established, i.e. it can't be part of reconstructVolumes().
func (rc *reconciler) updateReconstructedDevicePaths() {
func (rc *reconciler) updateReconstructedFromAPIServer() {
klog.V(4).InfoS("Updating reconstructed devicePaths")
if rc.kubeClient == nil {