k8s.io/kubernetes@v1.29.3/test/e2e/storage/volumes.go (about)

     1  /*
     2  Copyright 2015 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // This test is volumes test for configmap.
    18  
    19  package storage
    20  
    21  import (
    22  	"context"
    23  
    24  	"github.com/onsi/ginkgo/v2"
    25  	v1 "k8s.io/api/core/v1"
    26  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    27  	clientset "k8s.io/client-go/kubernetes"
    28  	"k8s.io/kubernetes/test/e2e/framework"
    29  	e2evolume "k8s.io/kubernetes/test/e2e/framework/volume"
    30  	"k8s.io/kubernetes/test/e2e/storage/utils"
    31  	admissionapi "k8s.io/pod-security-admission/api"
    32  )
    33  
    34  // These tests need privileged containers, which are disabled by default.
    35  var _ = utils.SIGDescribe("Volumes", func() {
    36  	f := framework.NewDefaultFramework("volume")
    37  	f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
    38  
    39  	// note that namespace deletion is handled by delete-namespace flag
    40  	// filled inside BeforeEach
    41  	var cs clientset.Interface
    42  	var namespace *v1.Namespace
    43  
    44  	ginkgo.BeforeEach(func() {
    45  		cs = f.ClientSet
    46  		namespace = f.Namespace
    47  	})
    48  
    49  	ginkgo.Describe("ConfigMap", func() {
    50  		ginkgo.It("should be mountable", func(ctx context.Context) {
    51  			config := e2evolume.TestConfig{
    52  				Namespace: namespace.Name,
    53  				Prefix:    "configmap",
    54  			}
    55  			configMap := &v1.ConfigMap{
    56  				TypeMeta: metav1.TypeMeta{
    57  					Kind:       "ConfigMap",
    58  					APIVersion: "v1",
    59  				},
    60  				ObjectMeta: metav1.ObjectMeta{
    61  					Name: config.Prefix + "-map",
    62  				},
    63  				Data: map[string]string{
    64  					"first":  "this is the first file",
    65  					"second": "this is the second file",
    66  					"third":  "this is the third file",
    67  				},
    68  			}
    69  			if _, err := cs.CoreV1().ConfigMaps(namespace.Name).Create(ctx, configMap, metav1.CreateOptions{}); err != nil {
    70  				framework.Failf("unable to create test configmap: %v", err)
    71  			}
    72  			defer func() {
    73  				_ = cs.CoreV1().ConfigMaps(namespace.Name).Delete(ctx, configMap.Name, metav1.DeleteOptions{})
    74  			}()
    75  
    76  			// Test one ConfigMap mounted several times to test #28502
    77  			tests := []e2evolume.Test{
    78  				{
    79  					Volume: v1.VolumeSource{
    80  						ConfigMap: &v1.ConfigMapVolumeSource{
    81  							LocalObjectReference: v1.LocalObjectReference{
    82  								Name: config.Prefix + "-map",
    83  							},
    84  							Items: []v1.KeyToPath{
    85  								{
    86  									Key:  "first",
    87  									Path: "firstfile",
    88  								},
    89  							},
    90  						},
    91  					},
    92  					File:            "firstfile",
    93  					ExpectedContent: "this is the first file",
    94  				},
    95  				{
    96  					Volume: v1.VolumeSource{
    97  						ConfigMap: &v1.ConfigMapVolumeSource{
    98  							LocalObjectReference: v1.LocalObjectReference{
    99  								Name: config.Prefix + "-map",
   100  							},
   101  							Items: []v1.KeyToPath{
   102  								{
   103  									Key:  "second",
   104  									Path: "secondfile",
   105  								},
   106  							},
   107  						},
   108  					},
   109  					File:            "secondfile",
   110  					ExpectedContent: "this is the second file",
   111  				},
   112  			}
   113  			e2evolume.TestVolumeClient(ctx, f, config, nil, "" /* fsType */, tests)
   114  		})
   115  	})
   116  })