From 5a1805f15cd41b2f26766a1e3e41d33a389142a6 Mon Sep 17 00:00:00 2001 From: Xuhui zhang Date: Fri, 11 Oct 2024 15:37:21 +0800 Subject: [PATCH] feat: specify cachedirs in configmap Signed-off-by: Xuhui zhang --- pkg/config/config.go | 25 +++++++++++++++++++++++-- pkg/config/setting.go | 22 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index a2f69e9578..8d6d9835e9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -130,13 +130,31 @@ type PVCSelector struct { MatchName string `json:"matchName,omitempty"` } +type MountPatchCacheDirType string + +var ( + MountPatchCacheDirTypeHostPath MountPatchCacheDirType = "HostPath" + MountPatchCacheDirTypePVC MountPatchCacheDirType = "PVC" +) + +type MountPatchCacheDir struct { + Type MountPatchCacheDirType `json:"type,omitempty"` + + // required for HostPath type + Path string `json:"path,omitempty"` + + // required for PVC type + Name string `json:"name,omitempty"` +} + type MountPodPatch struct { // used to specify the selector for the PVC that will be patched // omit will patch for all PVC PVCSelector *PVCSelector `json:"pvcSelector,omitempty"` - CEMountImage string `json:"ceMountImage,omitempty"` - EEMountImage string `json:"eeMountImage,omitempty"` + CEMountImage string `json:"ceMountImage,omitempty"` + EEMountImage string `json:"eeMountImage,omitempty"` + CacheDirs []MountPatchCacheDir `json:"cacheDirs,omitempty"` Image string `json:"-"` Labels map[string]string `json:"labels,omitempty"` @@ -275,6 +293,9 @@ func (mpp *MountPodPatch) merge(mp MountPodPatch) { if mp.MountOptions != nil { mpp.MountOptions = mp.MountOptions } + if mp.CacheDirs != nil { + mpp.CacheDirs = mp.CacheDirs + } } // TODO: migrate more config for here diff --git a/pkg/config/setting.go b/pkg/config/setting.go index edb7c97eb0..ef32a2f6ed 100644 --- a/pkg/config/setting.go +++ b/pkg/config/setting.go @@ -104,6 +104,7 @@ type PodAttr struct { VolumeDevices []corev1.VolumeDevice `json:"volumeDevices,omitempty"` VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` Env []corev1.EnvVar `json:"env,omitempty"` + CacheDirs []MountPatchCacheDir `json:"cacheDirs,omitempty"` // inherit from csi Image string @@ -256,8 +257,18 @@ func genCacheDirs(jfsSetting *JfsSetting, volCtx map[string]string) error { cacheDirsInContainer := []string{} var err error // parse pvc of cache + cachePVCs := []string{} if volCtx != nil && volCtx[common.CachePVC] != "" { - cachePVCs := strings.Split(strings.TrimSpace(volCtx[common.CachePVC]), ",") + cachePVCs = strings.Split(strings.TrimSpace(volCtx[common.CachePVC]), ",") + } + if len(jfsSetting.Attr.CacheDirs) > 0 { + for _, cacheDir := range jfsSetting.Attr.CacheDirs { + if cacheDir.Type == MountPatchCacheDirTypePVC { + cachePVCs = append(cachePVCs, cacheDir.Name) + } + } + } + if len(cachePVCs) > 0 { for i, pvc := range cachePVCs { if pvc == "" { continue @@ -270,6 +281,7 @@ func genCacheDirs(jfsSetting *JfsSetting, volCtx map[string]string) error { cacheDirsInContainer = append(cacheDirsInContainer, volPath) } } + // parse emptydir of cache if volCtx != nil { if _, ok := volCtx[common.CacheEmptyDir]; ok { @@ -335,6 +347,13 @@ func genCacheDirs(jfsSetting *JfsSetting, volCtx map[string]string) error { break } } + // parse hostPath dirs in setting attr + for _, cacheDir := range jfsSetting.Attr.CacheDirs { + if cacheDir.Type == MountPatchCacheDirTypeHostPath { + cacheDirsInContainer = append(cacheDirsInContainer, cacheDir.Path) + jfsSetting.CacheDirs = append(jfsSetting.CacheDirs, cacheDir.Path) + } + } if len(cacheDirsInContainer) == 0 { // set default cache dir cacheDirsInOptions = []string{"/var/jfsCache"} @@ -749,6 +768,7 @@ func applyConfigPatch(setting *JfsSetting) { attr.VolumeMounts = patch.VolumeMounts attr.Volumes = patch.Volumes attr.Env = patch.Env + attr.CacheDirs = patch.CacheDirs // merge or overwrite setting options if setting.Options == nil {