pv

package
v1.28.9 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 46

Documentation

Index

Constants

View Source
const (

	// VolumeSelectorKey is the key for volume selector.
	VolumeSelectorKey = "e2e-pv-pool"
)

Variables

View Source
var (
	// SELinuxLabel is common selinux labels.
	SELinuxLabel = &v1.SELinuxOptions{
		Level: "s0:c0,c1"}
)

Functions

func CreatePDWithRetry

func CreatePDWithRetry(ctx context.Context) (string, error)

CreatePDWithRetry creates PD with retry.

func CreatePDWithRetryAndZone

func CreatePDWithRetryAndZone(ctx context.Context, zone string) (string, error)

CreatePDWithRetryAndZone creates PD on zone with retry.

func CreatePV

CreatePV creates the PV resource. Fails test on error.

func CreatePVC

CreatePVC creates the PVC resource. Fails test on error.

func CreatePVCPV

CreatePVCPV creates a PVC followed by the PV based on the passed in nfs-server ip and namespace. If the "preBind" bool is true then pre-bind the PV to the PVC via the PV's ClaimRef. Return the pv and pvc to reflect the created objects. Note: in the pre-bind case the real PVC name, which is generated, is not

known until after the PVC is instantiated. This is why the pvc is created
before the pv.

func CreatePVPVC

CreatePVPVC creates a PV followed by the PVC based on the passed in nfs-server ip and namespace. If the "preBind" bool is true then pre-bind the PVC to the PV via the PVC's VolumeName. Return the pv and pvc to reflect the created objects. Note: in the pre-bind case the real PV name, which is generated, is not

known until after the PV is instantiated. This is why the pv is created
before the pvc.

func CreatePVSource

func CreatePVSource(ctx context.Context, zone string) (*v1.PersistentVolumeSource, error)

CreatePVSource creates a PV source.

func CreatePVsPVCs

func CreatePVsPVCs(ctx context.Context, numpvs, numpvcs int, c clientset.Interface, timeouts *framework.TimeoutContext, ns string, pvConfig PersistentVolumeConfig, pvcConfig PersistentVolumeClaimConfig) (PVMap, PVCMap, error)

CreatePVsPVCs creates the desired number of PVs and PVCs and returns them in separate maps. If the number of PVs != the number of PVCs then the min of those two counts is the number of PVs expected to bind. If a Create error occurs, the returned maps may contain pv and pvc entries for the resources that were successfully created. In other words, when the caller sees an error returned, it needs to decide what to do about entries in the maps. Note: when the test suite deletes the namespace orphaned pvcs and pods are deleted. However,

orphaned pvs are not deleted and will remain after the suite completes.

func CreateShare added in v1.24.0

func CreateShare() (string, string, string, error)

func DeletePDWithRetry

func DeletePDWithRetry(ctx context.Context, diskName string) error

DeletePDWithRetry deletes PD with retry.

func DeletePVCandValidatePV

func DeletePVCandValidatePV(ctx context.Context, c clientset.Interface, timeouts *framework.TimeoutContext, ns string, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, expectPVPhase v1.PersistentVolumePhase) error

DeletePVCandValidatePV deletes the PVC and waits for the PV to enter its expected phase. Validate that the PV has been reclaimed (assumption here about reclaimPolicy). Caller tells this func which phase value to expect for the pv bound to the to-be-deleted claim.

func DeletePVCandValidatePVGroup

func DeletePVCandValidatePVGroup(ctx context.Context, c clientset.Interface, timeouts *framework.TimeoutContext, ns string, pvols PVMap, claims PVCMap, expectPVPhase v1.PersistentVolumePhase) error

DeletePVCandValidatePVGroup wraps deletePVCandValidatePV() by calling the function in a loop over the PV map. Only bound PVs are deleted. Validates that the claim was deleted and the PV is in the expected Phase (Released, Available, Bound). Note: if there are more claims than pvs then some of the remaining claims may bind to just made

available pvs.

func DeletePVSource

func DeletePVSource(ctx context.Context, pvSource *v1.PersistentVolumeSource) error

DeletePVSource deletes a PV source.

func DeletePersistentVolume

func DeletePersistentVolume(ctx context.Context, c clientset.Interface, pvName string) error

DeletePersistentVolume deletes the PV.

func DeletePersistentVolumeClaim

func DeletePersistentVolumeClaim(ctx context.Context, c clientset.Interface, pvcName string, ns string) error

DeletePersistentVolumeClaim deletes the Claim.

func DeleteShare added in v1.24.0

func DeleteShare(accountName, shareName string) error

func GetDefaultFSType added in v1.21.0

func GetDefaultFSType() string

GetDefaultFSType returns the default fsType

func GetDefaultStorageClassName

func GetDefaultStorageClassName(ctx context.Context, c clientset.Interface) (string, error)

GetDefaultStorageClassName returns default storageClass or return error

func MakePersistentVolume

func MakePersistentVolume(pvConfig PersistentVolumeConfig) *v1.PersistentVolume

MakePersistentVolume returns a PV definition based on the nfs server IP. If the PVC is not nil then the PV is defined with a ClaimRef which includes the PVC's namespace. If the PVC is nil then the PV is not defined with a ClaimRef. If no reclaimPolicy is assigned, assumes "Retain". Specs are expected to match the test's PVC. Note: the passed-in claim does not have a name until it is created and thus the PV's

ClaimRef cannot be completely filled-in in this func. Therefore, the ClaimRef's name
is added later in CreatePVCPV.

func MakePersistentVolumeClaim

func MakePersistentVolumeClaim(cfg PersistentVolumeClaimConfig, ns string) *v1.PersistentVolumeClaim

MakePersistentVolumeClaim returns a PVC API Object based on the PersistentVolumeClaimConfig.

func PVPVCCleanup

PVPVCCleanup cleans up a pv and pvc in a single pv/pvc test case. Note: delete errors are appended to []error so that we can attempt to delete both the pvc and pv.

func PVPVCMapCleanup

func PVPVCMapCleanup(ctx context.Context, c clientset.Interface, ns string, pvols PVMap, claims PVCMap) []error

PVPVCMapCleanup Cleans up pvs and pvcs in multi-pv-pvc test cases. Entries found in the pv and claim maps are deleted as long as the Delete api call succeeds. Note: delete errors are appended to []error so that as many pvcs and pvs as possible are deleted.

func SkipIfNoDefaultStorageClass

func SkipIfNoDefaultStorageClass(ctx context.Context, c clientset.Interface)

SkipIfNoDefaultStorageClass skips tests if no default SC can be found.

func WaitAndVerifyBinds

func WaitAndVerifyBinds(ctx context.Context, c clientset.Interface, timeouts *framework.TimeoutContext, ns string, pvols PVMap, claims PVCMap, testExpected bool) error

WaitAndVerifyBinds searches for bound PVs and PVCs by examining pvols for non-nil claimRefs. NOTE: Each iteration waits for a maximum of 3 minutes per PV and, if the PV is bound,

up to 3 minutes for the PVC. When the number of PVs != number of PVCs, this can lead
to situations where the maximum wait times are reached several times in succession,
extending test time. Thus, it is recommended to keep the delta between PVs and PVCs
small.

func WaitForPVCFinalizer added in v1.20.0

func WaitForPVCFinalizer(ctx context.Context, cs clientset.Interface, name, namespace, finalizer string, poll, timeout time.Duration) error

WaitForPVCFinalizer waits for a finalizer to be added to a PVC in a given namespace.

func WaitForPVClaimBoundPhase

func WaitForPVClaimBoundPhase(ctx context.Context, client clientset.Interface, pvclaims []*v1.PersistentVolumeClaim, timeout time.Duration) ([]*v1.PersistentVolume, error)

WaitForPVClaimBoundPhase waits until all pvcs phase set to bound

func WaitForPersistentVolumeClaimPhase

func WaitForPersistentVolumeClaimPhase(ctx context.Context, phase v1.PersistentVolumeClaimPhase, c clientset.Interface, ns string, pvcName string, poll, timeout time.Duration) error

WaitForPersistentVolumeClaimPhase waits for a PersistentVolumeClaim to be in a specific phase or until timeout occurs, whichever comes first.

func WaitForPersistentVolumeClaimsPhase

func WaitForPersistentVolumeClaimsPhase(ctx context.Context, phase v1.PersistentVolumeClaimPhase, c clientset.Interface, ns string, pvcNames []string, poll, timeout time.Duration, matchAny bool) error

WaitForPersistentVolumeClaimsPhase waits for any (if matchAny is true) or all (if matchAny is false) PersistentVolumeClaims to be in a specific phase or until timeout occurs, whichever comes first.

func WaitForPersistentVolumeDeleted added in v1.19.0

func WaitForPersistentVolumeDeleted(ctx context.Context, c clientset.Interface, pvName string, poll, timeout time.Duration) error

WaitForPersistentVolumeDeleted waits for a PersistentVolume to get deleted or until timeout occurs, whichever comes first.

func WaitForPersistentVolumePhase

func WaitForPersistentVolumePhase(ctx context.Context, phase v1.PersistentVolumePhase, c clientset.Interface, pvName string, poll, timeout time.Duration) error

WaitForPersistentVolumePhase waits for a PersistentVolume to be in a specific phase or until timeout occurs, whichever comes first.

func WaitOnPVandPVC

WaitOnPVandPVC waits for the pv and pvc to bind to each other.

Types

type PVCMap

type PVCMap map[types.NamespacedName]pvcval

PVCMap is a map of all PVCs used in the multi pv-pvc tests. The key is "namespace/pvc.Name". The value is {} (empty struct) since we're only interested in the PVC's name and if it is present. We must always Get the pvc object before referencing any of its values, eg. its VolumeName. Note: It's unsafe to add keys to a map in a loop. Their insertion in the map is

unpredictable and can result in the same key being iterated over again.

type PVMap

type PVMap map[string]pvval

PVMap is a map of all PVs used in the multi pv-pvc tests. The key is the PV's name, which is guaranteed to be unique. The value is {} (empty struct) since we're only interested in the PV's name and if it is present. We must always Get the pv object before referencing any of its values, eg its ClaimRef.

type PersistentVolumeClaimConfig

type PersistentVolumeClaimConfig struct {
	// Name of the PVC. If set, overrides NamePrefix
	Name string
	// NamePrefix defaults to "pvc-" if unspecified
	NamePrefix string
	// ClaimSize must be specified in the Quantity format. Defaults to 2Gi if
	// unspecified
	ClaimSize string
	// AccessModes defaults to RWO if unspecified
	AccessModes      []v1.PersistentVolumeAccessMode
	Annotations      map[string]string
	Selector         *metav1.LabelSelector
	StorageClassName *string
	// VolumeMode defaults to nil if unspecified or specified as the empty
	// string
	VolumeMode *v1.PersistentVolumeMode
}

PersistentVolumeClaimConfig is consumed by MakePersistentVolumeClaim() to generate a PVC object.

type PersistentVolumeConfig

type PersistentVolumeConfig struct {
	// [Optional] NamePrefix defaults to "pv-" if unset
	NamePrefix string
	// [Optional] Labels contains information used to organize and categorize
	// objects
	Labels labels.Set
	// PVSource contains the details of the underlying volume and must be set
	PVSource v1.PersistentVolumeSource
	// [Optional] Prebind lets you specify a PVC to bind this PV to before
	// creation
	Prebind *v1.PersistentVolumeClaim
	// [Optiona] ReclaimPolicy defaults to "Reclaim" if unset
	ReclaimPolicy    v1.PersistentVolumeReclaimPolicy
	StorageClassName string
	// [Optional] NodeAffinity defines constraints that limit what nodes this
	// volume can be accessed from.
	NodeAffinity *v1.VolumeNodeAffinity
	// [Optional] VolumeMode defaults to "Filesystem" if unset
	VolumeMode *v1.PersistentVolumeMode
	// [Optional] AccessModes defaults to RWO if unset
	AccessModes []v1.PersistentVolumeAccessMode
	// [Optional] Capacity is the storage capacity in Quantity format. Defaults
	// to "2Gi" if unset
	Capacity string
}

PersistentVolumeConfig is consumed by MakePersistentVolume() to generate a PV object for varying storage options (NFS, ceph, etc.). (+optional) prebind holds a pre-bound PVC Example pvSource:

pvSource: api.PersistentVolumeSource{
	NFS: &api.NFSVolumeSource{
 		...
 	},
 }

Jump to

Keyboard shortcuts

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