Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cache dir from sidecar pod #1462

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/application/inject/fuse/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ func (s *Injector) inject(in runtime.Object, pvcName string, runtimeInfo base.Ru
}

// if it's not serverless enable or injection is done, skip
if !utils.ServerlessEnabled(metaObj.Labels) || utils.SidecarInjectDone(metaObj.Labels) {
if !utils.ServerlessEnabled(metaObj.Labels) || utils.InjectSidecarDone(metaObj.Labels) {
continue
}

// 1. check if the pod spec has fluid volume claim
injectFuseContainer := true
template, err := runtimeInfo.GetTemplateToInjectForFuse(pvcName)
enableCacheDir := utils.InjectCacheDirEnabled(metaObj.Labels)
template, err := runtimeInfo.GetTemplateToInjectForFuse(pvcName, enableCacheDir)
if err != nil {
return out, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const (
injectSidecar = ".sidecar" + inject
InjectServerless = "serverless" + inject
InjectFuseSidecar = "fuse" + injectSidecar
InjectCacheDir = "cachedir" + injectSidecar
InjectWorkerSidecar = "worker" + injectSidecar
InjectSidecarDone = "done" + injectSidecar
)
2 changes: 1 addition & 1 deletion pkg/ddc/base/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type RuntimeInfoInterface interface {

IsDeprecatedPVName() bool

GetTemplateToInjectForFuse(pvcName string) (*common.FuseInjectionTemplate, error)
GetTemplateToInjectForFuse(pvcName string, enableCache bool) (*common.FuseInjectionTemplate, error)

SetClient(client client.Client)
}
Expand Down
21 changes: 17 additions & 4 deletions pkg/ddc/base/runtime_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ import (
"k8s.io/apimachinery/pkg/types"
)

var (
// datavolume- for JindoFS
// mem, ssd, hdd for Alluxio and GooseFS
// cache-dir for JuiceFS
cacheDirNames = []string{"datavolume-", "cache-dir", "mem", "ssd", "hdd"}
)

// GetTemplateToInjectForFuse gets template for fuse injection
func (info *RuntimeInfo) GetTemplateToInjectForFuse(pvcName string) (template *common.FuseInjectionTemplate, err error) {
func (info *RuntimeInfo) GetTemplateToInjectForFuse(pvcName string, enableCacheDir bool) (template *common.FuseInjectionTemplate, err error) {
// TODO: create fuse container
ds, err := info.getFuseDaemonset()
if err != nil {
Expand All @@ -51,15 +58,21 @@ func (info *RuntimeInfo) GetTemplateToInjectForFuse(pvcName string) (template *c
UID: dataset.UID,
}

// 0. remove the cache dir if required
if len(ds.Spec.Template.Spec.Containers) != 1 {
return template, fmt.Errorf("the length of containers of fuse %s in namespace %s is not 1", ds.Name, ds.Namespace)
}
if !enableCacheDir {
ds.Spec.Template.Spec.Containers[0].VolumeMounts = utils.TrimVolumeMounts(ds.Spec.Template.Spec.Containers[0].VolumeMounts, cacheDirNames)
ds.Spec.Template.Spec.Volumes = utils.TrimVolumes(ds.Spec.Template.Spec.Volumes, cacheDirNames)
}

// 1. set the pvc name
template = &common.FuseInjectionTemplate{
PVCName: pvcName,
}

// 2. set the fuse container
if len(ds.Spec.Template.Spec.Containers) != 1 {
return template, fmt.Errorf("the length of containers of fuse %s in namespace %s is not 1", ds.Name, ds.Namespace)
}
template.FuseContainer = ds.Spec.Template.Spec.Containers[0]
template.FuseContainer.Name = common.FuseContainerName

Expand Down
Loading