mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Add e2e test for file exec
This commit is contained in:
parent
6be4f1bbf3
commit
8bb501bc70
@ -23,11 +23,17 @@ package testsuites
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "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/framework"
|
||||||
"k8s.io/kubernetes/test/e2e/storage/drivers"
|
"k8s.io/kubernetes/test/e2e/storage/drivers"
|
||||||
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
|
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
|
||||||
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
)
|
)
|
||||||
|
|
||||||
type volumesTestSuite struct {
|
type volumesTestSuite struct {
|
||||||
@ -91,10 +97,11 @@ func createVolumesTestInput(pattern testpatterns.TestPattern, resource genericVo
|
|||||||
}
|
}
|
||||||
|
|
||||||
return volumesTestInput{
|
return volumesTestInput{
|
||||||
f: f,
|
f: f,
|
||||||
name: dInfo.Name,
|
name: dInfo.Name,
|
||||||
config: dInfo.Config,
|
config: dInfo.Config,
|
||||||
fsGroup: fsGroup,
|
fsGroup: fsGroup,
|
||||||
|
resource: resource,
|
||||||
tests: []framework.VolumeTest{
|
tests: []framework.VolumeTest{
|
||||||
{
|
{
|
||||||
Volume: *volSource,
|
Volume: *volSource,
|
||||||
@ -140,11 +147,12 @@ func (t *volumesTestSuite) execTest(driver drivers.TestDriver, pattern testpatte
|
|||||||
}
|
}
|
||||||
|
|
||||||
type volumesTestInput struct {
|
type volumesTestInput struct {
|
||||||
f *framework.Framework
|
f *framework.Framework
|
||||||
name string
|
name string
|
||||||
config framework.VolumeTestConfig
|
config framework.VolumeTestConfig
|
||||||
fsGroup *int64
|
fsGroup *int64
|
||||||
tests []framework.VolumeTest
|
tests []framework.VolumeTest
|
||||||
|
resource genericVolumeTestResource
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVolumes(input *volumesTestInput) {
|
func testVolumes(input *volumesTestInput) {
|
||||||
@ -157,4 +165,56 @@ func testVolumes(input *volumesTestInput) {
|
|||||||
framework.InjectHtml(cs, input.config, volumeTest[0].Volume, volumeTest[0].ExpectedContent)
|
framework.InjectHtml(cs, input.config, volumeTest[0].Volume, volumeTest[0].ExpectedContent)
|
||||||
framework.TestVolumeClient(cs, input.config, input.fsGroup, input.tests)
|
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