empty_dir_wrapper.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package e2e
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/util/intstr"
  17. "k8s.io/kubernetes/pkg/util/uuid"
  18. "k8s.io/kubernetes/test/e2e/framework"
  19. "strconv"
  20. . "github.com/onsi/ginkgo"
  21. )
  22. // This test will create a pod with a secret volume and gitRepo volume
  23. // Thus requests a secret, a git server pod, and a git server service
  24. var _ = framework.KubeDescribe("EmptyDir wrapper volumes", func() {
  25. f := framework.NewDefaultFramework("emptydir-wrapper")
  26. It("should becomes running", func() {
  27. name := "emptydir-wrapper-test-" + string(uuid.NewUUID())
  28. volumeName := "secret-volume"
  29. volumeMountPath := "/etc/secret-volume"
  30. secret := &api.Secret{
  31. ObjectMeta: api.ObjectMeta{
  32. Namespace: f.Namespace.Name,
  33. Name: name,
  34. },
  35. Data: map[string][]byte{
  36. "data-1": []byte("value-1\n"),
  37. },
  38. }
  39. var err error
  40. if secret, err = f.Client.Secrets(f.Namespace.Name).Create(secret); err != nil {
  41. framework.Failf("unable to create test secret %s: %v", secret.Name, err)
  42. }
  43. gitServerPodName := "git-server-" + string(uuid.NewUUID())
  44. containerPort := 8000
  45. labels := map[string]string{"name": gitServerPodName}
  46. gitServerPod := &api.Pod{
  47. ObjectMeta: api.ObjectMeta{
  48. Name: gitServerPodName,
  49. Labels: labels,
  50. },
  51. Spec: api.PodSpec{
  52. Containers: []api.Container{
  53. {
  54. Name: "git-repo",
  55. Image: "gcr.io/google_containers/fakegitserver:0.1",
  56. ImagePullPolicy: "IfNotPresent",
  57. Ports: []api.ContainerPort{
  58. {ContainerPort: int32(containerPort)},
  59. },
  60. },
  61. },
  62. },
  63. }
  64. if gitServerPod, err = f.Client.Pods(f.Namespace.Name).Create(gitServerPod); err != nil {
  65. framework.Failf("unable to create test git server pod %s: %v", gitServerPod.Name, err)
  66. }
  67. // Portal IP and port
  68. httpPort := 2345
  69. gitServerSvc := &api.Service{
  70. ObjectMeta: api.ObjectMeta{
  71. Name: "git-server-svc",
  72. },
  73. Spec: api.ServiceSpec{
  74. Selector: labels,
  75. Ports: []api.ServicePort{
  76. {
  77. Name: "http-portal",
  78. Port: int32(httpPort),
  79. TargetPort: intstr.FromInt(containerPort),
  80. },
  81. },
  82. },
  83. }
  84. if gitServerSvc, err = f.Client.Services(f.Namespace.Name).Create(gitServerSvc); err != nil {
  85. framework.Failf("unable to create test git server service %s: %v", gitServerSvc.Name, err)
  86. }
  87. gitVolumeName := "git-volume"
  88. gitVolumeMountPath := "/etc/git-volume"
  89. gitURL := "http://" + gitServerSvc.Spec.ClusterIP + ":" + strconv.Itoa(httpPort)
  90. gitRepo := "test"
  91. pod := &api.Pod{
  92. ObjectMeta: api.ObjectMeta{
  93. Name: "pod-secrets-" + string(uuid.NewUUID()),
  94. },
  95. Spec: api.PodSpec{
  96. Volumes: []api.Volume{
  97. {
  98. Name: volumeName,
  99. VolumeSource: api.VolumeSource{
  100. Secret: &api.SecretVolumeSource{
  101. SecretName: name,
  102. },
  103. },
  104. },
  105. {
  106. Name: gitVolumeName,
  107. VolumeSource: api.VolumeSource{
  108. GitRepo: &api.GitRepoVolumeSource{
  109. Repository: gitURL,
  110. Directory: gitRepo,
  111. },
  112. },
  113. },
  114. },
  115. Containers: []api.Container{
  116. {
  117. Name: "secret-test",
  118. Image: "gcr.io/google_containers/test-webserver:e2e",
  119. VolumeMounts: []api.VolumeMount{
  120. {
  121. Name: volumeName,
  122. MountPath: volumeMountPath,
  123. ReadOnly: true,
  124. },
  125. {
  126. Name: gitVolumeName,
  127. MountPath: gitVolumeMountPath,
  128. },
  129. },
  130. },
  131. },
  132. },
  133. }
  134. pod, err = f.Client.Pods(f.Namespace.Name).Create(pod)
  135. if err != nil {
  136. framework.Failf("unable to create pod %v: %v", pod.Name, err)
  137. }
  138. defer func() {
  139. By("Cleaning up the secret")
  140. if err := f.Client.Secrets(f.Namespace.Name).Delete(secret.Name); err != nil {
  141. framework.Failf("unable to delete secret %v: %v", secret.Name, err)
  142. }
  143. By("Cleaning up the git server pod")
  144. if err = f.Client.Pods(f.Namespace.Name).Delete(gitServerPod.Name, api.NewDeleteOptions(0)); err != nil {
  145. framework.Failf("unable to delete git server pod %v: %v", gitServerPod.Name, err)
  146. }
  147. By("Cleaning up the git server svc")
  148. if err = f.Client.Services(f.Namespace.Name).Delete(gitServerSvc.Name); err != nil {
  149. framework.Failf("unable to delete git server svc %v: %v", gitServerSvc.Name, err)
  150. }
  151. By("Cleaning up the git vol pod")
  152. if err = f.Client.Pods(f.Namespace.Name).Delete(pod.Name, api.NewDeleteOptions(0)); err != nil {
  153. framework.Failf("unable to delete git vol pod %v: %v", pod.Name, err)
  154. }
  155. }()
  156. framework.ExpectNoError(framework.WaitForPodRunningInNamespace(f.Client, pod))
  157. })
  158. })