@@ -33,8 +33,11 @@ import (
3333
3434var _ = Describe ("FluidAppReconcilerImplement" , func () {
3535 const (
36- expectedJuiceFSMountCmd = "/mnt/jfs/juicefs-fuse"
37- fuseMountPath = "/mnt/fuse"
36+ expectedJuiceFSMountCmd = "/mnt/jfs/juicefs-fuse"
37+ fuseMountPath = "/mnt/fuse"
38+ juicefsFuseMount = "juicefs-fuse-mount"
39+ juicefsMountPath = "/mnt/jfs"
40+ shouldSucceedWithoutErrs = "should succeed without errors"
3841 )
3942
4043 var patches * gomonkey.Patches
@@ -65,75 +68,101 @@ var _ = Describe("FluidAppReconcilerImplement", func() {
6568 Expect (i .umountFuseSidecars (pod )).To (Succeed ())
6669 })
6770
68- It ("uses the container prestop command when present" , func () {
69- patches = gomonkey .ApplyFunc (kubeclient .ExecCommandInContainerWithContext , func (_ context.Context , podName , containerName , namespace string , cmd []string ) (string , string , error ) {
70- Expect (podName ).To (Equal ("test" ))
71- Expect (containerName ).To (Equal (common .FuseContainerName + "-0" ))
72- Expect (namespace ).To (BeEmpty ())
73- Expect (cmd ).To (Equal ([]string {"umount" }))
74- return "" , "" , nil
75- })
76-
77- i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
78- pod := & corev1.Pod {
79- ObjectMeta : metav1.ObjectMeta {Name : "test" },
80- Spec : corev1.PodSpec {Containers : []corev1.Container {{
81- Name : common .FuseContainerName + "-0" ,
82- Lifecycle : & corev1.Lifecycle {PreStop : & corev1.LifecycleHandler {
83- Exec : & corev1.ExecAction {Command : []string {"umount" }},
84- }},
85- }}},
86- }
71+ Context ("when fuse container has no mount path" , func () {
72+ It (shouldSucceedWithoutErrs , func () {
73+ i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
74+ pod := & corev1.Pod {
75+ ObjectMeta : metav1.ObjectMeta {Name : "test" },
76+ Spec : corev1.PodSpec {
77+ Containers : []corev1.Container {{Name : common .FuseContainerName + "-0" }},
78+ },
79+ }
8780
88- Expect (i .umountFuseSidecars (pod )).To (Succeed ())
81+ Expect (i .umountFuseSidecars (pod )).To (Succeed ())
82+ })
8983 })
9084
91- It ("derives the mount path when the fuse sidecar has no prestop" , func () {
92- patches = gomonkey .ApplyFunc (kubeclient .ExecCommandInContainerWithContext , func (_ context.Context , _ , _ , _ string , cmd []string ) (string , string , error ) {
93- Expect (cmd ).To (Equal ([]string {"umount" , expectedJuiceFSMountCmd }))
94- return "" , "" , nil
85+ Context ("when fuse container has prestop hook" , func () {
86+ It (shouldSucceedWithoutErrs , func () {
87+ patches = gomonkey .ApplyFunc (kubeclient .ExecCommandInContainerWithContext , func (_ context.Context , podName , containerName , namespace string , cmd []string ) (string , string , error ) {
88+ Expect (podName ).To (Equal ("test" ))
89+ Expect (containerName ).To (Equal (common .FuseContainerName + "-0" ))
90+ Expect (namespace ).To (BeEmpty ())
91+ Expect (cmd ).To (Equal ([]string {"umount" }))
92+ return "" , "" , nil
93+ })
94+
95+ i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
96+ pod := & corev1.Pod {
97+ ObjectMeta : metav1.ObjectMeta {Name : "test" },
98+ Spec : corev1.PodSpec {Containers : []corev1.Container {{
99+ Name : common .FuseContainerName + "-0" ,
100+ Lifecycle : & corev1.Lifecycle {PreStop : & corev1.LifecycleHandler {
101+ Exec : & corev1.ExecAction {Command : []string {"umount" }},
102+ }},
103+ }}},
104+ }
105+
106+ Expect (i .umountFuseSidecars (pod )).To (Succeed ())
95107 })
96-
97- i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
98- pod := & corev1.Pod {
99- ObjectMeta : metav1.ObjectMeta {Name : "test" },
100- Spec : corev1.PodSpec {Containers : []corev1.Container {{
101- Name : common .FuseContainerName + "-0" ,
102- VolumeMounts : []corev1.VolumeMount {{
103- Name : "juicefs-fuse-mount" ,
104- MountPath : "/mnt/jfs" ,
105- }},
106- }}},
107- }
108-
109- Expect (i .umountFuseSidecars (pod )).To (Succeed ())
110108 })
111109
112- It ("unmounts each fuse sidecar container" , func () {
113- containerNames := []string {}
114- patches = gomonkey .ApplyFunc ((* FluidAppReconcilerImplement ).umountFuseSidecar , func (_ * FluidAppReconcilerImplement , _ * corev1.Pod , fuseContainer corev1.Container ) error {
115- containerNames = append (containerNames , fuseContainer .Name )
116- return nil
110+ Context ("when fuse container has mount path" , func () {
111+ It ("should succeed and umount the path" , func () {
112+ patches = gomonkey .ApplyFunc (kubeclient .ExecCommandInContainerWithContext , func (_ context.Context , _ , _ , _ string , cmd []string ) (string , string , error ) {
113+ Expect (cmd ).To (Equal ([]string {"umount" , expectedJuiceFSMountCmd }))
114+ return "" , "" , nil
115+ })
116+
117+ i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
118+ pod := & corev1.Pod {
119+ ObjectMeta : metav1.ObjectMeta {Name : "test" },
120+ Spec : corev1.PodSpec {Containers : []corev1.Container {{
121+ Name : common .FuseContainerName + "-0" ,
122+ VolumeMounts : []corev1.VolumeMount {{
123+ Name : juicefsFuseMount ,
124+ MountPath : juicefsMountPath ,
125+ }},
126+ }}},
127+ }
128+
129+ Expect (i .umountFuseSidecars (pod )).To (Succeed ())
117130 })
131+ })
118132
119- i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
120- pod := & corev1.Pod {
121- ObjectMeta : metav1.ObjectMeta {Name : "test" },
122- Spec : corev1.PodSpec {Containers : []corev1.Container {
123- {
124- Name : common .FuseContainerName + "-0" ,
125- VolumeMounts : []corev1.VolumeMount {{Name : "juicefs-fuse-mount" , MountPath : "/mnt/jfs" }},
126- },
127- {
128- Name : common .FuseContainerName + "-1" ,
129- VolumeMounts : []corev1.VolumeMount {{Name : "juicefs-fuse-mount" , MountPath : "/mnt/jfs" }},
130- },
131- }},
132- }
133+ Context ("when pod has multiple fuse sidecars" , func () {
134+ It ("unmounts each fuse sidecar container" , func () {
135+ containerNames := []string {}
136+ patches = gomonkey .ApplyFunc ((* FluidAppReconcilerImplement ).umountFuseSidecar , func (_ * FluidAppReconcilerImplement , _ * corev1.Pod , fuseContainer corev1.Container ) error {
137+ containerNames = append (containerNames , fuseContainer .Name )
138+ return nil
139+ })
140+
141+ i := & FluidAppReconcilerImplement {Log : fake .NullLogger ()}
142+ pod := & corev1.Pod {
143+ ObjectMeta : metav1.ObjectMeta {Name : "test" },
144+ Spec : corev1.PodSpec {Containers : []corev1.Container {
145+ {
146+ Name : common .FuseContainerName + "-0" ,
147+ VolumeMounts : []corev1.VolumeMount {{
148+ Name : juicefsFuseMount ,
149+ MountPath : juicefsMountPath ,
150+ }},
151+ },
152+ {
153+ Name : common .FuseContainerName + "-1" ,
154+ VolumeMounts : []corev1.VolumeMount {{
155+ Name : juicefsFuseMount ,
156+ MountPath : juicefsMountPath ,
157+ }},
158+ },
159+ }},
160+ }
133161
134- Expect (i .umountFuseSidecars (pod )).To (Succeed ())
135- Expect (containerNames ).To (ConsistOf (common .FuseContainerName + "-0" , common .FuseContainerName + "-1" ))
136- Expect (containerNames ).To (HaveLen (2 ))
162+ Expect (i .umountFuseSidecars (pod )).To (Succeed ())
163+ Expect (containerNames ).To (ConsistOf (common .FuseContainerName + "-0" , common .FuseContainerName + "-1" ))
164+ Expect (containerNames ).To (HaveLen (2 ))
165+ })
137166 })
138167 })
139168
0 commit comments