utils

package
v1.22.0-alpha.0...-9444b71 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 45 Imported by: 0

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

Functions

func ChangeFilePathGidInPod

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

ChangeFilePathGidInPod changes the GID of the target filepath.

func CheckReadFromPath

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

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

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

func CreateDriverNamespace(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(f *framework.Framework, driverNamespace *v1.Namespace, patch func(item interface{}) error, files ...string) (func(), error)

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

func CreateItems

func CreateItems(f *framework.Framework, ns *v1.Namespace, items ...interface{}) (func(), 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(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(dc dynamic.Interface, ns string, snapshotName string) error

DeleteSnapshotWithoutWaiting deletes a VolumeSnapshot and return directly without waiting

func DeleteStorageClass

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

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

func FindVolumeGlobalMountPoints

func FindVolumeGlobalMountPoints(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,
	suffix string,
) *unstructured.Unstructured

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

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(dc dynamic.Interface, snapshot *unstructured.Unstructured) *unstructured.Unstructured

GetSnapshotContentFromSnapshot returns the VolumeSnapshotContent object Bound to a given VolumeSnapshot

func KubeletCommand

func KubeletCommand(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

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 *framework.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

func PatchItems(f *framework.Framework, driverNamspace *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 PrivilegedTestPSPClusterRoleBinding

func PrivilegedTestPSPClusterRoleBinding(client clientset.Interface,
	namespace string,
	teardown bool,
	saNames []string)

PrivilegedTestPSPClusterRoleBinding test Pod Security Policy Role bindings

func RunInPodWithVolume

func RunInPodWithVolume(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 SIGDescribe

func SIGDescribe(text string, body func()) bool

SIGDescribe annotates the test with the SIG label.

func StartExternalProvisioner

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

StartExternalProvisioner create external provisioner pod

func StartPodLogs

func StartPodLogs(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(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod)

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

func TestKubeletRestartsAndRestoresMount

func TestKubeletRestartsAndRestoresMount(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod)

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

func TestVolumeUnmapsFromDeletedPod

func TestVolumeUnmapsFromDeletedPod(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod)

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

func TestVolumeUnmapsFromDeletedPodWithForceOption

func TestVolumeUnmapsFromDeletedPodWithForceOption(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, forceDelete bool)

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(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod)

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

func TestVolumeUnmountsFromDeletedPod

func TestVolumeUnmountsFromDeletedPod(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod)

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

func TestVolumeUnmountsFromDeletedPodWithForceOption

func TestVolumeUnmountsFromDeletedPodWithForceOption(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod, forceDelete bool, checkSubpath bool)

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.

func TestVolumeUnmountsFromForceDeletedPod

func TestVolumeUnmountsFromForceDeletedPod(c clientset.Interface, f *framework.Framework, clientPod *v1.Pod)

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(f *framework.Framework, filePath, expectedFSGroup string, pod *v1.Pod)

VerifyFSGroupInPod verifies that the passed in filePath contains the expectedFSGroup

func VerifyFilePathGidInPod

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

VerifyFilePathGidInPod verfies expected GID of the target filepath

func WaitForGVRDeletion

func WaitForGVRDeletion(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(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(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

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

WaitUntil runs checkDone until a timeout is reached

Types

type EBSUtil

type EBSUtil struct {
	// contains filtered or unexported fields
}

EBSUtil provides functions to interact with EBS volumes

func NewEBSUtil

func NewEBSUtil(client *ec2.EC2) *EBSUtil

NewEBSUtil returns an instance of EBSUtil which can be used to to interact with EBS volumes

func (*EBSUtil) AttachDisk

func (ebs *EBSUtil) AttachDisk(volumeID string, nodeName string) error

AttachDisk attaches an EBS volume to a node.

type HostExec

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

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(f *framework.Framework, ns *v1.Namespace, item interface{}) (func() 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(node *v1.Node, volumeType LocalVolumeType, parameters map[string]string) *LocalTestResource
	Remove(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
}

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

Jump to

Keyboard shortcuts

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