...

Source file src/k8s.io/kubernetes/test/e2e/common/storage/volumes.go

Documentation: k8s.io/kubernetes/test/e2e/common/storage

     1  /*
     2  Copyright 2016 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  /*
    18   * This test checks that various VolumeSources are working.
    19   *
    20   * There are two ways, how to test the volumes:
    21   * 1) With containerized server (NFS, Ceph, iSCSI, ...)
    22   * The test creates a server pod, exporting simple 'index.html' file.
    23   * Then it uses appropriate VolumeSource to import this file into a client pod
    24   * and checks that the pod can see the file. It does so by importing the file
    25   * into web server root and loading the index.html from it.
    26   *
    27   * These tests work only when privileged containers are allowed, exporting
    28   * various filesystems (ex: NFS) usually needs some mounting or
    29   * other privileged magic in the server pod.
    30   *
    31   * Note that the server containers are for testing purposes only and should not
    32   * be used in production.
    33   *
    34   * 2) With server outside of Kubernetes
    35   * Appropriate server must exist somewhere outside
    36   * the tested Kubernetes cluster. The test itself creates a new volume,
    37   * and checks, that Kubernetes can use it as a volume.
    38   */
    39  
    40  package storage
    41  
    42  import (
    43  	"context"
    44  
    45  	v1 "k8s.io/api/core/v1"
    46  	clientset "k8s.io/client-go/kubernetes"
    47  	"k8s.io/kubernetes/test/e2e/framework"
    48  	e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
    49  	e2evolume "k8s.io/kubernetes/test/e2e/framework/volume"
    50  
    51  	"github.com/onsi/ginkgo/v2"
    52  	admissionapi "k8s.io/pod-security-admission/api"
    53  )
    54  
    55  // TODO(#99468): Check if these tests are still needed.
    56  var _ = SIGDescribe("Volumes", func() {
    57  	f := framework.NewDefaultFramework("volume")
    58  	f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
    59  
    60  	// note that namespace deletion is handled by delete-namespace flag
    61  	// filled in BeforeEach
    62  	var namespace *v1.Namespace
    63  	var c clientset.Interface
    64  
    65  	ginkgo.BeforeEach(func() {
    66  		e2eskipper.SkipUnlessNodeOSDistroIs("gci", "ubuntu", "custom")
    67  
    68  		namespace = f.Namespace
    69  		c = f.ClientSet
    70  	})
    71  
    72  	////////////////////////////////////////////////////////////////////////
    73  	// NFS
    74  	////////////////////////////////////////////////////////////////////////
    75  	ginkgo.Describe("NFSv4", func() {
    76  		ginkgo.It("should be mountable for NFSv4", func(ctx context.Context) {
    77  			config, _, serverHost := e2evolume.NewNFSServer(ctx, c, namespace.Name, []string{})
    78  			ginkgo.DeferCleanup(e2evolume.TestServerCleanup, f, config)
    79  
    80  			tests := []e2evolume.Test{
    81  				{
    82  					Volume: v1.VolumeSource{
    83  						NFS: &v1.NFSVolumeSource{
    84  							Server:   serverHost,
    85  							Path:     "/",
    86  							ReadOnly: true,
    87  						},
    88  					},
    89  					File:            "index.html",
    90  					ExpectedContent: "Hello from NFS!",
    91  				},
    92  			}
    93  
    94  			// Must match content of test/images/volumes-tester/nfs/index.html
    95  			e2evolume.TestVolumeClient(ctx, f, config, nil, "" /* fsType */, tests)
    96  		})
    97  	})
    98  
    99  	ginkgo.Describe("NFSv3", func() {
   100  		ginkgo.It("should be mountable for NFSv3", func(ctx context.Context) {
   101  			config, _, serverHost := e2evolume.NewNFSServer(ctx, c, namespace.Name, []string{})
   102  			ginkgo.DeferCleanup(e2evolume.TestServerCleanup, f, config)
   103  
   104  			tests := []e2evolume.Test{
   105  				{
   106  					Volume: v1.VolumeSource{
   107  						NFS: &v1.NFSVolumeSource{
   108  							Server:   serverHost,
   109  							Path:     "/exports",
   110  							ReadOnly: true,
   111  						},
   112  					},
   113  					File:            "index.html",
   114  					ExpectedContent: "Hello from NFS!",
   115  				},
   116  			}
   117  			// Must match content of test/images/volume-tester/nfs/index.html
   118  			e2evolume.TestVolumeClient(ctx, f, config, nil, "" /* fsType */, tests)
   119  		})
   120  	})
   121  })
   122  

View as plain text