From 7cd60df4aa1bfc9ecce404870021787dce62bb57 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Thu, 11 May 2023 17:11:23 +0200 Subject: [PATCH] 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. --- pkg/kubelet/volumemanager/reconciler/reconciler_new.go | 8 +++++++- .../volumemanager/reconciler/reconciler_new_test.go | 4 +++- pkg/kubelet/volumemanager/reconciler/reconstruct_new.go | 5 ++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler_new.go b/pkg/kubelet/volumemanager/reconciler/reconciler_new.go index 9e9e19e9cbf..a8dfa438598 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconciler_new.go +++ b/pkg/kubelet/volumemanager/reconciler/reconciler_new.go @@ -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() { diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler_new_test.go b/pkg/kubelet/volumemanager/reconciler/reconciler_new_test.go index e4b22cbe7e8..8d02731d927 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconciler_new_test.go +++ b/pkg/kubelet/volumemanager/reconciler/reconciler_new_test.go @@ -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() diff --git a/pkg/kubelet/volumemanager/reconciler/reconstruct_new.go b/pkg/kubelet/volumemanager/reconciler/reconstruct_new.go index ba220bd003f..4769d955d12 100644 --- a/pkg/kubelet/volumemanager/reconciler/reconstruct_new.go +++ b/pkg/kubelet/volumemanager/reconciler/reconstruct_new.go @@ -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 {