volumes.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // This test is volumes test for configmap.
  14. package storage
  15. import (
  16. "context"
  17. "github.com/onsi/ginkgo"
  18. v1 "k8s.io/api/core/v1"
  19. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  20. clientset "k8s.io/client-go/kubernetes"
  21. "k8s.io/kubernetes/test/e2e/framework"
  22. "k8s.io/kubernetes/test/e2e/framework/volume"
  23. "k8s.io/kubernetes/test/e2e/storage/utils"
  24. )
  25. // These tests need privileged containers, which are disabled by default.
  26. var _ = utils.SIGDescribe("Volumes", func() {
  27. f := framework.NewDefaultFramework("volume")
  28. // note that namespace deletion is handled by delete-namespace flag
  29. // filled inside BeforeEach
  30. var cs clientset.Interface
  31. var namespace *v1.Namespace
  32. ginkgo.BeforeEach(func() {
  33. cs = f.ClientSet
  34. namespace = f.Namespace
  35. })
  36. ginkgo.Describe("ConfigMap", func() {
  37. ginkgo.It("should be mountable", func() {
  38. config := volume.TestConfig{
  39. Namespace: namespace.Name,
  40. Prefix: "configmap",
  41. }
  42. configMap := &v1.ConfigMap{
  43. TypeMeta: metav1.TypeMeta{
  44. Kind: "ConfigMap",
  45. APIVersion: "v1",
  46. },
  47. ObjectMeta: metav1.ObjectMeta{
  48. Name: config.Prefix + "-map",
  49. },
  50. Data: map[string]string{
  51. "first": "this is the first file",
  52. "second": "this is the second file",
  53. "third": "this is the third file",
  54. },
  55. }
  56. if _, err := cs.CoreV1().ConfigMaps(namespace.Name).Create(context.TODO(), configMap, metav1.CreateOptions{}); err != nil {
  57. framework.Failf("unable to create test configmap: %v", err)
  58. }
  59. defer func() {
  60. _ = cs.CoreV1().ConfigMaps(namespace.Name).Delete(context.TODO(), configMap.Name, nil)
  61. }()
  62. // Test one ConfigMap mounted several times to test #28502
  63. tests := []volume.Test{
  64. {
  65. Volume: v1.VolumeSource{
  66. ConfigMap: &v1.ConfigMapVolumeSource{
  67. LocalObjectReference: v1.LocalObjectReference{
  68. Name: config.Prefix + "-map",
  69. },
  70. Items: []v1.KeyToPath{
  71. {
  72. Key: "first",
  73. Path: "firstfile",
  74. },
  75. },
  76. },
  77. },
  78. File: "firstfile",
  79. ExpectedContent: "this is the first file",
  80. },
  81. {
  82. Volume: v1.VolumeSource{
  83. ConfigMap: &v1.ConfigMapVolumeSource{
  84. LocalObjectReference: v1.LocalObjectReference{
  85. Name: config.Prefix + "-map",
  86. },
  87. Items: []v1.KeyToPath{
  88. {
  89. Key: "second",
  90. Path: "secondfile",
  91. },
  92. },
  93. },
  94. },
  95. File: "secondfile",
  96. ExpectedContent: "this is the second file",
  97. },
  98. }
  99. volume.TestVolumeClient(f, config, nil, "" /* fsType */, tests)
  100. })
  101. })
  102. })