mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Merge pull request #112390 from pohly/e2e-storage-helpers
e2e storage: update helpers
This commit is contained in:
commit
eedf0ed221
@ -18,6 +18,7 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
"k8s.io/kubernetes/test/e2e/storage/drivers/csi-test/mock/service"
|
"k8s.io/kubernetes/test/e2e/storage/drivers/csi-test/mock/service"
|
||||||
@ -37,7 +38,7 @@ func (p PodDirIO) DirExists(path string) (bool, error) {
|
|||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
fmt.Sprintf("if ! [ -e '%s' ]; then echo notexist; elif [ -d '%s' ]; then echo dir; else echo nodir; fi", path, path),
|
fmt.Sprintf("if ! [ -e '%s' ]; then echo notexist; elif [ -d '%s' ]; then echo dir; else echo nodir; fi", path, path),
|
||||||
})
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("error executing dir test commands: stderr=%q, %v", stderr, err)
|
return false, fmt.Errorf("error executing dir test commands: stderr=%q, %v", stderr, err)
|
||||||
}
|
}
|
||||||
@ -54,27 +55,36 @@ func (p PodDirIO) DirExists(path string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p PodDirIO) Mkdir(path string) error {
|
func (p PodDirIO) Mkdir(path string) error {
|
||||||
_, stderr, err := p.execute([]string{"mkdir", path})
|
_, stderr, err := p.execute([]string{"mkdir", path}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("mkdir %q: stderr=%q, %v", path, stderr, err)
|
return fmt.Errorf("mkdir %q: stderr=%q, %v", path, stderr, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p PodDirIO) CreateFile(path string, content io.Reader) error {
|
||||||
|
_, stderr, err := p.execute([]string{"dd", "of=" + path}, content)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("dd of=%s: stderr=%q, %v", path, stderr, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p PodDirIO) RemoveAll(path string) error {
|
func (p PodDirIO) RemoveAll(path string) error {
|
||||||
_, stderr, err := p.execute([]string{"rm", "-rf", path})
|
_, stderr, err := p.execute([]string{"rm", "-rf", path}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("rm -rf %q: stderr=%q, %v", path, stderr, err)
|
return fmt.Errorf("rm -rf %q: stderr=%q, %v", path, stderr, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PodDirIO) execute(command []string) (string, string, error) {
|
func (p PodDirIO) execute(command []string, stdin io.Reader) (string, string, error) {
|
||||||
return p.F.ExecWithOptions(framework.ExecOptions{
|
return p.F.ExecWithOptions(framework.ExecOptions{
|
||||||
Command: command,
|
Command: command,
|
||||||
Namespace: p.Namespace,
|
Namespace: p.Namespace,
|
||||||
PodName: p.PodName,
|
PodName: p.PodName,
|
||||||
ContainerName: p.ContainerName,
|
ContainerName: p.ContainerName,
|
||||||
|
Stdin: stdin,
|
||||||
CaptureStdout: true,
|
CaptureStdout: true,
|
||||||
CaptureStderr: true,
|
CaptureStderr: true,
|
||||||
Quiet: true,
|
Quiet: true,
|
||||||
|
@ -275,6 +275,7 @@ var factories = map[What]ItemFactory{
|
|||||||
{"ClusterRoleBinding"}: &clusterRoleBindingFactory{},
|
{"ClusterRoleBinding"}: &clusterRoleBindingFactory{},
|
||||||
{"CSIDriver"}: &csiDriverFactory{},
|
{"CSIDriver"}: &csiDriverFactory{},
|
||||||
{"DaemonSet"}: &daemonSetFactory{},
|
{"DaemonSet"}: &daemonSetFactory{},
|
||||||
|
{"ReplicaSet"}: &replicaSetFactory{},
|
||||||
{"Role"}: &roleFactory{},
|
{"Role"}: &roleFactory{},
|
||||||
{"RoleBinding"}: &roleBindingFactory{},
|
{"RoleBinding"}: &roleBindingFactory{},
|
||||||
{"Secret"}: &secretFactory{},
|
{"Secret"}: &secretFactory{},
|
||||||
@ -382,6 +383,14 @@ func patchItemRecursively(f *framework.Framework, driverNamespace *v1.Namespace,
|
|||||||
if err := patchContainerImages(item.Spec.Template.Spec.InitContainers); err != nil {
|
if err := patchContainerImages(item.Spec.Template.Spec.InitContainers); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
case *appsv1.ReplicaSet:
|
||||||
|
PatchNamespace(f, driverNamespace, &item.ObjectMeta.Namespace)
|
||||||
|
if err := patchContainerImages(item.Spec.Template.Spec.Containers); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := patchContainerImages(item.Spec.Template.Spec.InitContainers); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
case *apiextensionsv1.CustomResourceDefinition:
|
case *apiextensionsv1.CustomResourceDefinition:
|
||||||
// Do nothing. Patching name to all CRDs won't always be the expected behavior.
|
// Do nothing. Patching name to all CRDs won't always be the expected behavior.
|
||||||
default:
|
default:
|
||||||
@ -584,6 +593,27 @@ func (*daemonSetFactory) Create(f *framework.Framework, ns *v1.Namespace, i inte
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type replicaSetFactory struct{}
|
||||||
|
|
||||||
|
func (f *replicaSetFactory) New() runtime.Object {
|
||||||
|
return &appsv1.ReplicaSet{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*replicaSetFactory) Create(f *framework.Framework, ns *v1.Namespace, i interface{}) (func() error, error) {
|
||||||
|
item, ok := i.(*appsv1.ReplicaSet)
|
||||||
|
if !ok {
|
||||||
|
return nil, errorItemNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
client := f.ClientSet.AppsV1().ReplicaSets(ns.Name)
|
||||||
|
if _, err := client.Create(context.TODO(), item, metav1.CreateOptions{}); err != nil {
|
||||||
|
return nil, fmt.Errorf("create ReplicaSet: %w", err)
|
||||||
|
}
|
||||||
|
return func() error {
|
||||||
|
return client.Delete(context.TODO(), item.GetName(), metav1.DeleteOptions{})
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
type storageClassFactory struct{}
|
type storageClassFactory struct{}
|
||||||
|
|
||||||
func (f *storageClassFactory) New() runtime.Object {
|
func (f *storageClassFactory) New() runtime.Object {
|
||||||
|
Loading…
Reference in New Issue
Block a user