Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc20f64

Browse files
authored
Merge pull request kubernetes#73523 from pontiyaraja/shared_volumes
test case for shared volumes between the containers in pod
2 parents 41d2445 + 6d7a707 commit dc20f64

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

test/e2e/common/empty_dir.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package common
1919
import (
2020
"fmt"
2121
"path"
22+
"time"
2223

2324
. "github.com/onsi/ginkgo"
2425
"k8s.io/api/core/v1"
@@ -205,6 +206,79 @@ var _ = Describe("[sig-storage] EmptyDir volumes", func() {
205206
framework.ConformanceIt("should support (non-root,0777,default) [LinuxOnly] [NodeConformance]", func() {
206207
doTest0777(f, testImageNonRootUid, v1.StorageMediumDefault)
207208
})
209+
210+
It("pod should support shared volumes between containers", func() {
211+
var (
212+
volumeName = "shared-data"
213+
busyBoxMainVolumeMountPath = "/usr/share/volumeshare"
214+
busyBoxSubVolumeMountPath = "/pod-data"
215+
busyBoxMainVolumeFilePath = fmt.Sprintf("%s/shareddata.txt", busyBoxMainVolumeMountPath)
216+
busyBoxSubVolumeFilePath = fmt.Sprintf("%s/shareddata.txt", busyBoxSubVolumeMountPath)
217+
message = "Hello from the busy-box sub-container"
218+
busyBoxMainContainerName = "busybox-main-container"
219+
busyBoxSubContainerName = "busybox-sub-container"
220+
resultString = ""
221+
)
222+
223+
pod := &v1.Pod{
224+
ObjectMeta: metav1.ObjectMeta{
225+
Name: "pod-sharedvolume-" + string(uuid.NewUUID()),
226+
},
227+
Spec: v1.PodSpec{
228+
Volumes: []v1.Volume{
229+
{
230+
Name: volumeName,
231+
VolumeSource: v1.VolumeSource{
232+
EmptyDir: new(v1.EmptyDirVolumeSource),
233+
},
234+
},
235+
},
236+
Containers: []v1.Container{
237+
{
238+
Name: busyBoxMainContainerName,
239+
Image: imageutils.GetE2EImage(imageutils.BusyBox),
240+
Command: []string{"/bin/sh"},
241+
Args: []string{"-c", "sleep 10"},
242+
VolumeMounts: []v1.VolumeMount{
243+
{
244+
Name: volumeName,
245+
MountPath: busyBoxMainVolumeMountPath,
246+
},
247+
},
248+
},
249+
{
250+
Name: busyBoxSubContainerName,
251+
Image: imageutils.GetE2EImage(imageutils.BusyBox),
252+
Command: []string{"/bin/sh"},
253+
Args: []string{"-c", fmt.Sprintf("echo %s > %s", message, busyBoxSubVolumeFilePath)},
254+
VolumeMounts: []v1.VolumeMount{
255+
{
256+
Name: volumeName,
257+
MountPath: busyBoxSubVolumeMountPath,
258+
},
259+
},
260+
},
261+
},
262+
RestartPolicy: v1.RestartPolicyNever,
263+
},
264+
}
265+
266+
var err error
267+
By("Creating Pod")
268+
pod = f.PodClient().CreateSync(pod)
269+
270+
By("Waiting for the pod running")
271+
err = f.WaitForPodRunning(pod.Name)
272+
framework.ExpectNoError(err, "failed to deploy pod %s", pod.Name)
273+
274+
By("Geting the pod")
275+
pod, err = f.PodClient().Get(pod.Name, metav1.GetOptions{})
276+
framework.ExpectNoError(err, "failed to get pod %s", pod.Name)
277+
278+
By("Reading file content from the nginx-container")
279+
resultString, err = framework.LookForStringInFile(f.Namespace.Name, pod.Name, busyBoxMainContainerName, busyBoxMainVolumeFilePath, message, 30*time.Second)
280+
framework.ExpectNoError(err, "failed to match expected string %s with %s", message, resultString)
281+
})
208282
})
209283

210284
const (

0 commit comments

Comments
 (0)