Skip to content

Commit

Permalink
Fix cache dir (#21)
Browse files Browse the repository at this point in the history
* fix cache dir

Signed-off-by: zwwhdls <zww@hdls.me>

* update mountpoint & parse option

Signed-off-by: zwwhdls <zww@hdls.me>

* fix test

Signed-off-by: zwwhdls <zww@hdls.me>

* fix nodeSelector in fuse

Signed-off-by: zwwhdls <zww@hdls.me>

* update doc

Signed-off-by: zwwhdls <zww@hdls.me>
  • Loading branch information
zwwhdls authored Nov 17, 2021
1 parent cbb9e49 commit a80b0a4
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 320 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 16 additions & 26 deletions charts/juicefs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ spec:
{{- if .Values.fuse.envs }}
{{ toYaml .Values.fuse.envs | trim | indent 10 }}
{{- end }}
- name: NAME
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.nameSecret }}
key: name
- name: ACCESS_KEY
valueFrom:
secretKeyRef:
Expand All @@ -69,21 +64,6 @@ spec:
secretKeyRef:
name: {{ .Values.fuse.prepare.secretkeySecret }}
key: secret-key
- name: BUCKET
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.bucketSecret }}
key: bucket
- name: META_URL
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.metaurlSecret }}
key: metaurl
- name: STORAGE
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.prepare.storageSecret }}
key: storage
volumeMounts:
- mountPath: /root/.juicefs
mountPropagation: Bidirectional
Expand Down Expand Up @@ -144,12 +124,22 @@ spec:
- mountPath: /root/.juicefs
mountPropagation: Bidirectional
name: jfs-root-dir
{{- if .Values.fuse.cacheDir }}
- name: cache-dir
mountPath: {{ .Values.fuse.cacheDir }}
{{- end }}
restartPolicy: Always
volumes:
- name: jfs-dir
hostPath:
path: {{ .Values.fuse.hostMountPath }}
type: DirectoryOrCreate
{{- if .Values.fuse.cacheDir }}
- name: cache-dir
hostPath:
path: {{ .Values.fuse.cacheDir }}
type: DirectoryOrCreate
{{- end }}
- name: jfs-root-dir
emptyDir: {}
- name: prepare
Expand All @@ -170,15 +160,15 @@ data:
prepare-subpath.sh: |
#!/bin/bash
{{- if and .Values.fuse.prepare.storageSecret .Values.fuse.prepare.bucketSecret }}
/usr/local/bin/juicefs format --storage=${STORAGE} --bucket=${BUCKET} --access-key=${ACCESS_KEY} --secret-key=${SECRET_KEY} ${META_URL} ${NAME}
{{- if and .Values.fuse.prepare.storage .Values.fuse.prepare.bucket }}
/usr/local/bin/juicefs format --storage={{ .Values.fuse.prepare.storage }} --bucket={{ .Values.fuse.prepare.bucket }} --access-key=${ACCESS_KEY} --secret-key=${SECRET_KEY} {{ .Values.fuse.prepare.metaurl }} {{ .Values.fuse.prepare.name }}
{{- else }}
/usr/local/bin/juicefs format ${META_URL} ${NAME} --no-update
/usr/local/bin/juicefs format {{ .Values.fuse.prepare.metaurl }} {{ .Values.fuse.prepare.name }} --no-update
{{- end }}
/usr/local/bin/juicefs mount -d ${META_URL} /mnt/jfs
if [ ! -d /mnt/jfs/{{ .Values.fuse.prepare.subPath }} ]; then
mkdir /mnt/jfs/{{ .Values.fuse.prepare.subPath }}
/usr/local/bin/juicefs mount -d {{ .Values.fuse.prepare.metaurl }} /mnt/jfs
if [ ! -d /mnt/jfs{{ .Values.fuse.prepare.subPath }} ]; then
mkdir /mnt/jfs{{ .Values.fuse.prepare.subPath }}
fi;
umount /mnt/jfs
Expand Down
9 changes: 5 additions & 4 deletions charts/juicefs/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ worker:

fuse:
prepare:
nameSecret: jfs-secret
name: jfs-secret
accesskeySecret: jfs-secret
secretkeySecret: jfs-secret
bucketSecret: jfs-secret
metaurlSecret: jfs-secret
storageSecret: jfs-secret
bucket: jfs-secret
metaurl: jfs-secret
storage: jfs-secret
subPath: /mnt/jfs
criticalPod: false
enabled: true
Expand All @@ -59,6 +59,7 @@ fuse:
dnsPolicy: ClusterFirstWithHostNet
# Mount path in the host
mountPath: /mnt/jfs
cacheDir: ""
metaUrl : ""
hostMountPath: /mnt/jfs
command: "/usr/local/bin/juicefs mount /mnt/jfs"
Expand Down
37 changes: 9 additions & 28 deletions docs/en/samples/juicefs_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ Before using JuiceFS, you need to provide parameters for metadata services (such

```shell
kubectl create secret generic jfs-secret \
--from-literal=name=pics \
--from-literal=metaurl=redis://192.168.169.168:6379/1 \
--from-literal=storage=minio \
--from-literal=bucket=http://192.168.169.169:9000/pics \
--from-literal=access-key=minioadmin \
--from-literal=secret-key=minioadmin
--from-literal=access-key=<accesskey> \
--from-literal=secret-key=<secretkey>
```

**Check Dataset to be created**
Expand All @@ -58,28 +54,13 @@ metadata:
name: jfsdemo
spec:
mounts:
- name: demo
- name: minio
mountPoint: "juicefs:///demo"
options:
metaurl: "<metaurl>"
bucket: "<bucket>"
storage: "minio"
encryptOptions:
- name: name
valueFrom:
secretKeyRef:
name: jfs-secret
key: name
- name: metaurl
valueFrom:
secretKeyRef:
name: jfs-secret
key: metaurl
- name: storage
valueFrom:
secretKeyRef:
name: jfs-secret
key: storage
- name: bucket
valueFrom:
secretKeyRef:
name: jfs-secret
key: bucket
- name: access-key
valueFrom:
secretKeyRef:
Expand All @@ -96,7 +77,7 @@ EOF
> Note: demo refers to the Subpath of JuiceFS, which is the directory of the JuiceFS file system where users store data in.
> Attention:Only name and metaurl are required. If the juicefs has been formatted, you only need to fill in the name and metaurl.
Since JuiceFS uses local cache, the corresponding Dataset supports only one mount, and JuiceFS does not have UFS, name/path represents the subdirectory that needs to be mounted, and it will be mounted as the root directory into the container.
Since JuiceFS uses local cache, the corresponding Dataset supports only one mount, and JuiceFS does not have UFS, you can specify subdirectory in mountpoint ("juicefs:///" represents root directory), and it will be mounted as the root directory into the container.

**Create Dataset**
```shell
Expand Down
37 changes: 9 additions & 28 deletions docs/zh/samples/juicefs_runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ $ cd <any-path>/juicefs

```shell
kubectl create secret generic jfs-secret \
--from-literal=name=pics \
--from-literal=metaurl=redis://192.168.169.168:6379/1 \
--from-literal=storage=minio \
--from-literal=bucket=http://192.168.169.169:9000/pics \
--from-literal=access-key=minioadmin \
--from-literal=secret-key=minioadmin
--from-literal=access-key=<accesskey> \
--from-literal=secret-key=<secretkey>
```

**查看待创建的 Dataset 资源对象**
Expand All @@ -56,28 +52,13 @@ metadata:
name: jfsdemo
spec:
mounts:
- name: demo
- name: minio
mountPoint: "juicefs:///demo"
options:
metaurl: "<metaurl>"
bucket: "<bucket>"
storage: "minio"
encryptOptions:
- name: name
valueFrom:
secretKeyRef:
name: jfs-secret
key: name
- name: metaurl
valueFrom:
secretKeyRef:
name: jfs-secret
key: metaurl
- name: storage
valueFrom:
secretKeyRef:
name: jfs-secret
key: storage
- name: bucket
valueFrom:
secretKeyRef:
name: jfs-secret
key: bucket
- name: access-key
valueFrom:
secretKeyRef:
Expand All @@ -94,7 +75,7 @@ EOF
> 说明:demo 指的是 JuiceFS 的 Subpath,是用户在 JuiceFS 文件系统中存储数据的目录
> 注意:只有 name 和 metaurl 为必填项,若 juicefs 已经 format 过,只需要填 name 和 metaurl 即可。
由于 JuiceFS 采用的是本地缓存,对应的 Dataset 只支持一个 mount,且 JuiceFS 没有 UFS,name/path 代表需要挂载的子目录,会作为根目录挂载到容器内。
由于 JuiceFS 采用的是本地缓存,对应的 Dataset 只支持一个 mount,且 JuiceFS 没有 UFS,mountpoint 中可以指定需要挂载的子目录 ("juicefs:///" 为根路径),会作为根目录挂载到容器内。

**创建 Dataset 资源对象**
```shell
Expand Down
11 changes: 11 additions & 0 deletions pkg/ddc/base/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ func GetRuntimeInfo(client client.Client, name, namespace string) (RuntimeInfoIn
}
runtimeInfo.SetupFuseDeployMode(goosefsRuntime.Spec.Fuse.Global, goosefsRuntime.Spec.Fuse.NodeSelector)
return runtimeInfo, nil
case common.JuiceFSRuntime:
runtimeInfo, err := BuildRuntimeInfo(name, namespace, common.JuiceFSRuntime, datav1alpha1.TieredStore{})
if err != nil {
return runtimeInfo, err
}
juicefsRuntime, err := utils.GetJuiceFSRuntime(client, name, namespace)
if err != nil {
return runtimeInfo, err
}
runtimeInfo.SetupFuseDeployMode(juicefsRuntime.Spec.Fuse.Global, juicefsRuntime.Spec.Fuse.NodeSelector)
return runtimeInfo, nil
default:
runtimeInfo, err := BuildRuntimeInfo(name, namespace, runtimeType, datav1alpha1.TieredStore{})
return runtimeInfo, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/ddc/juicefs/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ const (

METADATA_SYNC_NOT_DONE_MSG = "[Calculating]"
CHECK_METADATA_SYNC_DONE_TIMEOUT_MILLISEC = 500

DefaultCacheDir = "/var/jfsCache"
)
1 change: 1 addition & 0 deletions pkg/ddc/juicefs/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type JuiceFSEngine struct {
client.Client
//When reaching this gracefulShutdownLimits, the system is forced to clean up.
gracefulShutdownLimits int32
MetadataSyncDoneCh chan MetadataSyncResult
runtimeInfo base.RuntimeInfoInterface
UnitTest bool
retryShutdown int32
Expand Down
19 changes: 19 additions & 0 deletions pkg/ddc/juicefs/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package juicefs

import (
"fmt"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubectl"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
Expand Down Expand Up @@ -59,6 +61,13 @@ func (j *JuiceFSEngine) setupMasterInternal() (err error) {

// generate juicefs struct
func (j *JuiceFSEngine) generateJuicefsValueFile(runtime *datav1alpha1.JuiceFSRuntime) (valueFileName string, err error) {
//0. Check if the configmap exists
err = kubeclient.DeleteConfigMap(j.Client, j.getConfigmapName(), j.namespace)
if err != nil {
j.Log.Error(err, "Failed to clean value files")
return
}

// labelName := common.LabelAnnotationStorageCapacityPrefix + e.runtimeType + "-" + e.name
// configmapName := e.name + "-" + e.runtimeType + "-values"
//1. Transform the runtime to value
Expand Down Expand Up @@ -89,5 +98,15 @@ func (j *JuiceFSEngine) generateJuicefsValueFile(runtime *datav1alpha1.JuiceFSRu
return
}

//3. Save the configfile into configmap
err = kubectl.CreateConfigMapFromFile(j.getConfigmapName(), "data", valueFileName, j.namespace)
if err != nil {
return
}

return valueFileName, err
}

func (j *JuiceFSEngine) getConfigmapName() string {
return j.name + "-" + j.runtimeType + "-values"
}
Loading

0 comments on commit a80b0a4

Please sign in to comment.