Skip to content

Commit dbb2e26

Browse files
Syspretor玖宇
andauthored
Fix that containerNetwork config is not effected (#4801)
Signed-off-by: 玖宇 <guotongyu.gty@alibaba-inc.com> Co-authored-by: 玖宇 <guotongyu.gty@alibaba-inc.com>
1 parent 56b744d commit dbb2e26

3 files changed

Lines changed: 223 additions & 121 deletions

File tree

pkg/ddc/thin/transform_fuse.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ func (t *ThinEngine) transformFuse(runtime *datav1alpha1.ThinRuntime, profile *d
8686
}
8787

8888
// 9. network
89-
value.Fuse.HostNetwork = datav1alpha1.IsHostNetwork(runtime.Spec.Fuse.NetworkMode)
89+
if runtime.Spec.Fuse.NetworkMode != "" {
90+
value.Fuse.HostNetwork = datav1alpha1.IsHostNetwork(runtime.Spec.Fuse.NetworkMode)
91+
}
9092
value.Fuse.HostPID = common.HostPIDEnabled(runtime.Annotations)
9193

9294
// 10. targetPath to mount

pkg/ddc/thin/transform_fuse_test.go

Lines changed: 219 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -283,125 +283,9 @@ func TestThinEngine_parseFuseOptions(t1 *testing.T) {
283283
}
284284

285285
func TestThinEngine_transformFuse(t1 *testing.T) {
286-
profile := &datav1alpha1.ThinRuntimeProfile{
287-
ObjectMeta: metav1.ObjectMeta{
288-
Name: "test",
289-
},
290-
Spec: datav1alpha1.ThinRuntimeProfileSpec{
291-
FileSystemType: "test",
292-
Fuse: datav1alpha1.ThinFuseSpec{
293-
Image: "test",
294-
ImageTag: "v1",
295-
ImagePullPolicy: "Always",
296-
Resources: corev1.ResourceRequirements{
297-
Requests: corev1.ResourceList{
298-
// Should be inherited
299-
corev1.ResourceCPU: resource.MustParse("100m"),
300-
// Should be overridden
301-
corev1.ResourceMemory: resource.MustParse("2Gi"),
302-
},
303-
},
304-
Env: []corev1.EnvVar{{
305-
Name: "a",
306-
Value: "b",
307-
}},
308-
NodeSelector: map[string]string{"a": "b"},
309-
Ports: []corev1.ContainerPort{{
310-
Name: "port",
311-
ContainerPort: 8080,
312-
}},
313-
NetworkMode: datav1alpha1.HostNetworkMode,
314-
VolumeMounts: []corev1.VolumeMount{{
315-
Name: "a",
316-
MountPath: "/test",
317-
}},
318-
},
319-
Volumes: []corev1.Volume{{
320-
Name: "a",
321-
VolumeSource: corev1.VolumeSource{
322-
HostPath: &corev1.HostPathVolumeSource{Path: "/test"},
323-
},
324-
}},
325-
},
326-
}
327-
runtime := &datav1alpha1.ThinRuntime{
328-
ObjectMeta: metav1.ObjectMeta{
329-
Name: "test",
330-
Namespace: "fluid",
331-
},
332-
Spec: datav1alpha1.ThinRuntimeSpec{
333-
ThinRuntimeProfileName: "test",
334-
Fuse: datav1alpha1.ThinFuseSpec{
335-
Resources: corev1.ResourceRequirements{
336-
Requests: corev1.ResourceList{
337-
corev1.ResourceMemory: resource.MustParse("1Gi"),
338-
},
339-
Limits: corev1.ResourceList{
340-
corev1.ResourceCPU: resource.MustParse("200m"),
341-
corev1.ResourceMemory: resource.MustParse("4Gi"),
342-
},
343-
},
344-
Env: []corev1.EnvVar{{
345-
Name: "b",
346-
ValueFrom: &corev1.EnvVarSource{
347-
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
348-
LocalObjectReference: corev1.LocalObjectReference{Name: "test-cm"},
349-
},
350-
},
351-
}},
352-
Options: map[string]string{
353-
"fuse-opt": "foo",
354-
},
355-
NodeSelector: map[string]string{"b": "c"},
356-
VolumeMounts: []corev1.VolumeMount{{
357-
Name: "b",
358-
MountPath: "/b",
359-
}},
360-
LivenessProbe: &corev1.Probe{
361-
ProbeHandler: corev1.ProbeHandler{
362-
HTTPGet: &corev1.HTTPGetAction{
363-
Path: "/healthz",
364-
},
365-
},
366-
InitialDelaySeconds: 1,
367-
TimeoutSeconds: 1,
368-
PeriodSeconds: 1,
369-
SuccessThreshold: 1,
370-
FailureThreshold: 1,
371-
},
372-
ReadinessProbe: &corev1.Probe{
373-
ProbeHandler: corev1.ProbeHandler{
374-
HTTPGet: &corev1.HTTPGetAction{
375-
Path: "/healthz",
376-
},
377-
},
378-
InitialDelaySeconds: 1,
379-
TimeoutSeconds: 1,
380-
PeriodSeconds: 1,
381-
SuccessThreshold: 1,
382-
FailureThreshold: 1,
383-
},
384-
},
385-
Volumes: []corev1.Volume{{
386-
Name: "b",
387-
VolumeSource: corev1.VolumeSource{
388-
HostPath: &corev1.HostPathVolumeSource{Path: "/b"},
389-
},
390-
}},
391-
},
392-
}
393-
dataset := &datav1alpha1.Dataset{
394-
Spec: datav1alpha1.DatasetSpec{
395-
SharedOptions: map[string]string{
396-
"c": "d",
397-
},
398-
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany},
399-
Mounts: []datav1alpha1.Mount{{
400-
MountPoint: "abc",
401-
Options: map[string]string{"a": "b"},
402-
}},
403-
},
404-
}
286+
profile := buildBaseThinRuntimeProfile()
287+
runtime := buildBaseThinRuntime()
288+
dataset := buildBaseDataset()
405289
wantValue := &ThinValue{
406290
Fuse: Fuse{
407291
Enabled: true,
@@ -519,6 +403,94 @@ func TestThinEngine_transformFuse(t1 *testing.T) {
519403
})
520404
}
521405

406+
func TestThinEngine_transformFuseWithContainerNetwork(t1 *testing.T) {
407+
profile := buildBaseThinRuntimeProfile()
408+
thinRuntime := buildBaseThinRuntime()
409+
dataset := buildBaseDataset()
410+
value := &ThinValue{}
411+
runtimeInfo, err := base.BuildRuntimeInfo("test", "fluid", "thin")
412+
if err != nil {
413+
t1.Errorf("fail to create the runtimeInfo with error %v", err)
414+
}
415+
t1.Run("test", func(t1 *testing.T) {
416+
hostNetworkMode := datav1alpha1.HostNetworkMode
417+
containerNetworkMode := datav1alpha1.ContainerNetworkMode
418+
tests := []struct {
419+
name string
420+
fuseNetworkModeInProfile *datav1alpha1.NetworkMode
421+
fuseNetworkModeInRuntime *datav1alpha1.NetworkMode
422+
wantFuseHostNetwork bool
423+
}{
424+
{
425+
name: "nilInProfile-nilInRuntime",
426+
fuseNetworkModeInProfile: nil,
427+
fuseNetworkModeInRuntime: nil,
428+
wantFuseHostNetwork: true,
429+
}, {
430+
name: "containerNetworkInProfile-nilInRuntime",
431+
fuseNetworkModeInProfile: &containerNetworkMode,
432+
fuseNetworkModeInRuntime: nil,
433+
wantFuseHostNetwork: false,
434+
},
435+
{
436+
name: "hostNetworkInProfile-nilInRuntime",
437+
fuseNetworkModeInProfile: &hostNetworkMode,
438+
fuseNetworkModeInRuntime: nil,
439+
wantFuseHostNetwork: true,
440+
},
441+
{
442+
name: "nilInProfile-hostNetworkInRuntime",
443+
fuseNetworkModeInProfile: nil,
444+
fuseNetworkModeInRuntime: &hostNetworkMode,
445+
wantFuseHostNetwork: true,
446+
},
447+
{
448+
name: "nilInProfile-containerNetworkInRuntime",
449+
fuseNetworkModeInProfile: nil,
450+
fuseNetworkModeInRuntime: &containerNetworkMode,
451+
wantFuseHostNetwork: false,
452+
},
453+
{
454+
name: "containerNetworkInProfile-hostNetworkInRuntime",
455+
fuseNetworkModeInProfile: &containerNetworkMode,
456+
fuseNetworkModeInRuntime: &hostNetworkMode,
457+
wantFuseHostNetwork: true,
458+
},
459+
{
460+
name: "hostNetworkInProfile-containerNetworkInRuntime",
461+
fuseNetworkModeInProfile: &hostNetworkMode,
462+
fuseNetworkModeInRuntime: &containerNetworkMode,
463+
wantFuseHostNetwork: false,
464+
},
465+
}
466+
467+
for _, test := range tests {
468+
if test.fuseNetworkModeInProfile != nil {
469+
profile.Spec.Fuse.NetworkMode = *test.fuseNetworkModeInProfile
470+
}
471+
if test.fuseNetworkModeInRuntime != nil {
472+
thinRuntime.Spec.Fuse.NetworkMode = *test.fuseNetworkModeInRuntime
473+
}
474+
t := &ThinEngine{
475+
Log: fake.NullLogger(),
476+
namespace: "fluid",
477+
name: "test",
478+
runtime: thinRuntime,
479+
runtimeInfo: runtimeInfo,
480+
Client: fake.NewFakeClientWithScheme(testScheme),
481+
}
482+
if err := t.transformFuse(thinRuntime, profile, dataset, value); err != nil {
483+
t1.Errorf("transformFuse() error = %v", err)
484+
}
485+
486+
if value.Fuse.HostNetwork != test.wantFuseHostNetwork {
487+
t1.Errorf("transformFuse() \ngot HostNetwork = %v, \nwant HostNetwork = %v", value.Fuse.HostNetwork, test.wantFuseHostNetwork)
488+
489+
}
490+
}
491+
})
492+
}
493+
522494
func TestThinEngine_transformFuseWithDuplicateOptionKey(t1 *testing.T) {
523495
profile := &datav1alpha1.ThinRuntimeProfile{
524496
ObjectMeta: metav1.ObjectMeta{
@@ -989,3 +961,131 @@ func TestParseHostVolumeFromDataset(t *testing.T) {
989961
})
990962
}
991963
}
964+
965+
func buildBaseDataset() *datav1alpha1.Dataset {
966+
return &datav1alpha1.Dataset{
967+
Spec: datav1alpha1.DatasetSpec{
968+
SharedOptions: map[string]string{
969+
"c": "d",
970+
},
971+
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteMany},
972+
Mounts: []datav1alpha1.Mount{{
973+
MountPoint: "abc",
974+
Options: map[string]string{"a": "b"},
975+
}},
976+
},
977+
}
978+
}
979+
980+
func buildBaseThinRuntime() *datav1alpha1.ThinRuntime {
981+
return &datav1alpha1.ThinRuntime{
982+
ObjectMeta: metav1.ObjectMeta{
983+
Name: "test",
984+
Namespace: "fluid",
985+
},
986+
Spec: datav1alpha1.ThinRuntimeSpec{
987+
ThinRuntimeProfileName: "test",
988+
Fuse: datav1alpha1.ThinFuseSpec{
989+
Resources: corev1.ResourceRequirements{
990+
Requests: corev1.ResourceList{
991+
corev1.ResourceMemory: resource.MustParse("1Gi"),
992+
},
993+
Limits: corev1.ResourceList{
994+
corev1.ResourceCPU: resource.MustParse("200m"),
995+
corev1.ResourceMemory: resource.MustParse("4Gi"),
996+
},
997+
},
998+
Env: []corev1.EnvVar{{
999+
Name: "b",
1000+
ValueFrom: &corev1.EnvVarSource{
1001+
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
1002+
LocalObjectReference: corev1.LocalObjectReference{Name: "test-cm"},
1003+
},
1004+
},
1005+
}},
1006+
Options: map[string]string{
1007+
"fuse-opt": "foo",
1008+
},
1009+
NodeSelector: map[string]string{"b": "c"},
1010+
VolumeMounts: []corev1.VolumeMount{{
1011+
Name: "b",
1012+
MountPath: "/b",
1013+
}},
1014+
LivenessProbe: &corev1.Probe{
1015+
ProbeHandler: corev1.ProbeHandler{
1016+
HTTPGet: &corev1.HTTPGetAction{
1017+
Path: "/healthz",
1018+
},
1019+
},
1020+
InitialDelaySeconds: 1,
1021+
TimeoutSeconds: 1,
1022+
PeriodSeconds: 1,
1023+
SuccessThreshold: 1,
1024+
FailureThreshold: 1,
1025+
},
1026+
ReadinessProbe: &corev1.Probe{
1027+
ProbeHandler: corev1.ProbeHandler{
1028+
HTTPGet: &corev1.HTTPGetAction{
1029+
Path: "/healthz",
1030+
},
1031+
},
1032+
InitialDelaySeconds: 1,
1033+
TimeoutSeconds: 1,
1034+
PeriodSeconds: 1,
1035+
SuccessThreshold: 1,
1036+
FailureThreshold: 1,
1037+
},
1038+
},
1039+
Volumes: []corev1.Volume{{
1040+
Name: "b",
1041+
VolumeSource: corev1.VolumeSource{
1042+
HostPath: &corev1.HostPathVolumeSource{Path: "/b"},
1043+
},
1044+
}},
1045+
},
1046+
}
1047+
}
1048+
1049+
func buildBaseThinRuntimeProfile() *datav1alpha1.ThinRuntimeProfile {
1050+
return &datav1alpha1.ThinRuntimeProfile{
1051+
ObjectMeta: metav1.ObjectMeta{
1052+
Name: "test",
1053+
},
1054+
Spec: datav1alpha1.ThinRuntimeProfileSpec{
1055+
FileSystemType: "test",
1056+
Fuse: datav1alpha1.ThinFuseSpec{
1057+
Image: "test",
1058+
ImageTag: "v1",
1059+
ImagePullPolicy: "Always",
1060+
Resources: corev1.ResourceRequirements{
1061+
Requests: corev1.ResourceList{
1062+
// Should be inherited
1063+
corev1.ResourceCPU: resource.MustParse("100m"),
1064+
// Should be overridden
1065+
corev1.ResourceMemory: resource.MustParse("2Gi"),
1066+
},
1067+
},
1068+
Env: []corev1.EnvVar{{
1069+
Name: "a",
1070+
Value: "b",
1071+
}},
1072+
NodeSelector: map[string]string{"a": "b"},
1073+
Ports: []corev1.ContainerPort{{
1074+
Name: "port",
1075+
ContainerPort: 8080,
1076+
}},
1077+
NetworkMode: datav1alpha1.HostNetworkMode,
1078+
VolumeMounts: []corev1.VolumeMount{{
1079+
Name: "a",
1080+
MountPath: "/test",
1081+
}},
1082+
},
1083+
Volumes: []corev1.Volume{{
1084+
Name: "a",
1085+
VolumeSource: corev1.VolumeSource{
1086+
HostPath: &corev1.HostPathVolumeSource{Path: "/test"},
1087+
},
1088+
}},
1089+
},
1090+
}
1091+
}

pkg/ddc/thin/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Fuse struct {
6565
Resources common.Resources `json:"resources,omitempty"`
6666
Ports []corev1.ContainerPort `json:"ports,omitempty"`
6767
CriticalPod bool `json:"criticalPod,omitempty"`
68-
HostNetwork bool `json:"hostNetwork,omitempty"`
68+
HostNetwork bool `json:"hostNetwork"`
6969
HostPID bool `json:"hostPID,omitempty"`
7070
TargetPath string `json:"targetPath,omitempty"`
7171
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

0 commit comments

Comments
 (0)