kubernetesk8s.io/kubernetes/test/e2e/storage/utils Index | Files

package utils

import "k8s.io/kubernetes/test/e2e/storage/utils"

Index

Constants

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"
)
const (
	// VolumeGroupSnapshot is the group snapshot api
	VolumeGroupSnapshotAPIGroup = "groupsnapshot.storage.k8s.io"
	// VolumeGroupSnapshotAPIVersion is the group snapshot api version
	VolumeGroupSnapshotAPIVersion = "groupsnapshot.storage.k8s.io/v1beta1"
)

Variables

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"}
)
var (

	// VolumeGroupSnapshotGVR is GroupVersionResource for volumegroupsnapshots
	VolumeGroupSnapshotGVR = schema.GroupVersionResource{Group: VolumeGroupSnapshotAPIGroup, Version: "v1beta1", Resource: "volumegroupsnapshots"}
	// VolumeGroupSnapshotClassGVR is GroupVersionResource for volumegroupsnapshotsclasses
	VolumeGroupSnapshotClassGVR   = schema.GroupVersionResource{Group: VolumeGroupSnapshotAPIGroup, Version: "v1beta1", Resource: "volumegroupsnapshotclasses"}
	VolumeGroupSnapshotContentGVR = schema.GroupVersionResource{Group: VolumeGroupSnapshotAPIGroup, Version: "v1beta1", Resource: "volumegroupsnapshotcontents"}
)
var SIGDescribe = framework.SIGDescribe("storage")

SIGDescribe annotates the test with the SIG label.

Functions

func ChangeFilePathGIDInPod

func ChangeFilePathGIDInPod(ctx context.Context, f *framework.Framework, filePath, targetGID string, pod *v1.Pod)

ChangeFilePathGIDInPod changes the GID of the target filepath.

func CheckReadFromPath

func CheckReadFromPath(ctx context.Context, 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

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

CheckReadWriteToPath check that path can b e read and written

func CheckWriteToPath

func CheckWriteToPath(ctx context.Context, 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

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

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

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

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

CreateVolumeSource creates a volume source object

func DeleteAndWaitSnapshot

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

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

DeleteSnapshotWithoutWaiting deletes a VolumeSnapshot and return directly without waiting

func DeleteStorageClass

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 EnsureGVRDeletion

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

EnsureGVRDeletion checks that no object as defined by the group/version/kind and name is ever found during the given time period

func EnsureNoGVRDeletion

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

EnsureNoGVRDeletion checks that an object as defined by the group/version/kind and name has not been deleted during the given time period

func FindVolumeGlobalMountPoints

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

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 GenerateVolumeGroupSnapshotClassSpec

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

func GetSectorSize

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

GetSectorSize returns the sector size of the device.

func GetSizeRangesIntersection

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

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.. Allowed kubeletOps are `KStart`, `KStop`, and `KRestart`

func LoadFromManifests

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

func LogResult(result Result)

LogResult records result log

func PatchCSIDeployment

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:

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

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

func PatchItems

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

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

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

func PatchNamespace

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

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

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

StartExternalProvisioner create external provisioner pod

func StartPodLogs

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

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

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

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

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

func TryFunc(f func()) error

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

func VerifyFSGroupInPod

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

VerifyFSGroupInPod verifies that the passed in filePath contains the expectedFSGroup

func VerifyFilePathGIDInPod

func VerifyFilePathGIDInPod(ctx context.Context, f *framework.Framework, filePath, expectedGID string, pod *v1.Pod)

VerifyFilePathGIDInPod verfies expected GID of the target filepath

func WaitForGVRDeletion

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

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

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

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 WaitForVolumeGroupSnapshotReady

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

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

func WaitUntil

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

WaitUntil runs checkDone until a timeout is reached

Types

type HostExec

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

func NewHostExec(framework *framework.Framework) HostExec

NewHostExec returns a HostExec

type ItemFactory

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

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

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

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

NewLocalResourceManager returns a instance of LocalTestResourceManager

type LocalVolumeType

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

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

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

Result holds the execution result of remote execution command.

type What

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

func (in *What) DeepCopy() *What

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

func (*What) DeepCopyInto

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

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

func (*What) DeepCopyObject

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

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

func (*What) GetObjectKind

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

GetObjectKind returns the ObjectKind schema

Source Files

create.go deployment.go framework.go host_exec.go local.go pod.go snapshot.go utils.go volume_group_snapshot.go

Version
v1.33.0 (latest)
Published
Apr 23, 2025
Platform
linux/amd64
Imports
47 packages
Last checked
5 hours ago

Tools for package owners.