sigs.k8s.io/blob-csi-driver@v1.24.1/test/e2e/testsuites/dynamically_provisioned_read_only_volume_tester.go (about)

     1  /*
     2  Copyright 2019 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  package testsuites
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  
    23  	"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
    24  
    25  	"github.com/onsi/ginkgo/v2"
    26  	"github.com/onsi/gomega"
    27  	v1 "k8s.io/api/core/v1"
    28  	clientset "k8s.io/client-go/kubernetes"
    29  	"k8s.io/kubernetes/test/e2e/framework"
    30  )
    31  
    32  const expectedReadOnlyLog = "Read-only file system"
    33  
    34  // DynamicallyProvisionedReadOnlyVolumeTest will provision required StorageClass(es), PVC(s) and Pod(s)
    35  // Waiting for the PV provisioner to create a new PV
    36  // Testing that the Pod(s) cannot write to the volume when mounted
    37  type DynamicallyProvisionedReadOnlyVolumeTest struct {
    38  	CSIDriver              driver.DynamicPVTestDriver
    39  	Pods                   []PodDetails
    40  	StorageClassParameters map[string]string
    41  }
    42  
    43  func (t *DynamicallyProvisionedReadOnlyVolumeTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
    44  	for _, pod := range t.Pods {
    45  		tpod, cleanup := pod.SetupWithDynamicVolumes(ctx, client, namespace, t.CSIDriver, t.StorageClassParameters)
    46  		// defer must be called here for resources not get removed before using them
    47  		for i := range cleanup {
    48  			defer cleanup[i](ctx)
    49  		}
    50  
    51  		ginkgo.By("deploying the pod")
    52  		tpod.Create(ctx)
    53  		defer tpod.Cleanup(ctx)
    54  		ginkgo.By("checking that the pods command exits with an error")
    55  		tpod.WaitForFailure(ctx)
    56  		ginkgo.By("checking that pod logs contain expected message")
    57  		body, err := tpod.Logs(ctx)
    58  		framework.ExpectNoError(err, fmt.Sprintf("Error getting logs for pod %s: %v", tpod.pod.Name, err))
    59  		gomega.Expect(string(body)).To(gomega.ContainSubstring(expectedReadOnlyLog))
    60  	}
    61  }