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. "github.com/onsi/ginkgo"
  17. "k8s.io/api/core/v1"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. clientset "k8s.io/client-go/kubernetes"
  20. "k8s.io/kubernetes/test/e2e/framework"
  21. "k8s.io/kubernetes/test/e2e/framework/volume"
  22. "k8s.io/kubernetes/test/e2e/storage/utils"
  23. )
  24. // These tests need privileged containers, which are disabled by default.
  25. var _ = utils.SIGDescribe("Volumes", func() {
  26. f := framework.NewDefaultFramework("volume")
  27. // note that namespace deletion is handled by delete-namespace flag
  28. // filled inside BeforeEach
  29. var cs clientset.Interface
  30. var namespace *v1.Namespace
  31. ginkgo.BeforeEach(func() {
  32. cs = f.ClientSet
  33. namespace = f.Namespace
  34. })
  35. ginkgo.Describe("ConfigMap", func() {
  36. ginkgo.It("should be mountable", func() {
  37. config := volume.TestConfig{
  38. Namespace: namespace.Name,
  39. Prefix: "configmap",
  40. }
  41. defer volume.TestCleanup(f, config)
  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(configMap); err != nil {
  57. framework.Failf("unable to create test configmap: %v", err)
  58. }
  59. defer func() {
  60. _ = cs.CoreV1().ConfigMaps(namespace.Name).Delete(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(cs, config, nil, "" /* fsType */, tests)
  100. })
  101. })
  102. })