mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Add e2e test for file exec
This commit is contained in:
parent
6be4f1bbf3
commit
8bb501bc70
@ -23,11 +23,17 @@ package testsuites
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
"k8s.io/kubernetes/test/e2e/storage/drivers"
|
||||
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
)
|
||||
|
||||
type volumesTestSuite struct {
|
||||
@ -91,10 +97,11 @@ func createVolumesTestInput(pattern testpatterns.TestPattern, resource genericVo
|
||||
}
|
||||
|
||||
return volumesTestInput{
|
||||
f: f,
|
||||
name: dInfo.Name,
|
||||
config: dInfo.Config,
|
||||
fsGroup: fsGroup,
|
||||
f: f,
|
||||
name: dInfo.Name,
|
||||
config: dInfo.Config,
|
||||
fsGroup: fsGroup,
|
||||
resource: resource,
|
||||
tests: []framework.VolumeTest{
|
||||
{
|
||||
Volume: *volSource,
|
||||
@ -140,11 +147,12 @@ func (t *volumesTestSuite) execTest(driver drivers.TestDriver, pattern testpatte
|
||||
}
|
||||
|
||||
type volumesTestInput struct {
|
||||
f *framework.Framework
|
||||
name string
|
||||
config framework.VolumeTestConfig
|
||||
fsGroup *int64
|
||||
tests []framework.VolumeTest
|
||||
f *framework.Framework
|
||||
name string
|
||||
config framework.VolumeTestConfig
|
||||
fsGroup *int64
|
||||
tests []framework.VolumeTest
|
||||
resource genericVolumeTestResource
|
||||
}
|
||||
|
||||
func testVolumes(input *volumesTestInput) {
|
||||
@ -157,4 +165,56 @@ func testVolumes(input *volumesTestInput) {
|
||||
framework.InjectHtml(cs, input.config, volumeTest[0].Volume, volumeTest[0].ExpectedContent)
|
||||
framework.TestVolumeClient(cs, input.config, input.fsGroup, input.tests)
|
||||
})
|
||||
It("should allow exec of files on the volume", func() {
|
||||
f := input.f
|
||||
defer framework.VolumeTestCleanup(f, input.config)
|
||||
|
||||
testScriptInPod(f, input.resource.volType, input.resource.volSource)
|
||||
})
|
||||
}
|
||||
|
||||
func testScriptInPod(f *framework.Framework, volumeType string, source *v1.VolumeSource) {
|
||||
const (
|
||||
volPath = "/vol1"
|
||||
volName = "vol1"
|
||||
)
|
||||
suffix := generateSuffixForPodName(volumeType)
|
||||
scriptName := fmt.Sprintf("test-%s.sh", suffix)
|
||||
fullPath := filepath.Join(volPath, scriptName)
|
||||
cmd := fmt.Sprintf("echo \"ls %s\" > %s; chmod u+x %s; %s", volPath, fullPath, fullPath, fullPath)
|
||||
|
||||
pod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fmt.Sprintf("exec-volume-test-%s", suffix),
|
||||
Namespace: f.Namespace.Name,
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: fmt.Sprintf("exec-container-%s", suffix),
|
||||
Image: imageutils.GetE2EImage(imageutils.Nginx),
|
||||
Command: []string{"/bin/sh", "-ec", cmd},
|
||||
VolumeMounts: []v1.VolumeMount{
|
||||
{
|
||||
Name: volName,
|
||||
MountPath: volPath,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Volumes: []v1.Volume{
|
||||
{
|
||||
Name: volName,
|
||||
VolumeSource: *source,
|
||||
},
|
||||
},
|
||||
RestartPolicy: v1.RestartPolicyNever,
|
||||
},
|
||||
}
|
||||
By(fmt.Sprintf("Creating pod %s", pod.Name))
|
||||
f.TestContainerOutput("exec-volume-test", pod, 0, []string{scriptName})
|
||||
|
||||
By(fmt.Sprintf("Deleting pod %s", pod.Name))
|
||||
err := framework.DeletePodWithWait(f, f.ClientSet, pod)
|
||||
Expect(err).NotTo(HaveOccurred(), "while deleting pod")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user