From f58cfb0af7deacf1eeaf86f1f0fadb18e8e7b158 Mon Sep 17 00:00:00 2001 From: trafalgarzzz Date: Fri, 8 Aug 2025 11:59:13 +0800 Subject: [PATCH] file prefetcher supports non-fluid PVCs Signed-off-by: trafalgarzzz --- charts/fluid/fluid/values.yaml | 4 +++- .../plugins/fileprefetcher/file_prefetcher.go | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/charts/fluid/fluid/values.yaml b/charts/fluid/fluid/values.yaml index 7ee136753e8..0fdfb05ee43 100644 --- a/charts/fluid/fluid/values.yaml +++ b/charts/fluid/fluid/values.yaml @@ -368,6 +368,7 @@ webhook: - MountPropagationInjector - DatasetUsageInjector withoutDataset: + - FilePrefetcher - PreferNodesWithoutCache # serverless webhook plugins serverless: @@ -375,7 +376,8 @@ webhook: - FilePrefetcher - FuseSidecar - DatasetUsageInjector - withoutDataset: [] + withoutDataset: + - FilePrefetcher pluginConfig: - name: NodeAffinityWithCache # plugin args is a serialized yaml string. diff --git a/pkg/webhook/plugins/fileprefetcher/file_prefetcher.go b/pkg/webhook/plugins/fileprefetcher/file_prefetcher.go index 5da0c7fad81..02b450439a1 100644 --- a/pkg/webhook/plugins/fileprefetcher/file_prefetcher.go +++ b/pkg/webhook/plugins/fileprefetcher/file_prefetcher.go @@ -91,23 +91,29 @@ func (p *FilePrefetcher) Mutate(pod *corev1.Pod, runtimeInfos map[string]base.Ru } containerSpec, statusFileVolume := p.buildFilePrefetcherSidecarContainer(config) + + // Inject file prefetcher container right after fuse sidecar containers, we assume fluid's fuse sidecar container is injected together. + // e.g. before injection: [C1, FUSE1, FUSE2, C2, C3], after injection: [C1, FUSE1, FUSE2, FILEPREFETCHER, C2, C3] + pod.Spec.Containers = p.injectFilePrefetcherSidecar(pod.Spec.Containers, containerSpec) if config.AsyncPrefetch { statusVolumeMount := corev1.VolumeMount{ Name: filePrefetcherStatusVolumeName, MountPath: filePrefetcherStatusVolumeMountPath, } + var foundPrefetcherSidecar bool = false for idx, ctr := range pod.Spec.Containers { - if strings.HasPrefix(ctr.Name, common.FuseContainerName) { - // Skip injecting file prefetcher status volume into fluid's fuse sidecar containers. + // Skip injecting status volume until we found a file prefetcher file prefetcher sidecar + // e.g. if the containers are [C1, FUSE1, FUSE2, FILEPREFETCHER, C2, C3], only C2 and C3 will get this status volume + if !foundPrefetcherSidecar { + if strings.HasPrefix(ctr.Name, filePrefetcherContainerName) { + foundPrefetcherSidecar = true + } continue } + pod.Spec.Containers[idx].VolumeMounts = append(pod.Spec.Containers[idx].VolumeMounts, statusVolumeMount) } } - - // Inject file prefetcher container right after fuse sidecar containers, we assume fluid's fuse sidecar container is injected together. - // e.g. before injection: [C1, FUSE1, FUSE2, C2, C3], after injection: [C1, FUSE1, FUSE2, FILEPREFETCHER, C2, C3] - pod.Spec.Containers = p.injectFilePrefetcherSidecar(pod.Spec.Containers, containerSpec) pod.Spec.Volumes = append(pod.Spec.Volumes, statusFileVolume) pod.Annotations[AnnotationFilePrefetcherInjectDone] = common.True @@ -221,11 +227,6 @@ func (p *FilePrefetcher) parseGlobPathsFromFileList(fileList string, pod *corev1 globPath = filepath.Clean(fmt.Sprintf("%c%s", filepath.Separator, filepath.Join(items[1:]...))) } - if _, ok := runtimeInfos[pvcName]; !ok { - p.log.Info("skip adding path to prefetch list because the persistentVolumeClaim is not managed by Fluid", "path", uriPath) - continue - } - for _, volume := range pod.Spec.Volumes { if volume.PersistentVolumeClaim != nil && volume.PersistentVolumeClaim.ClaimName == pvcName { volumeMountPaths[volume.Name] = path.Join("/data", volume.Name)