mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Merge pull request #128644 from huww98/multi-volume-part-1
kubelet: don't check for mounted before update dsw PV size
This commit is contained in:
commit
aee1a91896
@ -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
|
// Iterate through all pods and add to desired state of world if they don't
|
||||||
// exist but should
|
// exist but should
|
||||||
func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods(ctx context.Context) {
|
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() {
|
for _, pod := range dswp.podManager.GetPods() {
|
||||||
// Keep consistency of adding pod during reconstruction
|
// Keep consistency of adding pod during reconstruction
|
||||||
if dswp.hasAddedPods && dswp.podStateProvider.ShouldPodContainersBeTerminating(pod.UID) {
|
if dswp.hasAddedPods && dswp.podStateProvider.ShouldPodContainersBeTerminating(pod.UID) {
|
||||||
@ -204,7 +193,7 @@ func (dswp *desiredStateOfWorldPopulator) findAndAddNewPods(ctx context.Context)
|
|||||||
continue
|
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
|
// processPodVolumes processes the volumes in the given pod and adds them to the
|
||||||
// desired state of the world.
|
// desired state of the world.
|
||||||
func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
|
func (dswp *desiredStateOfWorldPopulator) processPodVolumes(ctx context.Context, pod *v1.Pod) {
|
||||||
ctx context.Context,
|
|
||||||
pod *v1.Pod,
|
|
||||||
mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) {
|
|
||||||
if pod == nil {
|
if pod == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -322,17 +308,17 @@ func (dswp *desiredStateOfWorldPopulator) processPodVolumes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add volume to desired state of world
|
// 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])
|
uniquePodName, pod, volumeSpec, podVolume.Name, volumeGIDValue, seLinuxContainerContexts[podVolume.Name])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err, "Failed to add volume to desiredStateOfWorld", "pod", klog.KObj(pod), "volumeName", podVolume.Name, "volumeSpecName", volumeSpec.Name())
|
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())
|
dswp.desiredStateOfWorld.AddErrorToPod(uniquePodName, err.Error())
|
||||||
allVolumesAdded = false
|
allVolumesAdded = false
|
||||||
} else {
|
continue
|
||||||
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, 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
|
// 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,
|
podVolume v1.Volume,
|
||||||
pvc *v1.PersistentVolumeClaim,
|
pvc *v1.PersistentVolumeClaim,
|
||||||
volumeSpec *volume.Spec,
|
volumeSpec *volume.Spec,
|
||||||
uniquePodName volumetypes.UniquePodName,
|
uniqueVolumeName v1.UniqueVolumeName) {
|
||||||
mountedVolumesForPod map[volumetypes.UniquePodName]map[string]cache.MountedVolume) {
|
|
||||||
|
|
||||||
// if a volumeSpec does not have PV or has InlineVolumeSpecForCSIMigration set or pvc is nil
|
// 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.
|
// we can't resize the volume and hence resizing should be skipped.
|
||||||
@ -371,13 +356,6 @@ func (dswp *desiredStateOfWorldPopulator) checkVolumeFSResize(
|
|||||||
return
|
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.
|
// 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
|
// 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.
|
// 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)
|
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
|
// 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
|
// been processed/reprocessed by the populator. Otherwise, the volumes for this pod need to
|
||||||
// be reprocessed.
|
// be reprocessed.
|
||||||
|
Loading…
Reference in New Issue
Block a user