Skip to content

Commit aee1a91

Browse files
authored
Merge pull request kubernetes#128644 from huww98/multi-volume-part-1
kubelet: don't check for mounted before update dsw PV size
2 parents 25101d3 + fd2dbe0 commit aee1a91

File tree

1 file changed

+7
-44
lines changed

1 file changed

+7
-44
lines changed

pkg/kubelet/volumemanager/populator/desired_state_of_world_populator.go

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,6 @@ func (dswp *desiredStateOfWorldPopulator) populatorLoop(ctx context.Context) {
180180
// Iterate through all pods and add to desired state of world if they don't
181181
// exist but should
182182
func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods(ctx context.Context) {
183-
// Map unique pod name to outer volume name to MountedVolume.
184-
mountedVolumesForPod := make(map[volumetypes.UniquePodName]map[string]cache.MountedVolume)
185-
for _, mountedVolume := range dswp.actualStateOfWorld.GetMountedVolumes() {
186-
mountedVolumes, exist := mountedVolumesForPod[mountedVolume.PodName]
187-
if !exist {
188-
mountedVolumes = make(map[string]cache.MountedVolume)
189-
mountedVolumesForPod[mountedVolume.PodName] = mountedVolumes
190-
}
191-
mountedVolumes[mountedVolume.OuterVolumeSpecName] = mountedVolume
192-
}
193-
194183
for _, pod := range dswp.podManager.GetPods() {
195184
// Keep consistency of adding pod during reconstruction
196185
if dswp.hasAddedPods && dswp.podStateProvider.ShouldPodContainersBeTerminating(pod.UID) {
@@ -204,7 +193,7 @@ func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods(ctx context.Context)
204193
continue
205194
}
206195

207-
dswp.processPodVolumes(ctx, pod, mountedVolumesForPod)
196+
dswp.processPodVolumes(ctx, pod)
208197
}
209198
}
210199

@@ -286,10 +275,7 @@ func (dswp *desiredStateOfWorldPopulator) findAndRemoveDeletedPods() {
286275

287276
// processPodVolumes processes the volumes in the given pod and adds them to the
288277
// desired state of the world.
289-
func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
290-
ctx context.Context,
291-
pod *v1.Pod,
292-
mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) {
278+
func (dswp *desiredStateOfWorldPopulator) processPodVolumes(ctx context.Context, pod *v1.Pod) {
293279
if pod == nil {
294280
return
295281
}
@@ -322,17 +308,17 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
322308
}
323309

324310
// Add volume to desired state of world
325-
_, err = dswp.desiredStateOfWorld.AddPodToVolume(
311+
uniqueVolumeName, err := dswp.desiredStateOfWorld.AddPodToVolume(
326312
uniquePodName, pod, volumeSpec, podVolume.Name, volumeGIDValue, seLinuxContainerContexts[podVolume.Name])
327313
if err != nil {
328314
logger.Error(err, "Failed to add volume to desiredStateOfWorld", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name())
329315
dswp.desiredStateOfWorld.AddErrorToPod(uniquePodName, err.Error())
330316
allVolumesAdded = false
331-
} else {
332-
logger.V(4).Info("Added volume to desired state", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name())
317+
continue
333318
}
334319

335-
dswp.checkVolumeFSResize(pod, podVolume, pvc, volumeSpec, uniquePodName, mountedVolumesForPod)
320+
logger.V(4).Info("Added volume to desired state", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name())
321+
dswp.checkVolumeFSResize(pod, podVolume, pvc, volumeSpec, uniqueVolumeName)
336322
}
337323

338324
// some of the volume additions may have failed, should not mark this pod as fully processed
@@ -361,8 +347,7 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize(
361347
podVolume v1.Volume,
362348
pvc *v1.PersistentVolumeClaim,
363349
volumeSpec *volume.Spec,
364-
uniquePodName volumetypes.UniquePodName,
365-
mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) {
350+
uniqueVolumeName v1.UniqueVolumeName) {
366351

367352
// if a volumeSpec does not have PV or has InlineVolumeSpecForCSIMigration set or pvc is nil
368353
// we can't resize the volume and hence resizing should be skipped.
@@ -371,13 +356,6 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize(
371356
return
372357
}
373358

374-
uniqueVolumeName, exist := getUniqueVolumeName(uniquePodName, podVolume.Name, mountedVolumesForPod)
375-
if !exist {
376-
// Volume not exist in ASW, we assume it hasn't been mounted yet. If it needs resize,
377-
// it will be handled as offline resize(if it indeed hasn't been mounted yet),
378-
// or online resize in subsequent loop(after we confirm it has been mounted).
379-
return
380-
}
381359
// volumeSpec.ReadOnly is the value that determines if volume could be formatted when being mounted.
382360
// This is the same flag that determines filesystem resizing behaviour for offline resizing and hence
383361
// we should use it here. This value comes from Pod.spec.volumes.persistentVolumeClaim.readOnly.
@@ -395,21 +373,6 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize(
395373
dswp.actualStateOfWorld.InitializeClaimSize(klog.TODO(), uniqueVolumeName, pvcStatusCap)
396374
}
397375

398-
func getUniqueVolumeName(
399-
podName volumetypes.UniquePodName,
400-
outerVolumeSpecName string,
401-
mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) (v1.UniqueVolumeName, bool) {
402-
mountedVolumes, exist := mountedVolumesForPod[podName]
403-
if !exist {
404-
return "", false
405-
}
406-
mountedVolume, exist := mountedVolumes[outerVolumeSpecName]
407-
if !exist {
408-
return "", false
409-
}
410-
return mountedVolume.VolumeName, true
411-
}
412-
413376
// podPreviouslyProcessed returns true if the volumes for this pod have already
414377
// been processed/reprocessed by the populator. Otherwise, the volumes for this pod need to
415378
// be reprocessed.

0 commit comments

Comments
 (0)