Skip to content

Commit

Permalink
Remove cache dir from sidecar pod (#1462)
Browse files Browse the repository at this point in the history
* Remove cache dir, To #39482462

Signed-off-by: cheyang <[email protected]>

* Remove cache dir, To #39482462

Signed-off-by: cheyang <[email protected]>

* Remove cache dir, To #39482462

Signed-off-by: cheyang <[email protected]>

* Add Fuse container sidecar test, To #37688693

Signed-off-by: cheyang <[email protected]>

* Add Fuse container sidecar test, To #37688693

Signed-off-by: cheyang <[email protected]>
  • Loading branch information
cheyang authored Feb 25, 2022
1 parent 109ba96 commit 0edad98
Show file tree
Hide file tree
Showing 9 changed files with 642 additions and 10 deletions.
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

0 comments on commit 0edad98

Please sign in to comment.