Skip to content

Commit 6f45844

Browse files
committed
add unit test for fuse eager/lazy mode
Signed-off-by: EvanCley <caoyifan1a2b@163.com>
1 parent 51ff84e commit 6f45844

File tree

13 files changed

+1342
-15
lines changed

13 files changed

+1342
-15
lines changed

pkg/ctrl/affinity_test.go

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ func TestBuildWorkersAffinity(t *testing.T) {
9494
},
9595
},
9696
},
97+
{
98+
Weight: 100,
99+
Preference: v1.NodeSelectorTerm{
100+
MatchExpressions: []v1.NodeSelectorRequirement{
101+
{
102+
Key: "nodeA",
103+
Operator: v1.NodeSelectorOpIn,
104+
Values: []string{"true"},
105+
},
106+
},
107+
},
108+
},
97109
},
98110
},
99111
},
@@ -166,6 +178,18 @@ func TestBuildWorkersAffinity(t *testing.T) {
166178
},
167179
},
168180
},
181+
{
182+
Weight: 100,
183+
Preference: v1.NodeSelectorTerm{
184+
MatchExpressions: []v1.NodeSelectorRequirement{
185+
{
186+
Key: "nodeA",
187+
Operator: v1.NodeSelectorOpIn,
188+
Values: []string{"true"},
189+
},
190+
},
191+
},
192+
},
169193
},
170194
},
171195
},
@@ -248,6 +272,83 @@ func TestBuildWorkersAffinity(t *testing.T) {
248272
},
249273
},
250274
},
275+
{
276+
Weight: 100,
277+
Preference: v1.NodeSelectorTerm{
278+
MatchExpressions: []v1.NodeSelectorRequirement{
279+
{
280+
Key: "nodeA",
281+
Operator: v1.NodeSelectorOpIn,
282+
Values: []string{"true"},
283+
},
284+
},
285+
},
286+
},
287+
},
288+
},
289+
},
290+
},
291+
}, {
292+
name: "fuse-eager-mode-with-fuse-nodeSelector",
293+
fields: fields{
294+
dataset: &datav1alpha1.Dataset{
295+
ObjectMeta: metav1.ObjectMeta{
296+
Name: "test4",
297+
Namespace: "big-data",
298+
},
299+
Spec: datav1alpha1.DatasetSpec{},
300+
},
301+
worker: &appsv1.StatefulSet{
302+
ObjectMeta: metav1.ObjectMeta{
303+
Name: "test4-thin-worker",
304+
Namespace: "big-data",
305+
},
306+
Spec: appsv1.StatefulSetSpec{
307+
Replicas: ptr.To[int32](1),
308+
},
309+
},
310+
want: &v1.Affinity{
311+
PodAntiAffinity: &v1.PodAntiAffinity{
312+
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
313+
{
314+
LabelSelector: &metav1.LabelSelector{
315+
MatchExpressions: []metav1.LabelSelectorRequirement{
316+
{
317+
Key: "fluid.io/dataset",
318+
Operator: metav1.LabelSelectorOpExists,
319+
},
320+
},
321+
},
322+
TopologyKey: "kubernetes.io/hostname",
323+
},
324+
},
325+
},
326+
NodeAffinity: &v1.NodeAffinity{
327+
PreferredDuringSchedulingIgnoredDuringExecution: []v1.PreferredSchedulingTerm{
328+
{
329+
Weight: 100,
330+
Preference: v1.NodeSelectorTerm{
331+
MatchExpressions: []v1.NodeSelectorRequirement{
332+
{
333+
Key: "fluid.io/f-big-data-test4",
334+
Operator: v1.NodeSelectorOpIn,
335+
Values: []string{"true"},
336+
},
337+
},
338+
},
339+
},
340+
{
341+
Weight: 100,
342+
Preference: v1.NodeSelectorTerm{
343+
MatchExpressions: []v1.NodeSelectorRequirement{
344+
{
345+
Key: "nodeA",
346+
Operator: v1.NodeSelectorOpIn,
347+
Values: []string{"true"},
348+
},
349+
},
350+
},
351+
},
251352
},
252353
},
253354
},
@@ -265,10 +366,12 @@ func TestBuildWorkersAffinity(t *testing.T) {
265366
runtimeObjs = append(runtimeObjs, tt.fields.dataset)
266367
runtimeObjs = append(runtimeObjs, tt.fields.worker)
267368
mockClient := fake.NewFakeClientWithScheme(s, runtimeObjs...)
268-
runtimeInfo, err := base.BuildRuntimeInfo(tt.fields.dataset.Name, tt.fields.dataset.Namespace, common.JindoRuntime)
369+
runtimeInfo, err := base.BuildRuntimeInfo(tt.fields.dataset.Name, tt.fields.dataset.Namespace, common.ThinRuntime)
269370
if err != nil {
270371
t.Errorf("testcase %s failed due to %v", tt.name, err)
271372
}
373+
runtimeInfo.SetFuseLaunchMode(datav1alpha1.EagerMode)
374+
runtimeInfo.SetFuseNodeSelector(map[string]string{"nodeA": "true"})
272375
h := BuildHelper(runtimeInfo, mockClient, fake.NullLogger())
273376

274377
want := tt.fields.want

pkg/ctrl/fuse_test.go

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ func TestCleanUpFuse(t *testing.T) {
303303
log logr.Logger
304304
runtimeType string
305305
nodeInputs []*corev1.Node
306+
fuseLaunchMode datav1alpha1.FuseLaunchMode
306307
}{
307308
{
308309
wantedCount: 1,
@@ -324,8 +325,9 @@ func TestCleanUpFuse(t *testing.T) {
324325
"node-select": "true",
325326
},
326327
},
327-
log: fake.NullLogger(),
328-
runtimeType: "jindo",
328+
log: fake.NullLogger(),
329+
runtimeType: "jindo",
330+
fuseLaunchMode: datav1alpha1.LazyMode,
329331
nodeInputs: []*corev1.Node{
330332
{
331333
ObjectMeta: metav1.ObjectMeta{
@@ -378,8 +380,9 @@ func TestCleanUpFuse(t *testing.T) {
378380
"node-select": "true",
379381
},
380382
},
381-
log: fake.NullLogger(),
382-
runtimeType: "alluxio",
383+
log: fake.NullLogger(),
384+
runtimeType: "alluxio",
385+
fuseLaunchMode: datav1alpha1.LazyMode,
383386
nodeInputs: []*corev1.Node{
384387
{
385388
ObjectMeta: metav1.ObjectMeta{
@@ -434,8 +437,9 @@ func TestCleanUpFuse(t *testing.T) {
434437
"node-select": "true",
435438
},
436439
},
437-
log: fake.NullLogger(),
438-
runtimeType: "goosefs",
440+
log: fake.NullLogger(),
441+
runtimeType: "goosefs",
442+
fuseLaunchMode: datav1alpha1.LazyMode,
439443
nodeInputs: []*corev1.Node{
440444
{
441445
ObjectMeta: metav1.ObjectMeta{
@@ -469,6 +473,63 @@ func TestCleanUpFuse(t *testing.T) {
469473
},
470474
},
471475
},
476+
{
477+
wantedCount: 0,
478+
name: "hadoop",
479+
namespace: "fluid",
480+
wantedNodeLabels: map[string]map[string]string{
481+
"no-fuse": {},
482+
"multiple-fuse": {
483+
"fluid.io/f-fluid-spark": "true",
484+
"node-select": "true",
485+
"fluid.io/f-fluid-hadoop": "true",
486+
"fluid.io/s-fluid-hadoop": "true",
487+
"fluid.io/s-h-juicefs-d-fluid-hadoop": "5B",
488+
"fluid.io/s-h-juicefs-m-fluid-hadoop": "1B",
489+
"fluid.io/s-h-juicefs-t-fluid-hadoop": "6B",
490+
},
491+
"fuse": {
492+
"fluid.io/dataset-num": "1",
493+
"fluid.io/f-fluid-spark": "true",
494+
"node-select": "true",
495+
},
496+
},
497+
log: fake.NullLogger(),
498+
runtimeType: "juicefs",
499+
fuseLaunchMode: datav1alpha1.EagerMode,
500+
nodeInputs: []*corev1.Node{
501+
{
502+
ObjectMeta: metav1.ObjectMeta{
503+
Name: "no-fuse",
504+
Labels: map[string]string{},
505+
},
506+
},
507+
{
508+
ObjectMeta: metav1.ObjectMeta{
509+
Name: "multiple-fuse",
510+
Labels: map[string]string{
511+
"fluid.io/f-fluid-spark": "true",
512+
"node-select": "true",
513+
"fluid.io/f-fluid-hadoop": "true",
514+
"fluid.io/s-fluid-hadoop": "true",
515+
"fluid.io/s-h-juicefs-d-fluid-hadoop": "5B",
516+
"fluid.io/s-h-juicefs-m-fluid-hadoop": "1B",
517+
"fluid.io/s-h-juicefs-t-fluid-hadoop": "6B",
518+
},
519+
},
520+
},
521+
{
522+
ObjectMeta: metav1.ObjectMeta{
523+
Name: "fuse",
524+
Labels: map[string]string{
525+
"fluid.io/dataset-num": "1",
526+
"fluid.io/f-fluid-spark": "true",
527+
"node-select": "true",
528+
},
529+
},
530+
},
531+
},
532+
},
472533
}
473534
for _, test := range testCase {
474535

@@ -488,6 +549,7 @@ func TestCleanUpFuse(t *testing.T) {
488549
if err != nil {
489550
t.Errorf("build runtime info error %v", err)
490551
}
552+
runtimeInfo.SetFuseLaunchMode(test.fuseLaunchMode)
491553
h := &Helper{
492554
runtimeInfo: runtimeInfo,
493555
client: fakeClient,

pkg/ddc/alluxio/transform_fuse_test.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2626
"github.com/fluid-cloudnative/fluid/pkg/ddc/base"
27+
"github.com/fluid-cloudnative/fluid/pkg/utils"
2728
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
2829
)
2930

@@ -270,3 +271,112 @@ func TestTransformFuseWithNetwork(t *testing.T) {
270271

271272
}
272273
}
274+
275+
func TestTransformFuseWithLaunchMode(t *testing.T) {
276+
testCases := map[string]struct {
277+
runtime *datav1alpha1.AlluxioRuntime
278+
wantValue *Alluxio
279+
}{
280+
"test fuse launch mode case 1": {
281+
runtime: &datav1alpha1.AlluxioRuntime{
282+
ObjectMeta: metav1.ObjectMeta{
283+
Name: "hbase",
284+
Namespace: "fluid",
285+
},
286+
Spec: datav1alpha1.AlluxioRuntimeSpec{
287+
Fuse: datav1alpha1.AlluxioFuseSpec{
288+
ImageTag: "2.8.0",
289+
Image: "fluid/alluixo-fuse",
290+
ImagePullPolicy: "always",
291+
LaunchMode: datav1alpha1.EagerMode,
292+
NodeSelector: map[string]string{
293+
"fuse_node": "true",
294+
},
295+
},
296+
},
297+
},
298+
wantValue: &Alluxio{
299+
Fuse: Fuse{
300+
NodeSelector: map[string]string{
301+
"fuse_node": "true",
302+
},
303+
},
304+
},
305+
},
306+
"test fuse launch mode case 2": {
307+
runtime: &datav1alpha1.AlluxioRuntime{
308+
ObjectMeta: metav1.ObjectMeta{
309+
Name: "hbase",
310+
Namespace: "fluid",
311+
},
312+
Spec: datav1alpha1.AlluxioRuntimeSpec{
313+
Fuse: datav1alpha1.AlluxioFuseSpec{
314+
ImageTag: "2.8.0",
315+
Image: "fluid/alluixo-fuse",
316+
ImagePullPolicy: "always",
317+
LaunchMode: datav1alpha1.LazyMode,
318+
NodeSelector: map[string]string{
319+
"fuse_node": "true",
320+
},
321+
},
322+
},
323+
},
324+
wantValue: &Alluxio{
325+
Fuse: Fuse{
326+
NodeSelector: map[string]string{
327+
utils.GetFuseLabelName("fluid", "hbase", ""): "true",
328+
"fuse_node": "true",
329+
},
330+
},
331+
},
332+
},
333+
"test fuse launch mode case 3": {
334+
runtime: &datav1alpha1.AlluxioRuntime{
335+
ObjectMeta: metav1.ObjectMeta{
336+
Name: "hbase",
337+
Namespace: "fluid",
338+
},
339+
Spec: datav1alpha1.AlluxioRuntimeSpec{
340+
Fuse: datav1alpha1.AlluxioFuseSpec{
341+
ImageTag: "2.8.0",
342+
Image: "fluid/alluixo-fuse",
343+
ImagePullPolicy: "always",
344+
LaunchMode: "",
345+
},
346+
},
347+
},
348+
wantValue: &Alluxio{
349+
Fuse: Fuse{
350+
NodeSelector: map[string]string{
351+
utils.GetFuseLabelName("fluid", "hbase", ""): "true",
352+
},
353+
},
354+
},
355+
},
356+
}
357+
358+
runtimeInfo, err := base.BuildRuntimeInfo("hbase", "fluid", "alluxio")
359+
if err != nil {
360+
t.Errorf("fail to create the runtimeInfo with error %v", err)
361+
}
362+
363+
engine := &AlluxioEngine{
364+
Log: fake.NullLogger(),
365+
runtimeInfo: runtimeInfo,
366+
Client: fake.NewFakeClientWithScheme(testScheme),
367+
}
368+
ds := &datav1alpha1.Dataset{}
369+
for k, v := range testCases {
370+
gotValue := &Alluxio{}
371+
if err := engine.transformFuse(v.runtime, ds, gotValue); err == nil {
372+
if !reflect.DeepEqual(gotValue.Fuse.NodeSelector, v.wantValue.Fuse.NodeSelector) {
373+
t.Errorf("check %s failure, got:%+v,want:%+v",
374+
k,
375+
gotValue.Fuse.NodeSelector,
376+
v.wantValue.Fuse.NodeSelector,
377+
)
378+
}
379+
}
380+
381+
}
382+
}

0 commit comments

Comments
 (0)