Skip to content

Commit

Permalink
support juicefs cloud service (#1683)
Browse files Browse the repository at this point in the history
* support juicefs cloud service

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

* fix golangci-lint

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

* add dataload for enterprise

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

* fix test

Signed-off-by: zwwhdls <[email protected]>
  • Loading branch information
zwwhdls authored Mar 31, 2022
1 parent bf3b453 commit ed486d8
Show file tree
Hide file tree
Showing 17 changed files with 729 additions and 94 deletions.
7 changes: 6 additions & 1 deletion charts/fluid-dataloader/juicefs/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ data:
local pod="${podNames[i]}"
echo -e "juicefs warmup on $pod $targetPath starts"
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT juicefs warmup $targetPath
if [ $EDITION == 'community' ]
then
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT /usr/local/bin/juicefs warmup $targetPath
else
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT /usr/bin/juicefs warmup $targetPath
fi
echo -e "juicefs warmup on $pod $targetPath ends"
done
}
Expand Down
17 changes: 4 additions & 13 deletions charts/fluid-dataloader/juicefs/templates/dataloader.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ spec:
- name: TIMEOUT
value: {{ $val | quote }}
{{- end }}
{{- if eq $key "edition" }}
- name: EDITION
value: {{ $val | quote }}
{{- end }}
{{- end }}
- name: DATA_PATH
value: {{ $targetPaths | quote }}
Expand Down Expand Up @@ -107,12 +111,6 @@ spec:
{{- end }}
{{- end }}
name: cachedir
{{- range $key, $val := .Values.dataloader.options }}
{{- if eq $key "mountpath" }}
- mountPath: {{ $val | quote }}
{{- end }}
{{- end }}
name: mountpath1
volumes:
- name: data-load-script
configMap:
Expand All @@ -135,10 +133,3 @@ spec:
path: {{ $val | quote }}
{{- end }}
{{- end }}
- name: mountpath1
{{- range $key, $val := .Values.dataloader.options }}
{{- if eq $key "mountpath" }}
hostPath:
path: {{ $val | quote }}
{{- end }}
{{- end }}
18 changes: 12 additions & 6 deletions charts/juicefs/templates/fuse/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ spec:
name: {{ .Values.fuse.secretkeySecret }}
key: secret-key
{{- end }}
{{- if .Values.fuse.tokenSecret }}
- name: TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.tokenSecret }}
key: token
{{- end }}
readinessProbe:
exec:
command:
Expand Down Expand Up @@ -130,26 +137,25 @@ spec:
{{- end }}
- name: script
configMap:
name: {{ template "juicefs.fullname" . }}-script
name: {{ template "juicefs.fullname" . }}-fuse-script
defaultMode: 0755
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "juicefs.fullname" . }}-script
name: {{ template "juicefs.fullname" . }}-fuse-script
labels:
app: {{ template "juicefs.name" . }}
chart: {{ template "juicefs.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: juicefs-fuse
data:
script.sh: |
#!/bin/bash
{{- if and .Values.fuse.storage .Values.fuse.bucket .Values.fuse.accesskeySecret .Values.fuse.secretkeySecret }}
/usr/local/bin/juicefs format --storage={{ .Values.fuse.storage }} --bucket={{ .Values.fuse.bucket }} --access-key=${ACCESS_KEY} --secret-key=${SECRET_KEY} ${METAURL} {{ .Values.fuse.name }}
{{- else }}
/usr/local/bin/juicefs format ${METAURL} {{ .Values.fuse.name }} --no-update
{{- if .Values.fuse.formatCmd }}
{{ .Values.fuse.formatCmd }}
{{- end }}
{{ .Values.fuse.command }}
Expand Down
29 changes: 28 additions & 1 deletion charts/juicefs/templates/worker/statefuleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ spec:
name: {{ .Values.fuse.secretkeySecret }}
key: secret-key
{{- end }}
{{- if .Values.fuse.tokenSecret }}
- name: TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.fuse.tokenSecret }}
key: token
{{- end }}
livenessProbe:
exec:
command:
Expand Down Expand Up @@ -124,5 +131,25 @@ spec:
{{- end }}
- name: script
configMap:
name: {{ template "juicefs.fullname" . }}-script
name: {{ template "juicefs.fullname" . }}-worker-script
defaultMode: 0755
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "juicefs.fullname" . }}-worker-script
labels:
app: {{ template "juicefs.name" . }}
chart: {{ template "juicefs.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
role: juicefs-worker
data:
script.sh: |
#!/bin/bash
{{- if .Values.fuse.formatCmd }}
{{ .Values.fuse.formatCmd }}
{{- end }}
{{ .Values.worker.command }}
4 changes: 4 additions & 0 deletions charts/juicefs/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This should not be modified in the usual case.
fullnameOverride: juicefs
edition: community

##
## Example:
Expand Down Expand Up @@ -29,6 +30,7 @@ worker:
cacheDir: ""
ports: []
envs: []
command: ""
resources:
requests:
# cpu: "0.5"
Expand All @@ -48,6 +50,8 @@ fuse:
bucket: ""
metaurlSecret: ""
storage: ""
tokenSecret: ""
formatCmd : ""
subPath: ""
criticalPod: false
enabled: true
Expand Down
5 changes: 4 additions & 1 deletion pkg/common/juicefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const (

DefaultJuiceFSRuntimeImage = "registry.cn-hangzhou.aliyuncs.com/juicefs/juicefs-fuse:v1.0.0-beta2"

JuiceFSMountPath = "/bin/mount.juicefs"
JuiceFSCeMountPath = "/bin/mount.juicefs"
JuiceFSMountPath = "/sbin/mount.juicefs"
JuiceCeCliPath = "/usr/local/bin/juicefs"
JuiceCliPath = "/usr/bin/juicefs"

JuiceFSFuseContainer = "juicefs-fuse"

Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/juicefs/cacheinfo_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func parseCacheInfoFromConfigMap(configMap *v1.ConfigMap) (cacheinfo map[string]
}
configmapinfo[CacheDir] = value.Fuse.CacheDir
configmapinfo[MountPath] = value.Fuse.MountPath
configmapinfo[Edition] = value.Edition
}
return configmapinfo, nil
}
4 changes: 2 additions & 2 deletions pkg/ddc/juicefs/cacheinfo_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGetCacheInfoFromConfigmap(t *testing.T) {
runtimeObjs = append(runtimeObjs, configMap)
runtimeObjs = append(runtimeObjs, dataSet.DeepCopy())
fakeClient := fake.NewFakeClientWithScheme(testScheme, runtimeObjs...)
wantCacheInfo := map[string]string{"cachedir": "/tmp/jfs-cache", "mountpath": "/runtime-mnt/juicefs/fluid/test-dataset/juicefs-fuse"}
wantCacheInfo := map[string]string{"cachedir": "/tmp/jfs-cache", "mountpath": "/runtime-mnt/juicefs/fluid/test-dataset/juicefs-fuse", "edition": "community"}
cacheinfo, err := GetCacheInfoFromConfigmap(fakeClient, dataSet.Name, dataSet.Namespace)
if err != nil {
t.Errorf("GetCacheInfoFromConfigmap failed.")
Expand Down Expand Up @@ -84,7 +84,7 @@ func Test_parseCacheInfoFromConfigMap(t *testing.T) {
"data": valuesConfigMapData,
},
}},
wantCacheInfo: map[string]string{"cachedir": "/tmp/jfs-cache", "mountpath": "/runtime-mnt/juicefs/fluid/test-dataset/juicefs-fuse"},
wantCacheInfo: map[string]string{"cachedir": "/tmp/jfs-cache", "mountpath": "/runtime-mnt/juicefs/fluid/test-dataset/juicefs-fuse", "edition": "community"},
wantErr: false,
},
{
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 @@ -38,8 +38,10 @@ const (
JuiceMetaUrl = "metaurl"
JuiceAccessKey = "access-key"
JuiceSecretKey = "secret-key"
JuiceToken = "token"

CacheDir = "cachedir"
MountPath = "mountpath"
Edition = "edition"
DefaultDataLoadTimeout = "30m"
)
41 changes: 23 additions & 18 deletions pkg/ddc/juicefs/data_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

// CreateDataLoadJob creates the job to load data
func (e *JuiceFSEngine) CreateDataLoadJob(ctx cruntime.ReconcileRequestContext, targetDataload datav1alpha1.DataLoad) (err error) {
func (j *JuiceFSEngine) CreateDataLoadJob(ctx cruntime.ReconcileRequestContext, targetDataload datav1alpha1.DataLoad) (err error) {
log := ctx.Log.WithName("createDataLoadJob")

// 1. Check if the helm release already exists
Expand All @@ -48,7 +48,7 @@ func (e *JuiceFSEngine) CreateDataLoadJob(ctx cruntime.ReconcileRequestContext,
// 2. install the helm chart if not exists
if !existed {
log.Info("DataLoad job helm chart not installed yet, will install")
valueFileName, err := e.generateDataLoadValueFile(ctx, targetDataload)
valueFileName, err := j.generateDataLoadValueFile(ctx, targetDataload)
if err != nil {
log.Error(err, "failed to generate dataload chart's value file")
return err
Expand All @@ -67,12 +67,12 @@ func (e *JuiceFSEngine) CreateDataLoadJob(ctx cruntime.ReconcileRequestContext,

// generateDataLoadValueFile builds a DataLoadValue by extracted specifications from the given DataLoad, and
// marshals the DataLoadValue to a temporary yaml file where stores values that'll be used by fluid dataloader helm chart
func (e *JuiceFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestContext, dataload datav1alpha1.DataLoad) (valueFileName string, err error) {
func (j *JuiceFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestContext, dataload datav1alpha1.DataLoad) (valueFileName string, err error) {
targetDataset, err := utils.GetDataset(r.Client, dataload.Spec.Dataset.Name, dataload.Spec.Dataset.Namespace)
if err != nil {
return "", err
}
e.Log.Info("target dataset", "dataset", targetDataset)
j.Log.Info("target dataset", "dataset", targetDataset)

imageName, imageTag := docker.GetWorkerImage(r.Client, dataload.Spec.Dataset.Name, "juicefs", dataload.Spec.Dataset.Namespace)

Expand Down Expand Up @@ -121,25 +121,30 @@ func (e *JuiceFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestCon
options[key] = value
}
}
cacheinfo, err := GetCacheInfoFromConfigmap(e.Client, dataload.Spec.Dataset.Name, dataload.Spec.Dataset.Namespace)
cacheinfo, err := GetCacheInfoFromConfigmap(j.Client, dataload.Spec.Dataset.Name, dataload.Spec.Dataset.Namespace)
if err != nil {
return
}
for key, value := range cacheinfo {
options[key] = value
}

stsName := e.getWorkerName()
pods, err := e.GetRunningPodsOfStatefulSet(stsName, e.namespace)
stsName := j.getWorkerName()
pods, err := j.GetRunningPodsOfStatefulSet(stsName, j.namespace)
if err != nil || len(pods) == 0 {
return
}
podNames := []string{}
for _, pod := range pods {
podNames = append(podNames, pod.Name)
}
options["podNames"] = strings.Join(podNames, ":")
options["runtimeName"] = e.name
if cacheinfo[Edition] == "community" {
options["podNames"] = strings.Join(podNames, ":")
} else {
options["podNames"] = podNames[0]
}
options["edition"] = cacheinfo[Edition]
options["runtimeName"] = j.name
if _, ok := options["timeout"]; !ok {
options["timeout"] = DefaultDataLoadTimeout
}
Expand All @@ -154,7 +159,7 @@ func (e *JuiceFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestCon
if err != nil {
return
}
e.Log.Info("dataload value", "value", string(data))
j.Log.Info("dataload value", "value", string(data))

valueFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s-%s-loader-values.yaml", dataload.Namespace, dataload.Name))
if err != nil {
Expand All @@ -167,18 +172,18 @@ func (e *JuiceFSEngine) generateDataLoadValueFile(r cruntime.ReconcileRequestCon
return valueFile.Name(), nil
}

func (e *JuiceFSEngine) CheckRuntimeReady() (ready bool) {
stsName := e.getWorkerName()
pods, err := e.GetRunningPodsOfStatefulSet(stsName, e.namespace)
func (j *JuiceFSEngine) CheckRuntimeReady() (ready bool) {
stsName := j.getWorkerName()
pods, err := j.GetRunningPodsOfStatefulSet(stsName, j.namespace)
if err != nil || len(pods) == 0 {
return false
}
return true
}

func (e *JuiceFSEngine) CheckExistenceOfPath(targetDataload datav1alpha1.DataLoad) (notExist bool, err error) {
func (j *JuiceFSEngine) CheckExistenceOfPath(targetDataload datav1alpha1.DataLoad) (notExist bool, err error) {
// get mount path
cacheinfo, err := GetCacheInfoFromConfigmap(e.Client, targetDataload.Spec.Dataset.Name, targetDataload.Spec.Dataset.Namespace)
cacheinfo, err := GetCacheInfoFromConfigmap(j.Client, targetDataload.Spec.Dataset.Name, targetDataload.Spec.Dataset.Namespace)
if err != nil {
return
}
Expand All @@ -188,15 +193,15 @@ func (e *JuiceFSEngine) CheckExistenceOfPath(targetDataload datav1alpha1.DataLoa
}

// get worker pod
stsName := e.getWorkerName()
pods, err := e.GetRunningPodsOfStatefulSet(stsName, e.namespace)
stsName := j.getWorkerName()
pods, err := j.GetRunningPodsOfStatefulSet(stsName, j.namespace)
if err != nil || len(pods) == 0 {
return true, err
}

// check path exist
pod := pods[0]
fileUtils := operations.NewJuiceFileUtils(pod.Name, common.JuiceFSWorkerContainer, e.namespace, e.Log)
fileUtils := operations.NewJuiceFileUtils(pod.Name, common.JuiceFSWorkerContainer, j.namespace, j.Log)
for _, target := range targetDataload.Spec.Target {
targetPath := filepath.Join(mountPath, target.Path)
isExist, err := fileUtils.IsExist(targetPath)
Expand Down
1 change: 1 addition & 0 deletions pkg/ddc/juicefs/data_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

var valuesConfigMapData = `
fullnameOverride: test-dataset
edition: community
image: juicedata/juicefs-csi-driver
imageTag: v0.11.0
imagePullPolicy: IfNotPresent
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/juicefs/master_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (j *JuiceFSEngine) generateJuicefsValueFile(runtime *datav1alpha1.JuiceFSRu
}

valueFileName = valueFile.Name()
j.Log.V(1).Info("Save the values file", "valueFile", valueFileName)
j.Log.Info("Save the values file", "valueFile", valueFileName)

err = ioutil.WriteFile(valueFileName, data, 0400)
if err != nil {
Expand Down
Loading

0 comments on commit ed486d8

Please sign in to comment.