mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #22613 from jayunit100/e2e-volumes-simple
Auto commit by PR queue bot
This commit is contained in:
commit
26e9f187d7
@ -182,8 +182,6 @@ func volumeTestCleanup(client *client.Client, config VolumeTestConfig) {
|
||||
// and check that the pod sees the data from the server pod.
|
||||
func testVolumeClient(client *client.Client, config VolumeTestConfig, volume api.VolumeSource, fsGroup *int64, expectedContent string) {
|
||||
By(fmt.Sprint("starting ", config.prefix, " client"))
|
||||
podClient := client.Pods(config.namespace)
|
||||
|
||||
clientPod := &api.Pod{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "Pod",
|
||||
@ -198,19 +196,21 @@ func testVolumeClient(client *client.Client, config VolumeTestConfig, volume api
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Name: config.prefix + "-client",
|
||||
Image: "gcr.io/google_containers/nginx:1.7.9",
|
||||
Ports: []api.ContainerPort{
|
||||
{
|
||||
Name: "web",
|
||||
ContainerPort: 80,
|
||||
Protocol: api.ProtocolTCP,
|
||||
},
|
||||
Name: config.prefix + "-client",
|
||||
Image: "gcr.io/google_containers/busybox:1.24",
|
||||
WorkingDir: "/opt",
|
||||
// An imperative and easily debuggable container which reads vol contents for
|
||||
// us to scan in the tests or by eye.
|
||||
// We expect that /opt is empty in the minimal containers which we use in this test.
|
||||
Command: []string{
|
||||
"/bin/sh",
|
||||
"-c",
|
||||
"while true ; do cat /opt/index.html ; sleep 2 ; ls -altrh /opt/ ; sleep 2 ; done ",
|
||||
},
|
||||
VolumeMounts: []api.VolumeMount{
|
||||
{
|
||||
Name: config.prefix + "-volume",
|
||||
MountPath: "/usr/share/nginx/html",
|
||||
MountPath: "/opt/",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -228,46 +228,25 @@ func testVolumeClient(client *client.Client, config VolumeTestConfig, volume api
|
||||
},
|
||||
},
|
||||
}
|
||||
podsNamespacer := client.Pods(config.namespace)
|
||||
|
||||
if fsGroup != nil {
|
||||
clientPod.Spec.SecurityContext.FSGroup = fsGroup
|
||||
}
|
||||
|
||||
if _, err := podClient.Create(clientPod); err != nil {
|
||||
if _, err := podsNamespacer.Create(clientPod); err != nil {
|
||||
Failf("Failed to create %s pod: %v", clientPod.Name, err)
|
||||
}
|
||||
expectNoError(waitForPodRunningInNamespace(client, clientPod.Name, config.namespace))
|
||||
|
||||
By("reading a web page from the client")
|
||||
subResourceProxyAvailable, err := serverVersionGTE(subResourcePodProxyVersion, client)
|
||||
if err != nil {
|
||||
Failf("Failed to get server version: %v", err)
|
||||
}
|
||||
var body []byte
|
||||
if subResourceProxyAvailable {
|
||||
body, err = client.Get().
|
||||
Namespace(config.namespace).
|
||||
Resource("pods").
|
||||
SubResource("proxy").
|
||||
Name(clientPod.Name).
|
||||
DoRaw()
|
||||
} else {
|
||||
body, err = client.Get().
|
||||
Prefix("proxy").
|
||||
Namespace(config.namespace).
|
||||
Resource("pods").
|
||||
Name(clientPod.Name).
|
||||
DoRaw()
|
||||
}
|
||||
expectNoError(err, "Cannot read web page: %v", err)
|
||||
Logf("body: %v", string(body))
|
||||
|
||||
By("checking the page content")
|
||||
Expect(body).To(ContainSubstring(expectedContent))
|
||||
By("Checking that text file contents are perfect.")
|
||||
_, err := lookForStringInPodExec(config.namespace, clientPod.Name, []string{"cat", "/opt/index.html"}, expectedContent, time.Minute)
|
||||
Expect(err).NotTo(HaveOccurred(), "failed: finding the contents of the mounted file.")
|
||||
|
||||
if fsGroup != nil {
|
||||
By("Checking fsGroup")
|
||||
_, err = lookForStringInPodExec(config.namespace, clientPod.Name, []string{"ls", "-ld", "/usr/share/nginx/html"}, strconv.Itoa(int(*fsGroup)), time.Minute)
|
||||
Expect(err).NotTo(HaveOccurred(), "waiting for output from pod exec")
|
||||
|
||||
By("Checking fsGroup is correct.")
|
||||
_, err = lookForStringInPodExec(config.namespace, clientPod.Name, []string{"ls", "-ld", "/opt"}, strconv.Itoa(int(*fsGroup)), time.Minute)
|
||||
Expect(err).NotTo(HaveOccurred(), "failed: getting the right priviliges in the file %v", int(*fsGroup))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user