utils

package
v1.29.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 46 Imported by: 109

Documentation

Index

Constants

View Source
const (
	// SnapshotGroup is the snapshot CRD api group
	SnapshotGroup = "snapshot.storage.k8s.io"
	// SnapshotAPIVersion is the snapshot CRD api version
	SnapshotAPIVersion = "snapshot.storage.k8s.io/v1"
)

Variables

View Source
var (
	// SnapshotGVR is GroupVersionResource for volumesnapshots
	SnapshotGVR = schema.GroupVersionResource{Group: SnapshotGroup, Version: "v1", Resource: "volumesnapshots"}
	// SnapshotClassGVR is GroupVersionResource for volumesnapshotclasses
	SnapshotClassGVR = schema.GroupVersionResource{Group: SnapshotGroup, Version: "v1", Resource: "volumesnapshotclasses"}
	// SnapshotContentGVR is GroupVersionResource for volumesnapshotcontents
	SnapshotContentGVR = schema.GroupVersionResource{Group: SnapshotGroup, Version: "v1", Resource: "volumesnapshotcontents"}
)
View Source
var SIGDescribe = framework.SIGDescribe("storage")

SIGDescribe annotates the test with the SIG label.

Functions

func ChangeFilePathGidInPod added in v1.20.0

func ChangeFilePathGidInPod(f *framework.Framework, filePath, targetGid string, pod *v1.Pod)

ChangeFilePathGidInPod changes the GID of the target filepath.

func CheckReadFromPath added in v1.15.0

func CheckReadFromPath(f *framework.Framework, pod *v1.Pod, volMode v1.PersistentVolumeMode, directIO bool, path string, len int, seed int64)

CheckReadFromPath validate that file can be properly read.

Note: directIO does not work with (default) BusyBox Pods. A requirement for directIO to function correctly, is to read whole sector(s) for Block-mode PVCs (normally a sector is 512 bytes), or memory pages for files (commonly 4096 bytes).

func CheckReadWriteToPath added in v1.12.8

func CheckReadWriteToPath(f *framework.Framework, pod *v1.Pod, volMode v1.PersistentVolumeMode, path string)

CheckReadWriteToPath check that path can b e read and written

func CheckWriteToPath added in v1.15.0

func CheckWriteToPath(f *framework.Framework, pod *v1.Pod, volMode v1.PersistentVolumeMode, nocache bool, path string, len int, seed int64)

CheckWriteToPath that file can be properly written.

Note: nocache does not work with (default) BusyBox Pods. To read without caching, enable directIO with CheckReadFromPath and check the hints about the len requirements.

func CreateDriverNamespace added in v1.19.0

func CreateDriverNamespace(ctx context.Context, f *framework.Framework) *v1.Namespace

CreateDriverNamespace creates a namespace for CSI driver installation. The namespace is still tracked and ensured that gets deleted when test terminates.

func CreateFromManifests added in v1.17.0

func CreateFromManifests(ctx context.Context, f *framework.Framework, driverNamespace *v1.Namespace, patch func(item interface{}) error, files ...string) error

CreateFromManifests is a combination of LoadFromManifests, PatchItems, patching with an optional custom function, and CreateItems.

func CreateItems added in v1.17.0

func CreateItems(ctx context.Context, f *framework.Framework, ns *v1.Namespace, items ...interface{}) error

CreateItems creates the items. Each of them must be an API object of a type that is registered in Factory.

It returns either a cleanup function or an error, but never both.

Cleaning up after a test can be triggered in two ways:

PatchItems has the some limitations as LoadFromManifests: - only some common items are supported, unknown ones trigger an error - only the latest stable API version for each item is supported

func CreateVolumeSource added in v1.21.0

func CreateVolumeSource(pvcName string, readOnly bool) *v1.VolumeSource

CreateVolumeSource creates a volume source object

func DeleteAndWaitSnapshot added in v1.21.0

func DeleteAndWaitSnapshot(ctx context.Context, dc dynamic.Interface, ns string, snapshotName string, poll, timeout time.Duration) error

DeleteAndWaitSnapshot deletes a VolumeSnapshot and waits for it to be deleted or until timeout occurs, whichever comes first

func DeleteSnapshotWithoutWaiting added in v1.21.0

func DeleteSnapshotWithoutWaiting(ctx context.Context, dc dynamic.Interface, ns string, snapshotName string) error

DeleteSnapshotWithoutWaiting deletes a VolumeSnapshot and return directly without waiting

func DeleteStorageClass added in v1.21.0

func DeleteStorageClass(ctx context.Context, cs clientset.Interface, className string) error

DeleteStorageClass deletes the passed in StorageClass and catches errors other than "Not Found"

func FindVolumeGlobalMountPoints added in v1.17.0

func FindVolumeGlobalMountPoints(ctx context.Context, hostExec HostExec, node *v1.Node) sets.String

FindVolumeGlobalMountPoints returns all volume global mount points on the node of given pod.

func GenerateSnapshotClassSpec added in v1.21.0

func GenerateSnapshotClassSpec(
	snapshotter string,
	parameters map[string]string,
	ns string,
) *unstructured.Unstructured

GenerateSnapshotClassSpec constructs a new SnapshotClass instance spec with a unique name that is based on namespace + suffix.

func GetSectorSize added in v1.22.0

func GetSectorSize(f *framework.Framework, pod *v1.Pod, device string) int

GetSectorSize returns the sector size of the device.

func GetSizeRangesIntersection added in v1.21.0

func GetSizeRangesIntersection(first e2evolume.SizeRange, second e2evolume.SizeRange) (string, error)

GetSizeRangesIntersection takes two instances of storage size ranges and determines the intersection of the intervals (if it exists) and return the minimum of the intersection to be used as the claim size for the test. if value not set, that means there's no minimum or maximum size limitation and we set default size for it.

func GetSnapshotContentFromSnapshot added in v1.21.0

func GetSnapshotContentFromSnapshot(ctx context.Context, dc dynamic.Interface, snapshot *unstructured.Unstructured, timeout time.Duration) *unstructured.Unstructured

GetSnapshotContentFromSnapshot returns the VolumeSnapshotContent object Bound to a given VolumeSnapshot

func KubeletCommand

func KubeletCommand(ctx context.Context, kOp KubeletOpt, c clientset.Interface, pod *v1.Pod)

KubeletCommand performs `start`, `restart`, or `stop` on the kubelet running on the node of the target pod and waits for the desired statues.. - First issues the command via `systemctl` - If `systemctl` returns stderr "command not found, issues the command via `service` - If `service` also returns stderr "command not found", the test is aborted. Allowed kubeletOps are `KStart`, `KStop`, and `KRestart`

func LoadFromManifests added in v1.17.0

func LoadFromManifests(files ...string) ([]interface{}, error)

LoadFromManifests loads .yaml or .json manifest files and returns all items that it finds in them. It supports all items for which there is a factory registered in factories and .yaml files with multiple items separated by "---". Files are accessed via the "testfiles" package, which means they can come from a file system or be built into the binary.

LoadFromManifests has some limitations:

func LogResult added in v1.17.0

func LogResult(result Result)

LogResult records result log

func PatchCSIDeployment added in v1.13.0

func PatchCSIDeployment(f *e2eframework.Framework, o PatchCSIOptions, object interface{}) error

PatchCSIDeployment modifies the CSI driver deployment: - replaces the provisioner name - forces pods onto a specific host

All of that is optional, see PatchCSIOptions. Just beware that not renaming the CSI driver deployment can be problematic:

  • when multiple tests deploy the driver, they need to run sequentially
  • might conflict with manual deployments

This function is written so that it works for CSI driver deployments that follow these conventions:

  • driver and provisioner names are identical
  • the driver binary accepts a --drivername parameter
  • the paths inside the container are either fixed and don't need to be patch (for example, --csi-address=/csi/csi.sock is okay) or are specified directly in a parameter (for example, --kubelet-registration-path=/var/lib/kubelet/plugins/csi-hostpath/csi.sock)

Driver deployments that are different will have to do the patching without this function, or skip patching entirely.

func PatchItems added in v1.17.0

func PatchItems(f *framework.Framework, driverNamespace *v1.Namespace, items ...interface{}) error

PatchItems modifies the given items in place such that each test gets its own instances, to avoid conflicts between different tests and between tests and normal deployments.

This is done by: - creating namespaced items inside the test's namespace - changing the name of non-namespaced items like ClusterRole

PatchItems has some limitations: - only some common items are supported, unknown ones trigger an error - only the latest stable API version for each item is supported

func PatchName added in v1.17.0

func PatchName(f *framework.Framework, item *string)

PatchName makes the name of some item unique by appending the generated unique name.

func PatchNamespace added in v1.17.0

func PatchNamespace(f *framework.Framework, driverNamespace *v1.Namespace, item *string)

PatchNamespace moves the item into the test's namespace. Not all items can be namespaced. For those, the name also needs to be patched.

func PrettyPrint added in v1.17.0

func PrettyPrint(item interface{}) string

PrettyPrint returns a human-readable representation of an item.

func RunInPodWithVolume

func RunInPodWithVolume(ctx context.Context, c clientset.Interface, t *framework.TimeoutContext, ns, claimName, command string)

RunInPodWithVolume runs a command in a pod with given claim mounted to /mnt directory.

func StartExternalProvisioner added in v1.12.0

func StartExternalProvisioner(ctx context.Context, c clientset.Interface, ns string, externalPluginName string) *v1.Pod

StartExternalProvisioner create external provisioner pod

func StartPodLogs added in v1.21.0

func StartPodLogs(ctx context.Context, f *framework.Framework, driverNamespace *v1.Namespace) func()

StartPodLogs begins capturing log output and events from current and future pods running in the namespace of the framework. That ends when the returned cleanup function is called.

The output goes to log files (when using --report-dir, as in the CI) or the output stream (otherwise).

func TestKubeletRestartsAndRestoresMap added in v1.16.0

func TestKubeletRestartsAndRestoresMap(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, volumePath string)

TestKubeletRestartsAndRestoresMap tests that a volume mapped to a pod remains mapped after a kubelet restarts

func TestKubeletRestartsAndRestoresMount

func TestKubeletRestartsAndRestoresMount(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, volumePath string)

TestKubeletRestartsAndRestoresMount tests that a volume mounted to a pod remains mounted after a kubelet restarts

func TestVolumeUnmapsFromDeletedPod added in v1.16.0

func TestVolumeUnmapsFromDeletedPod(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, devicePath string)

TestVolumeUnmapsFromDeletedPod tests that a volume unmaps if the client pod was deleted while the kubelet was down.

func TestVolumeUnmapsFromDeletedPodWithForceOption added in v1.16.0

func TestVolumeUnmapsFromDeletedPodWithForceOption(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, forceDelete bool, devicePath string)

TestVolumeUnmapsFromDeletedPodWithForceOption tests that a volume unmaps if the client pod was deleted while the kubelet was down. forceDelete is true indicating whether the pod is forcefully deleted.

func TestVolumeUnmapsFromForceDeletedPod added in v1.16.0

func TestVolumeUnmapsFromForceDeletedPod(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, devicePath string)

TestVolumeUnmapsFromForceDeletedPod tests that a volume unmaps if the client pod was forcefully deleted while the kubelet was down.

func TestVolumeUnmountsFromDeletedPod

func TestVolumeUnmountsFromDeletedPod(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, volumePath string)

TestVolumeUnmountsFromDeletedPod tests that a volume unmounts if the client pod was deleted while the kubelet was down.

func TestVolumeUnmountsFromDeletedPodWithForceOption

func TestVolumeUnmountsFromDeletedPodWithForceOption(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, forceDelete bool, checkSubpath bool, secondPod *v1.Pod, volumePath string)

TestVolumeUnmountsFromDeletedPodWithForceOption tests that a volume unmounts if the client pod was deleted while the kubelet was down. forceDelete is true indicating whether the pod is forcefully deleted. checkSubpath is true indicating whether the subpath should be checked. If secondPod is set, it is started when kubelet is down to check that the volume is usable while the old pod is being deleted and the new pod is starting.

func TestVolumeUnmountsFromForceDeletedPod

func TestVolumeUnmountsFromForceDeletedPod(ctx context.Context, c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, volumePath string)

TestVolumeUnmountsFromForceDeletedPod tests that a volume unmounts if the client pod was forcefully deleted while the kubelet was down.

func TryFunc added in v1.21.0

func TryFunc(f func()) error

TryFunc try to execute the function and return err if there is any

func VerifyFSGroupInPod added in v1.20.0

func VerifyFSGroupInPod(f *framework.Framework, filePath, expectedFSGroup string, pod *v1.Pod)

VerifyFSGroupInPod verifies that the passed in filePath contains the expectedFSGroup

func VerifyFilePathGidInPod added in v1.20.0

func VerifyFilePathGidInPod(f *framework.Framework, filePath, expectedGid string, pod *v1.Pod)

VerifyFilePathGidInPod verfies expected GID of the target filepath

func WaitForGVRDeletion added in v1.19.0

func WaitForGVRDeletion(ctx context.Context, c dynamic.Interface, gvr schema.GroupVersionResource, objectName string, poll, timeout time.Duration) error

WaitForGVRDeletion waits until a non-namespaced object has been deleted

func WaitForGVRFinalizer added in v1.20.0

func WaitForGVRFinalizer(ctx context.Context, c dynamic.Interface, gvr schema.GroupVersionResource, objectName, objectNamespace, finalizer string, poll, timeout time.Duration) error

WaitForGVRFinalizer waits until a object from a given GVR contains a finalizer If namespace is empty, assume it is a non-namespaced object

func WaitForNamespacedGVRDeletion added in v1.19.9

func WaitForNamespacedGVRDeletion(ctx context.Context, c dynamic.Interface, gvr schema.GroupVersionResource, ns, objectName string, poll, timeout time.Duration) error

WaitForNamespacedGVRDeletion waits until a namespaced object has been deleted

func WaitForSnapshotReady added in v1.21.0

func WaitForSnapshotReady(ctx context.Context, c dynamic.Interface, ns string, snapshotName string, poll, timeout time.Duration) error

WaitForSnapshotReady waits for a VolumeSnapshot to be ready to use or until timeout occurs, whichever comes first.

func WaitUntil added in v1.19.0

func WaitUntil(poll, timeout time.Duration, checkDone func() bool) bool

WaitUntil runs checkDone until a timeout is reached

Types

type HostExec added in v1.14.0

type HostExec interface {
	Execute(ctx context.Context, cmd string, node *v1.Node) (Result, error)
	IssueCommandWithResult(ctx context.Context, cmd string, node *v1.Node) (string, error)
	IssueCommand(ctx context.Context, cmd string, node *v1.Node) error
	Cleanup(ctx context.Context)
}

HostExec represents interface we require to execute commands on remote host.

func NewHostExec added in v1.14.0

func NewHostExec(framework *framework.Framework) HostExec

NewHostExec returns a HostExec

type ItemFactory added in v1.17.0

type ItemFactory interface {
	// New returns a new empty item.
	New() runtime.Object

	// Create is responsible for creating the item. It returns an
	// error or a cleanup function for the created item.
	// If the item is of an unsupported type, it must return
	// an error that has errorItemNotSupported as cause.
	Create(ctx context.Context, f *framework.Framework, ns *v1.Namespace, item interface{}) (func(ctx context.Context) error, error)
}

ItemFactory provides support for creating one particular item. The type gets exported because other packages might want to extend the set of pre-defined factories.

type KubeletOpt

type KubeletOpt string

KubeletOpt type definition

const (
	// NodeStateTimeout defines Timeout
	NodeStateTimeout = 1 * time.Minute
	// KStart defines start value
	KStart KubeletOpt = "start"
	// KStop defines stop value
	KStop KubeletOpt = "stop"
	// KRestart defines restart value
	KRestart KubeletOpt = "restart"
)

type LocalTestResource added in v1.14.0

type LocalTestResource struct {
	VolumeType LocalVolumeType
	Node       *v1.Node
	// Volume path, path to filesystem or block device on the node
	Path string
	// contains filtered or unexported fields
}

LocalTestResource represents test resource of a local volume.

type LocalTestResourceManager added in v1.14.0

type LocalTestResourceManager interface {
	Create(ctx context.Context, node *v1.Node, volumeType LocalVolumeType, parameters map[string]string) *LocalTestResource
	ExpandBlockDevice(ctx context.Context, ltr *LocalTestResource, mbToAdd int) error
	Remove(ctx context.Context, ltr *LocalTestResource)
}

LocalTestResourceManager represents interface to create/destroy local test resources on node

func NewLocalResourceManager added in v1.14.0

func NewLocalResourceManager(prefix string, hostExec HostExec, hostBase string) LocalTestResourceManager

NewLocalResourceManager returns a instance of LocalTestResourceManager

type LocalVolumeType added in v1.14.0

type LocalVolumeType string

LocalVolumeType represents type of local volume, e.g. tmpfs, directory, block, etc.

const (
	// LocalVolumeDirectory reprensents a simple directory as local volume
	LocalVolumeDirectory LocalVolumeType = "dir"
	// LocalVolumeDirectoryLink is like LocalVolumeDirectory but it's a symbolic link to directory
	LocalVolumeDirectoryLink LocalVolumeType = "dir-link"
	// LocalVolumeDirectoryBindMounted is like LocalVolumeDirectory but bind mounted
	LocalVolumeDirectoryBindMounted LocalVolumeType = "dir-bindmounted"
	// LocalVolumeDirectoryLinkBindMounted is like LocalVolumeDirectory but it's a symbolic link to self bind mounted directory
	// Note that bind mounting at symbolic link actually mounts at directory it
	// links to
	LocalVolumeDirectoryLinkBindMounted LocalVolumeType = "dir-link-bindmounted"
	// LocalVolumeTmpfs represents a temporary filesystem to be used as local volume
	LocalVolumeTmpfs LocalVolumeType = "tmpfs"
	// LocalVolumeBlock represents a Block device, creates a local file, and maps it as a block device
	LocalVolumeBlock LocalVolumeType = "block"
	// LocalVolumeBlockFS represents a filesystem backed by a block device
	LocalVolumeBlockFS LocalVolumeType = "blockfs"
	// LocalVolumeGCELocalSSD represents a Filesystem backed by GCE Local SSD as local volume
	LocalVolumeGCELocalSSD LocalVolumeType = "gce-localssd-scsi-fs"
)

type PatchCSIOptions added in v1.13.0

type PatchCSIOptions struct {
	// The original driver name.
	OldDriverName string
	// The driver name that replaces the original name.
	// Can be empty (not used at all) or equal to OldDriverName
	// (then it will be added were appropriate without renaming
	// in existing fields).
	NewDriverName string
	// The name of the container which has the CSI driver binary.
	// If non-empty, DriverContainerArguments are added to argument
	// list in container with that name.
	DriverContainerName string
	// List of arguments to add to container with
	// DriverContainerName.
	DriverContainerArguments []string
	// The name of the container which has the provisioner binary.
	// If non-empty, --provisioner with new name will be appended
	// to the argument list.
	ProvisionerContainerName string
	// The name of the container which has the snapshotter binary.
	// If non-empty, --snapshotter with new name will be appended
	// to the argument list.
	SnapshotterContainerName string
	// If non-empty, all pods are forced to run on this node.
	NodeName string
	// If not nil, the value to use for the CSIDriver.Spec.PodInfo
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	PodInfo *bool
	// If not nil, the value to use for the CSIDriver.Spec.CanAttach
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	CanAttach *bool
	// If not nil, the value to use for the CSIDriver.Spec.StorageCapacity
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	StorageCapacity *bool
	// If not nil, the value to use for the CSIDriver.Spec.VolumeLifecycleModes
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	VolumeLifecycleModes *[]storagev1.VolumeLifecycleMode
	// If not nil, the value to use for the CSIDriver.Spec.TokenRequests
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	TokenRequests []storagev1.TokenRequest
	// If not nil, the value to use for the CSIDriver.Spec.RequiresRepublish
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	RequiresRepublish *bool
	// If not nil, the value to use for the CSIDriver.Spec.FSGroupPolicy
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	FSGroupPolicy *storagev1.FSGroupPolicy
	// If not nil, the value to use for the CSIDriver.Spec.SELinuxMount
	// field *if* the driver deploys a CSIDriver object. Ignored
	// otherwise.
	SELinuxMount *bool
	// If not nil, the values will be used for setting feature arguments to
	// specific sidecar.
	// Feature is a map - where key is sidecar name such as:
	//	-- key: resizer
	//	-- value: []string{feature-gates}
	Features map[string][]string
}

PatchCSIOptions controls how PatchCSIDeployment patches the objects.

type Result added in v1.17.0

type Result struct {
	Host   string
	Cmd    string
	Stdout string
	Stderr string
	Code   int
}

Result holds the execution result of remote execution command.

type What added in v1.17.0

type What struct {
	Kind string `json:"kind"`
}

What is a subset of metav1.TypeMeta which (in contrast to metav1.TypeMeta itself) satisfies the runtime.Object interface.

func (*What) DeepCopy added in v1.17.0

func (in *What) DeepCopy() *What

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new What.

func (*What) DeepCopyInto added in v1.17.0

func (in *What) DeepCopyInto(out *What)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out.

func (*What) DeepCopyObject added in v1.17.0

func (in *What) DeepCopyObject() runtime.Object

DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.

func (*What) GetObjectKind added in v1.17.0

func (in *What) GetObjectKind() schema.ObjectKind

GetObjectKind returns the ObjectKind schema

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL