From fd2dbe0d6855f2621352e1915142e8ceaf584de5 Mon Sep 17 00:00:00 2001 From: huweiwen Date: Fri, 15 Dec 2023 18:11:42 +0800 Subject: [PATCH] kubelet: don't check for mounted before update dsw PV size We are still only calling NodeExpand after the volume is mounted. avoid depending on ASW from dswp.findAndAddNewPods(). It is weird to determine desired state based on actual state. --- .../desired_state_of_world_populator.go | 51 +++---------------- 1 file changed, 7 insertions(+), 44 deletions(-) diff --git a/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go b/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go index 1c5eeeeeb63..63c7152040e 100644 --- a/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go +++ b/pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go @@ -180,17 +180,6 @@ func (dswp *desiredStateOfWorldPopulator) populatorLoop(ctx context.Context) { // Iterate through all pods and add to desired state of world if they don't // exist but should func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods(ctx context.Context) { - // Map unique pod name to outer volume name to MountedVolume. - mountedVolumesForPod := make(map[volumetypes.UniquePodName]map[string]cache.MountedVolume) - for _, mountedVolume := range dswp.actualStateOfWorld.GetMountedVolumes() { - mountedVolumes, exist := mountedVolumesForPod[mountedVolume.PodName] - if !exist { - mountedVolumes = make(map[string]cache.MountedVolume) - mountedVolumesForPod[mountedVolume.PodName] = mountedVolumes - } - mountedVolumes[mountedVolume.OuterVolumeSpecName] = mountedVolume - } - for _, pod := range dswp.podManager.GetPods() { // Keep consistency of adding pod during reconstruction if dswp.hasAddedPods && dswp.podStateProvider.ShouldPodContainersBeTerminating(pod.UID) { @@ -204,7 +193,7 @@ func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods(ctx context.Context) continue } - dswp.processPodVolumes(ctx, pod, mountedVolumesForPod) + dswp.processPodVolumes(ctx, pod) } } @@ -286,10 +275,7 @@ func (dswp *desiredStateOfWorldPopulator) findAndRemoveDeletedPods() { // processPodVolumes processes the volumes in the given pod and adds them to the // desired state of the world. -func (dswp *desiredStateOfWorldPopulator) processPodVolumes( - ctx context.Context, - pod *v1.Pod, - mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) { +func (dswp *desiredStateOfWorldPopulator) processPodVolumes(ctx context.Context, pod *v1.Pod) { if pod == nil { return } @@ -322,17 +308,17 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes( } // Add volume to desired state of world - _, err = dswp.desiredStateOfWorld.AddPodToVolume( + uniqueVolumeName, err := dswp.desiredStateOfWorld.AddPodToVolume( uniquePodName, pod, volumeSpec, podVolume.Name, volumeGIDValue, seLinuxContainerContexts[podVolume.Name]) if err != nil { logger.Error(err, "Failed to add volume to desiredStateOfWorld", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name()) dswp.desiredStateOfWorld.AddErrorToPod(uniquePodName, err.Error()) allVolumesAdded = false - } else { - logger.V(4).Info("Added volume to desired state", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name()) + continue } - dswp.checkVolumeFSResize(pod, podVolume, pvc, volumeSpec, uniquePodName, mountedVolumesForPod) + logger.V(4).Info("Added volume to desired state", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name()) + dswp.checkVolumeFSResize(pod, podVolume, pvc, volumeSpec, uniqueVolumeName) } // some of the volume additions may have failed, should not mark this pod as fully processed @@ -361,8 +347,7 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize( podVolume v1.Volume, pvc *v1.PersistentVolumeClaim, volumeSpec *volume.Spec, - uniquePodName volumetypes.UniquePodName, - mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) { + uniqueVolumeName v1.UniqueVolumeName) { // if a volumeSpec does not have PV or has InlineVolumeSpecForCSIMigration set or pvc is nil // we can't resize the volume and hence resizing should be skipped. @@ -371,13 +356,6 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize( return } - uniqueVolumeName, exist := getUniqueVolumeName(uniquePodName, podVolume.Name, mountedVolumesForPod) - if !exist { - // Volume not exist in ASW, we assume it hasn't been mounted yet. If it needs resize, - // it will be handled as offline resize(if it indeed hasn't been mounted yet), - // or online resize in subsequent loop(after we confirm it has been mounted). - return - } // volumeSpec.ReadOnly is the value that determines if volume could be formatted when being mounted. // This is the same flag that determines filesystem resizing behaviour for offline resizing and hence // we should use it here. This value comes from Pod.spec.volumes.persistentVolumeClaim.readOnly. @@ -395,21 +373,6 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize( dswp.actualStateOfWorld.InitializeClaimSize(klog.TODO(), uniqueVolumeName, pvcStatusCap) } -func getUniqueVolumeName( - podName volumetypes.UniquePodName, - outerVolumeSpecName string, - mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) (v1.UniqueVolumeName, bool) { - mountedVolumes, exist := mountedVolumesForPod[podName] - if !exist { - return "", false - } - mountedVolume, exist := mountedVolumes[outerVolumeSpecName] - if !exist { - return "", false - } - return mountedVolume.VolumeName, true -} - // podPreviouslyProcessed returns true if the volumes for this pod have already // been processed/reprocessed by the populator. Otherwise, the volumes for this pod need to // be reprocessed.