Skip to content

Commit aba6d90

Browse files
authored
juicefs: support extra options in dataload (#4760)
* juicefs: support extra options in dataload Signed-off-by: zwwhdls <zww@hdls.me> * docs: add docs for options in dataload Signed-off-by: zwwhdls <zww@hdls.me> * fix unittest Signed-off-by: zwwhdls <zww@hdls.me> --------- Signed-off-by: zwwhdls <zww@hdls.me>
1 parent dbb2e26 commit aba6d90

6 files changed

Lines changed: 40 additions & 19 deletions

File tree

charts/fluid-dataloader/juicefs/templates/configmap.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ data:
3838
local pod="${podNames[i]}"
3939
4040
echo -e "juicefs warmup on $pod $targetPath starts"
41-
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT /usr/local/bin/juicefs warmup $targetPath
41+
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT /usr/local/bin/juicefs warmup $targetPath $OPTION
4242
echo -e "juicefs warmup on $pod $targetPath ends"
4343
done
4444
fi
@@ -47,7 +47,7 @@ data:
4747
then
4848
echo -e "juicefs warmup $targetPath starts"
4949
local pod="${podNames[0]}"
50-
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT /usr/bin/juicefs warmup $targetPath
50+
/usr/local/bin/kubectl -n $ns exec -it $pod -- timeout $TIMEOUT /usr/bin/juicefs warmup $targetPath $OPTION
5151
echo -e "juicefs warmup $targetPath ends"
5252
fi
5353
}

charts/fluid-dataloader/juicefs/templates/cronjob.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ spec:
111111
- name: TIMEOUT
112112
value: {{ $val | quote }}
113113
{{- end }}
114+
{{- if eq $key "option" }}
115+
- name: OPTION
116+
value: {{ $val | quote }}
117+
{{- end }}
114118
{{- if eq $key "edition" }}
115119
- name: EDITION
116120
value: {{ $val | quote }}

charts/fluid-dataloader/juicefs/templates/job.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ spec:
124124
- name: TIMEOUT
125125
value: {{ $val | quote }}
126126
{{- end }}
127+
{{- if eq $key "option" }}
128+
- name: OPTION
129+
value: {{ $val | quote }}
130+
{{- end }}
127131
{{- if eq $key "edition" }}
128132
- name: EDITION
129133
value: {{ $val | quote }}

docs/zh/samples/juicefs/juicefs_data_accelerate.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ spec:
2121
namespace: default
2222
target:
2323
- path: /dir1
24+
options:
25+
threads: "50"
2426
```
2527
2628
其中:
2729
- `spec.dataset.name`:指定要加速数据访问的 Dataset 名称;
2830
- `spec.dataset.namespce`:指定要加速数据访问的 Dataset 的 namespace;
2931
- `spec.target.path`:指定要加速数据访问的数据路径,可以是目录或文件;target 是列表,可以填多个 path。
32+
- `spec.options`:指定缓存加速的参数,可用参数可参考 [JuiceFS 的缓存加速文档](https://juicefs.com/docs/zh/community/command_reference#warmup),注意 key 和 value 均为字符串类型。

pkg/ddc/juicefs/data_load.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@ func (j *JuiceFSEngine) genDataLoadValue(image string, cacheinfo map[string]stri
179179
dataloadInfo.TargetPaths = targetPaths
180180

181181
options := map[string]string{}
182-
// resolve spec options
183-
if dataload.Spec.Options != nil {
184-
for key, value := range dataload.Spec.Options {
185-
options[key] = value
186-
}
187-
}
188182

189183
for key, value := range cacheinfo {
190184
options[key] = value
@@ -201,9 +195,21 @@ func (j *JuiceFSEngine) genDataLoadValue(image string, cacheinfo map[string]stri
201195
}
202196
options["edition"] = cacheinfo[Edition]
203197
options["runtimeName"] = j.name
204-
if _, ok := options["timeout"]; !ok {
205-
options["timeout"] = DefaultDataLoadTimeout
198+
timeout := dataload.Spec.Options["timeout"]
199+
delete(dataload.Spec.Options, "timeout")
200+
if timeout == "" {
201+
timeout = DefaultDataLoadTimeout
202+
}
203+
warmupOtions := []string{}
204+
for k, v := range dataload.Spec.Options {
205+
if v != "" {
206+
warmupOtions = append(warmupOtions, fmt.Sprintf("--%s=%s", k, v))
207+
} else {
208+
warmupOtions = append(warmupOtions, fmt.Sprintf("--%s", k))
209+
}
206210
}
211+
options["option"] = strings.Join(warmupOtions, " ")
212+
options["timeout"] = timeout
207213

208214
dataloadInfo.Options = options
209215

pkg/ddc/juicefs/data_load_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package juicefs
1818

1919
import (
20+
"encoding/json"
2021
"os"
2122
"path/filepath"
2223
"reflect"
@@ -25,14 +26,15 @@ import (
2526

2627
"github.com/fluid-cloudnative/fluid/pkg/common"
2728

28-
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
29-
cdataload "github.com/fluid-cloudnative/fluid/pkg/dataload"
30-
cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime"
31-
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
3229
appsv1 "k8s.io/api/apps/v1"
3330
v1 "k8s.io/api/core/v1"
3431
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3532
"k8s.io/apimachinery/pkg/runtime"
33+
34+
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
35+
cdataload "github.com/fluid-cloudnative/fluid/pkg/dataload"
36+
cruntime "github.com/fluid-cloudnative/fluid/pkg/runtime"
37+
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
3638
)
3739

3840
var valuesConfigMapData = `
@@ -561,7 +563,7 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) {
561563
ImagePullSecrets: []v1.LocalObjectReference{},
562564
Options: map[string]string{
563565
// dataload spec options
564-
"dl-opts-k-1": "dl-opts-v-1",
566+
"option": "--dl-opts-k-1=dl-opts-v-1",
565567
// cache info
566568
Edition: CommunityEdition,
567569
"cache-info-k1": "cache-info-v1",
@@ -728,7 +730,7 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) {
728730
},
729731
Options: map[string]string{
730732
// dataload spec options
731-
"dl-opts-k-1": "dl-opts-v-1",
733+
"option": "--dl-opts-k-1=dl-opts-v-1",
732734
// cache info
733735
Edition: CommunityEdition,
734736
"cache-info-k1": "cache-info-v1",
@@ -829,7 +831,7 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) {
829831
},
830832
Options: map[string]string{
831833
// dataload spec options
832-
"dl-opts-k-1": "dl-opts-v-1",
834+
"option": "--dl-opts-k-1=dl-opts-v-1",
833835
// cache info
834836
Edition: CommunityEdition,
835837
"cache-info-k1": "cache-info-v1",
@@ -938,7 +940,7 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) {
938940
},
939941
Options: map[string]string{
940942
// dataload spec options
941-
"dl-opts-k-1": "dl-opts-v-1",
943+
"option": "--dl-opts-k-1=dl-opts-v-1",
942944
// cache info
943945
Edition: CommunityEdition,
944946
"cache-info-k1": "cache-info-v1",
@@ -961,7 +963,9 @@ func TestJuiceFSEngine_genDataLoadValue(t *testing.T) {
961963
}
962964
got, _ := engine.genDataLoadValue(item.image, item.cacheInfo, item.pods, item.targetDataset, item.dataload)
963965
if !reflect.DeepEqual(got, item.want) {
964-
t.Errorf("case %s, got %v,want:%v", k, got, item.want)
966+
gotJson, _ := json.Marshal(got)
967+
wantJson, _ := json.Marshal(item.want)
968+
t.Errorf("case %s, got %v\nwant:%v", k, string(gotJson), string(wantJson))
965969
}
966970
}
967971
}

0 commit comments

Comments
 (0)