subpath.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. Copyright 2018 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 storage
  14. import (
  15. "context"
  16. "k8s.io/api/core/v1"
  17. apierrors "k8s.io/apimachinery/pkg/api/errors"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. "k8s.io/kubernetes/test/e2e/storage/testsuites"
  21. "k8s.io/kubernetes/test/e2e/storage/utils"
  22. "github.com/onsi/ginkgo"
  23. )
  24. var _ = utils.SIGDescribe("Subpath", func() {
  25. f := framework.NewDefaultFramework("subpath")
  26. ginkgo.Context("Atomic writer volumes", func() {
  27. var err error
  28. var privilegedSecurityContext bool = false
  29. ginkgo.BeforeEach(func() {
  30. ginkgo.By("Setting up data")
  31. secret := &v1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "my-secret"}, Data: map[string][]byte{"secret-key": []byte("secret-value")}}
  32. _, err = f.ClientSet.CoreV1().Secrets(f.Namespace.Name).Create(context.TODO(), secret, metav1.CreateOptions{})
  33. if err != nil && !apierrors.IsAlreadyExists(err) {
  34. framework.ExpectNoError(err, "while creating secret")
  35. }
  36. configmap := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "my-configmap"}, Data: map[string]string{"configmap-key": "configmap-value"}}
  37. _, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), configmap, metav1.CreateOptions{})
  38. if err != nil && !apierrors.IsAlreadyExists(err) {
  39. framework.ExpectNoError(err, "while creating configmap")
  40. }
  41. })
  42. /*
  43. Release : v1.12
  44. Testname: SubPath: Reading content from a secret volume.
  45. Description: Containers in a pod can read content from a secret mounted volume which was configured with a subpath.
  46. This test is marked LinuxOnly since Windows cannot mount individual files in Containers.
  47. */
  48. framework.ConformanceIt("should support subpaths with secret pod [LinuxOnly]", func() {
  49. // TODO(claudiub): Remove [LinuxOnly] tag once Containerd becomes the default container runtime on Windows.
  50. pod := testsuites.SubpathTestPod(f, "secret-key", "secret", &v1.VolumeSource{Secret: &v1.SecretVolumeSource{SecretName: "my-secret"}}, privilegedSecurityContext)
  51. testsuites.TestBasicSubpath(f, "secret-value", pod)
  52. })
  53. /*
  54. Release : v1.12
  55. Testname: SubPath: Reading content from a configmap volume.
  56. Description: Containers in a pod can read content from a configmap mounted volume which was configured with a subpath.
  57. This test is marked LinuxOnly since Windows cannot mount individual files in Containers.
  58. */
  59. framework.ConformanceIt("should support subpaths with configmap pod [LinuxOnly]", func() {
  60. // TODO(claudiub): Remove [LinuxOnly] tag once Containerd becomes the default container runtime on Windows.
  61. pod := testsuites.SubpathTestPod(f, "configmap-key", "configmap", &v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "my-configmap"}}}, privilegedSecurityContext)
  62. testsuites.TestBasicSubpath(f, "configmap-value", pod)
  63. })
  64. /*
  65. Release : v1.12
  66. Testname: SubPath: Reading content from a configmap volume.
  67. Description: Containers in a pod can read content from a configmap mounted volume which was configured with a subpath and also using a mountpath that is a specific file.
  68. This test is marked LinuxOnly since Windows cannot mount individual files in Containers.
  69. */
  70. framework.ConformanceIt("should support subpaths with configmap pod with mountPath of existing file [LinuxOnly]", func() {
  71. // TODO(claudiub): Remove [LinuxOnly] tag once Containerd becomes the default container runtime on Windows.
  72. pod := testsuites.SubpathTestPod(f, "configmap-key", "configmap", &v1.VolumeSource{ConfigMap: &v1.ConfigMapVolumeSource{LocalObjectReference: v1.LocalObjectReference{Name: "my-configmap"}}}, privilegedSecurityContext)
  73. file := "/etc/resolv.conf"
  74. pod.Spec.Containers[0].VolumeMounts[0].MountPath = file
  75. testsuites.TestBasicSubpathFile(f, "configmap-value", pod, file)
  76. })
  77. /*
  78. Release : v1.12
  79. Testname: SubPath: Reading content from a downwardAPI volume.
  80. Description: Containers in a pod can read content from a downwardAPI mounted volume which was configured with a subpath.
  81. This test is marked LinuxOnly since Windows cannot mount individual files in Containers.
  82. */
  83. framework.ConformanceIt("should support subpaths with downward pod [LinuxOnly]", func() {
  84. // TODO(claudiub): Remove [LinuxOnly] tag once Containerd becomes the default container runtime on Windows.
  85. pod := testsuites.SubpathTestPod(f, "downward/podname", "downwardAPI", &v1.VolumeSource{
  86. DownwardAPI: &v1.DownwardAPIVolumeSource{
  87. Items: []v1.DownwardAPIVolumeFile{{Path: "downward/podname", FieldRef: &v1.ObjectFieldSelector{APIVersion: "v1", FieldPath: "metadata.name"}}},
  88. },
  89. }, privilegedSecurityContext)
  90. testsuites.TestBasicSubpath(f, pod.Name, pod)
  91. })
  92. /*
  93. Release : v1.12
  94. Testname: SubPath: Reading content from a projected volume.
  95. Description: Containers in a pod can read content from a projected mounted volume which was configured with a subpath.
  96. This test is marked LinuxOnly since Windows cannot mount individual files in Containers.
  97. */
  98. framework.ConformanceIt("should support subpaths with projected pod [LinuxOnly]", func() {
  99. // TODO(claudiub): Remove [LinuxOnly] tag once Containerd becomes the default container runtime on Windows.
  100. pod := testsuites.SubpathTestPod(f, "projected/configmap-key", "projected", &v1.VolumeSource{
  101. Projected: &v1.ProjectedVolumeSource{
  102. Sources: []v1.VolumeProjection{
  103. {ConfigMap: &v1.ConfigMapProjection{
  104. LocalObjectReference: v1.LocalObjectReference{Name: "my-configmap"},
  105. Items: []v1.KeyToPath{{Path: "projected/configmap-key", Key: "configmap-key"}},
  106. }},
  107. },
  108. },
  109. }, privilegedSecurityContext)
  110. testsuites.TestBasicSubpath(f, "configmap-value", pod)
  111. })
  112. })
  113. })