Skip to content

Commit

Permalink
feat: specify cachedirs in configmap
Browse files Browse the repository at this point in the history
Signed-off-by: Xuhui zhang <[email protected]>
  • Loading branch information
zxh326 committed Oct 11, 2024
1 parent d0f5c04 commit 5a1805f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
25 changes: 23 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion pkg/config/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5a1805f

Please sign in to comment.