common

package
v1.59.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ImportPaused provides a const to indicate that a multistage import is waiting for the next stage
	ImportPaused = "ImportPaused"
	// MessageImportPaused provides a const for a "multistage import paused" message
	MessageImportPaused = "Multistage import into PVC %s is paused"
)
View Source
const (
	// DataVolName provides a const to use for creating volumes in pod specs
	DataVolName = "cdi-data-vol"

	// ScratchVolName provides a const to use for creating scratch pvc volumes in pod specs
	ScratchVolName = "cdi-scratch-vol"

	// AnnAPIGroup is the APIGroup for CDI
	AnnAPIGroup = "cdi.kubevirt.io"
	// AnnCreatedBy is a pod annotation indicating if the pod was created by the PVC
	AnnCreatedBy = AnnAPIGroup + "/storage.createdByController"
	// AnnPodPhase is a PVC annotation indicating the related pod progress (phase)
	AnnPodPhase = AnnAPIGroup + "/storage.pod.phase"
	// AnnPodReady tells whether the pod is ready
	AnnPodReady = AnnAPIGroup + "/storage.pod.ready"
	// AnnPodRestarts is a PVC annotation that tells how many times a related pod was restarted
	AnnPodRestarts = AnnAPIGroup + "/storage.pod.restarts"
	// AnnPopulatedFor is a PVC annotation telling the datavolume controller that the PVC is already populated
	AnnPopulatedFor = AnnAPIGroup + "/storage.populatedFor"
	// AnnPrePopulated is a PVC annotation telling the datavolume controller that the PVC is already populated
	AnnPrePopulated = AnnAPIGroup + "/storage.prePopulated"
	// AnnPriorityClassName is PVC annotation to indicate the priority class name for importer, cloner and uploader pod
	AnnPriorityClassName = AnnAPIGroup + "/storage.pod.priorityclassname"
	// AnnExternalPopulation annotation marks a PVC as "externally populated", allowing the import-controller to skip it
	AnnExternalPopulation = AnnAPIGroup + "/externalPopulation"

	// AnnDeleteAfterCompletion is PVC annotation for deleting DV after completion
	AnnDeleteAfterCompletion = AnnAPIGroup + "/storage.deleteAfterCompletion"
	// AnnPodRetainAfterCompletion is PVC annotation for retaining transfer pods after completion
	AnnPodRetainAfterCompletion = AnnAPIGroup + "/storage.pod.retainAfterCompletion"

	// AnnPreviousCheckpoint provides a const to indicate the previous snapshot for a multistage import
	AnnPreviousCheckpoint = AnnAPIGroup + "/storage.checkpoint.previous"
	// AnnCurrentCheckpoint provides a const to indicate the current snapshot for a multistage import
	AnnCurrentCheckpoint = AnnAPIGroup + "/storage.checkpoint.current"
	// AnnFinalCheckpoint provides a const to indicate whether the current checkpoint is the last one
	AnnFinalCheckpoint = AnnAPIGroup + "/storage.checkpoint.final"
	// AnnCheckpointsCopied is a prefix for recording which checkpoints have already been copied
	AnnCheckpointsCopied = AnnAPIGroup + "/storage.checkpoint.copied"

	// AnnCurrentPodID keeps track of the latest pod servicing this PVC
	AnnCurrentPodID = AnnAPIGroup + "/storage.checkpoint.pod.id"
	// AnnMultiStageImportDone marks a multi-stage import as totally finished
	AnnMultiStageImportDone = AnnAPIGroup + "/storage.checkpoint.done"

	// AnnPopulatorProgress is a standard annotation that can be used progress reporting
	AnnPopulatorProgress = AnnAPIGroup + "/storage.populator.progress"

	// AnnPreallocationRequested provides a const to indicate whether preallocation should be performed on the PV
	AnnPreallocationRequested = AnnAPIGroup + "/storage.preallocation.requested"
	// AnnPreallocationApplied provides a const for PVC preallocation annotation
	AnnPreallocationApplied = AnnAPIGroup + "/storage.preallocation"

	// AnnRunningCondition provides a const for the running condition
	AnnRunningCondition = AnnAPIGroup + "/storage.condition.running"
	// AnnRunningConditionMessage provides a const for the running condition
	AnnRunningConditionMessage = AnnAPIGroup + "/storage.condition.running.message"
	// AnnRunningConditionReason provides a const for the running condition
	AnnRunningConditionReason = AnnAPIGroup + "/storage.condition.running.reason"

	// AnnBoundCondition provides a const for the running condition
	AnnBoundCondition = AnnAPIGroup + "/storage.condition.bound"
	// AnnBoundConditionMessage provides a const for the running condition
	AnnBoundConditionMessage = AnnAPIGroup + "/storage.condition.bound.message"
	// AnnBoundConditionReason provides a const for the running condition
	AnnBoundConditionReason = AnnAPIGroup + "/storage.condition.bound.reason"

	// AnnSourceRunningCondition provides a const for the running condition
	AnnSourceRunningCondition = AnnAPIGroup + "/storage.condition.source.running"
	// AnnSourceRunningConditionMessage provides a const for the running condition
	AnnSourceRunningConditionMessage = AnnAPIGroup + "/storage.condition.source.running.message"
	// AnnSourceRunningConditionReason provides a const for the running condition
	AnnSourceRunningConditionReason = AnnAPIGroup + "/storage.condition.source.running.reason"

	// AnnVddkVersion shows the last VDDK library version used by a DV's importer pod
	AnnVddkVersion = AnnAPIGroup + "/storage.pod.vddk.version"
	// AnnVddkHostConnection shows the last ESX host that serviced a DV's importer pod
	AnnVddkHostConnection = AnnAPIGroup + "/storage.pod.vddk.host"
	// AnnVddkInitImageURL saves a per-DV VDDK image URL on the PVC
	AnnVddkInitImageURL = AnnAPIGroup + "/storage.pod.vddk.initimageurl"

	// AnnRequiresScratch provides a const for our PVC requires scratch annotation
	AnnRequiresScratch = AnnAPIGroup + "/storage.import.requiresScratch"

	// AnnContentType provides a const for the PVC content-type
	AnnContentType = AnnAPIGroup + "/storage.contentType"

	// AnnSource provide a const for our PVC import source annotation
	AnnSource = AnnAPIGroup + "/storage.import.source"
	// AnnEndpoint provides a const for our PVC endpoint annotation
	AnnEndpoint = AnnAPIGroup + "/storage.import.endpoint"

	// AnnSecret provides a const for our PVC secretName annotation
	AnnSecret = AnnAPIGroup + "/storage.import.secretName"
	// AnnCertConfigMap is the name of a configmap containing tls certs
	AnnCertConfigMap = AnnAPIGroup + "/storage.import.certConfigMap"
	// AnnRegistryImportMethod provides a const for registry import method annotation
	AnnRegistryImportMethod = AnnAPIGroup + "/storage.import.registryImportMethod"
	// AnnRegistryImageStream provides a const for registry image stream annotation
	AnnRegistryImageStream = AnnAPIGroup + "/storage.import.registryImageStream"
	// AnnImportPod provides a const for our PVC importPodName annotation
	AnnImportPod = AnnAPIGroup + "/storage.import.importPodName"
	// AnnDiskID provides a const for our PVC diskId annotation
	AnnDiskID = AnnAPIGroup + "/storage.import.diskId"
	// AnnUUID provides a const for our PVC uuid annotation
	AnnUUID = AnnAPIGroup + "/storage.import.uuid"
	// AnnBackingFile provides a const for our PVC backing file annotation
	AnnBackingFile = AnnAPIGroup + "/storage.import.backingFile"
	// AnnThumbprint provides a const for our PVC backing thumbprint annotation
	AnnThumbprint = AnnAPIGroup + "/storage.import.vddk.thumbprint"
	// AnnExtraHeaders provides a const for our PVC extraHeaders annotation
	AnnExtraHeaders = AnnAPIGroup + "/storage.import.extraHeaders"
	// AnnSecretExtraHeaders provides a const for our PVC secretExtraHeaders annotation
	AnnSecretExtraHeaders = AnnAPIGroup + "/storage.import.secretExtraHeaders"

	// AnnCloneToken is the annotation containing the clone token
	AnnCloneToken = AnnAPIGroup + "/storage.clone.token"
	// AnnExtendedCloneToken is the annotation containing the long term clone token
	AnnExtendedCloneToken = AnnAPIGroup + "/storage.extended.clone.token"
	// AnnPermissiveClone annotation allows the clone-controller to skip the clone size validation
	AnnPermissiveClone = AnnAPIGroup + "/permissiveClone"
	// AnnOwnerUID annotation has the owner UID
	AnnOwnerUID = AnnAPIGroup + "/ownerUID"
	// AnnCloneType is the comuuted/requested clone type
	AnnCloneType = AnnAPIGroup + "/cloneType"
	// AnnCloneSourcePod name of the source clone pod
	AnnCloneSourcePod = AnnAPIGroup + "/storage.sourceClonePodName"

	// AnnUploadRequest marks that a PVC should be made available for upload
	AnnUploadRequest = AnnAPIGroup + "/storage.upload.target"

	// AnnCheckStaticVolume checks if a statically allocated PV exists before creating the target PVC.
	// If so, PVC is still created but population is skipped
	AnnCheckStaticVolume = AnnAPIGroup + "/storage.checkStaticVolume"

	// AnnPersistentVolumeList is an annotation storing a list of PV names
	AnnPersistentVolumeList = AnnAPIGroup + "/storage.persistentVolumeList"

	// AnnPopulatorKind annotation is added to a PVC' to specify the population kind, so it's later
	// checked by the common populator watches.
	AnnPopulatorKind = AnnAPIGroup + "/storage.populator.kind"
	// AnnUsePopulator annotation indicates if the datavolume population will use populators
	AnnUsePopulator = AnnAPIGroup + "/storage.usePopulator"

	// AnnDefaultStorageClass is the annotation indicating that a storage class is the default one
	AnnDefaultStorageClass = "storageclass.kubernetes.io/is-default-class"
	// AnnDefaultVirtStorageClass is the annotation indicating that a storage class is the default one for virtualization purposes
	AnnDefaultVirtStorageClass = "storageclass.kubevirt.io/is-default-virt-class"
	// AnnDefaultSnapshotClass is the annotation indicating that a snapshot class is the default one
	AnnDefaultSnapshotClass = "snapshot.storage.kubernetes.io/is-default-class"

	// AnnOpenShiftImageLookup is the annotation for OpenShift image stream lookup
	AnnOpenShiftImageLookup = "alpha.image.policy.openshift.io/resolve-names"

	// AnnCloneRequest sets our expected annotation for a CloneRequest
	AnnCloneRequest = "k8s.io/CloneRequest"
	// AnnCloneOf is used to indicate that cloning was complete
	AnnCloneOf = "k8s.io/CloneOf"

	// AnnPodNetwork is used for specifying Pod Network
	AnnPodNetwork = "k8s.v1.cni.cncf.io/networks"
	// AnnPodMultusDefaultNetwork is used for specifying default Pod Network
	AnnPodMultusDefaultNetwork = "v1.multus-cni.io/default-network"
	// AnnPodSidecarInjectionIstio is used for enabling/disabling Pod istio/AspenMesh sidecar injection
	AnnPodSidecarInjectionIstio = "sidecar.istio.io/inject"
	// AnnPodSidecarInjectionIstioDefault is the default value passed for AnnPodSidecarInjection
	AnnPodSidecarInjectionIstioDefault = "false"
	// AnnPodSidecarInjectionLinkerd is used to enable/disable linkerd sidecar injection
	AnnPodSidecarInjectionLinkerd = "linkerd.io/inject"
	// AnnPodSidecarInjectionLinkerdDefault is the default value passed for AnnPodSidecarInjectionLinkerd
	AnnPodSidecarInjectionLinkerdDefault = "disabled"

	// AnnImmediateBinding provides a const to indicate whether immediate binding should be performed on the PV (overrides global config)
	AnnImmediateBinding = AnnAPIGroup + "/storage.bind.immediate.requested"

	// AnnSelectedNode annotation is added to a PVC that has been triggered by scheduler to
	// be dynamically provisioned. Its value is the name of the selected node.
	AnnSelectedNode = "volume.kubernetes.io/selected-node"

	// AnnGarbageCollected is a PVC annotation indicating that the PVC was garbage collected
	AnnGarbageCollected = AnnAPIGroup + "/garbageCollected"

	// CloneUniqueID is used as a special label to be used when we search for the pod
	CloneUniqueID = AnnAPIGroup + "/storage.clone.cloneUniqeId"

	// CloneSourceInUse is reason for event created when clone source pvc is in use
	CloneSourceInUse = "CloneSourceInUse"

	// CloneComplete message
	CloneComplete = "Clone Complete"

	// ErrStartingPod provides a const to indicate that a pod wasn't able to start without providing sensitive information (reason)
	ErrStartingPod = "ErrStartingPod"
	// MessageErrStartingPod provides a const to indicate that a pod wasn't able to start without providing sensitive information (message)
	MessageErrStartingPod = "Error starting pod '%s': For more information, request access to cdi-deploy logs from your sysadmin"
	// ErrClaimNotValid provides a const to indicate a claim is not valid
	ErrClaimNotValid = "ErrClaimNotValid"
	// ErrExceededQuota provides a const to indicate the claim has exceeded the quota
	ErrExceededQuota = "ErrExceededQuota"
	// ErrIncompatiblePVC provides a const to indicate a clone is not possible due to an incompatible PVC
	ErrIncompatiblePVC = "ErrIncompatiblePVC"

	// SourceHTTP is the source type HTTP, if unspecified or invalid, it defaults to SourceHTTP
	SourceHTTP = "http"
	// SourceS3 is the source type S3
	SourceS3 = "s3"
	// SourceGCS is the source type GCS
	SourceGCS = "gcs"
	// SourceGlance is the source type of glance
	SourceGlance = "glance"
	// SourceNone means there is no source.
	SourceNone = "none"
	// SourceRegistry is the source type of Registry
	SourceRegistry = "registry"
	// SourceImageio is the source type ovirt-imageio
	SourceImageio = "imageio"
	// SourceVDDK is the source type of VDDK
	SourceVDDK = "vddk"

	// VolumeSnapshotClassSelected reports that a VolumeSnapshotClass was selected
	VolumeSnapshotClassSelected = "VolumeSnapshotClassSelected"
	// MessageStorageProfileVolumeSnapshotClassSelected reports that a VolumeSnapshotClass was selected according to StorageProfile
	MessageStorageProfileVolumeSnapshotClassSelected = "VolumeSnapshotClass selected according to StorageProfile"
	// MessageDefaultVolumeSnapshotClassSelected reports that the default VolumeSnapshotClass was selected
	MessageDefaultVolumeSnapshotClassSelected = "Default VolumeSnapshotClass selected"
	// MessageFirstVolumeSnapshotClassSelected reports that the first VolumeSnapshotClass was selected
	MessageFirstVolumeSnapshotClassSelected = "First VolumeSnapshotClass selected"

	// ClaimLost reason const
	ClaimLost = "ClaimLost"
	// NotFound reason const
	NotFound = "NotFound"

	// LabelDefaultInstancetype provides a default VirtualMachine{ClusterInstancetype,Instancetype} that can be used by a VirtualMachine booting from a given PVC
	LabelDefaultInstancetype = "instancetype.kubevirt.io/default-instancetype"
	// LabelDefaultInstancetypeKind provides a default kind of either VirtualMachineClusterInstancetype or VirtualMachineInstancetype
	LabelDefaultInstancetypeKind = "instancetype.kubevirt.io/default-instancetype-kind"
	// LabelDefaultPreference provides a default VirtualMachine{ClusterPreference,Preference} that can be used by a VirtualMachine booting from a given PVC
	LabelDefaultPreference = "instancetype.kubevirt.io/default-preference"
	// LabelDefaultPreferenceKind provides a default kind of either VirtualMachineClusterPreference or VirtualMachinePreference
	LabelDefaultPreferenceKind = "instancetype.kubevirt.io/default-preference-kind"

	// LabelDynamicCredentialSupport specifies if the OS supports updating credentials at runtime.
	LabelDynamicCredentialSupport = "kubevirt.io/dynamic-credentials-support"

	// ProgressDone this means we are DONE
	ProgressDone = "100.0%"

	// AnnEventSourceKind is the source kind that should be related to events
	AnnEventSourceKind = AnnAPIGroup + "/events.source.kind"
	// AnnEventSource is the source that should be related to events (namespace/name)
	AnnEventSource = AnnAPIGroup + "/events.source"

	// AnnAllowClaimAdoption is the annotation that allows a claim to be adopted by a DataVolume
	AnnAllowClaimAdoption = AnnAPIGroup + "/allowClaimAdoption"

	// AnnCdiCustomizeComponentHash annotation is a hash of all customizations that live under spec.CustomizeComponents
	AnnCdiCustomizeComponentHash = AnnAPIGroup + "/customizer-identifier"

	// AnnCreatedForDataVolume stores the UID of the datavolume that the PVC was created for
	AnnCreatedForDataVolume = AnnAPIGroup + "/createdForDataVolume"
)
View Source
const (
	NoErr int = iota
	ErrBadArguments
	ErrInvalidFile
	ErrInvalidPath
	ErrBadTermFile
	ErrUnknown
)

Size-detection pod error codes

Variables

View Source
var (
	// BlockMode is raw block device mode
	BlockMode = corev1.PersistentVolumeBlock
	// FilesystemMode is filesystem device mode
	FilesystemMode = corev1.PersistentVolumeFilesystem

	// DefaultInstanceTypeLabels is a list of currently supported default instance type labels
	DefaultInstanceTypeLabels = []string{
		LabelDefaultInstancetype,
		LabelDefaultInstancetypeKind,
		LabelDefaultPreference,
		LabelDefaultPreferenceKind,
	}
)

Functions

func AddAnnotation

func AddAnnotation(obj metav1.Object, key, value string)

AddAnnotation adds an annotation to an object

func AddFinalizer

func AddFinalizer(obj metav1.Object, name string)

AddFinalizer adds a finalizer to a resource

func AddImmediateBindingAnnotationIfWFFCDisabled added in v1.57.0

func AddImmediateBindingAnnotationIfWFFCDisabled(obj metav1.Object, gates featuregates.FeatureGates) error

AddImmediateBindingAnnotationIfWFFCDisabled adds the immediateBinding annotation if wffc feature gate is disabled

func AddImportVolumeMounts

func AddImportVolumeMounts() []corev1.VolumeMount

AddImportVolumeMounts is being called for pods using PV with filesystem volume mode

func AddLabel

func AddLabel(obj metav1.Object, key, value string)

AddLabel adds a label to an object

func AddVolumeDevices

func AddVolumeDevices() []corev1.VolumeDevice

AddVolumeDevices returns VolumeDevice slice with one block device for pods using PV with block volume mode

func AllowClaimAdoption added in v1.58.2

func AllowClaimAdoption(c client.Client, pvc *corev1.PersistentVolumeClaim, dv *cdiv1.DataVolume) (bool, error)

AllowClaimAdoption returns true if the PVC may be adopted

func BuildHTTPClient added in v1.57.0

func BuildHTTPClient(httpClient *http.Client) *http.Client

BuildHTTPClient generates an http client that accepts any certificate, since we are using it to get prometheus data it doesn't matter if someone can intercept the data. Once we have a mechanism to properly sign the server, we can update this method to get a proper client.

func BulkDeleteResources added in v1.57.0

func BulkDeleteResources(ctx context.Context, c client.Client, obj client.ObjectList, lo client.ListOption) error

BulkDeleteResources deletes a bunch of resources

func ClaimIsPopulatedForDataVolume added in v1.58.2

func ClaimIsPopulatedForDataVolume(pvc *corev1.PersistentVolumeClaim, dv *cdiv1.DataVolume) bool

ClaimIsPopulatedForDataVolume returns true if the PVC is populated for the given DataVolume

func ClaimMayExistBeforeDataVolume added in v1.58.2

func ClaimMayExistBeforeDataVolume(c client.Client, pvc *corev1.PersistentVolumeClaim, dv *cdiv1.DataVolume) (bool, error)

ClaimMayExistBeforeDataVolume returns true if the PVC may exist before the DataVolume

func CreateClient

func CreateClient(objs ...runtime.Object) client.Client

CreateClient creates a fake client

func CreateCloneSourcePodName

func CreateCloneSourcePodName(targetPvc *corev1.PersistentVolumeClaim) string

CreateCloneSourcePodName creates clone source pod name

func CreateImporterTestPod

func CreateImporterTestPod(pvc *corev1.PersistentVolumeClaim, dvname string, scratchPvc *corev1.PersistentVolumeClaim) *corev1.Pod

CreateImporterTestPod creates importer test pod CR

func CreatePvc

func CreatePvc(name, ns string, annotations, labels map[string]string) *corev1.PersistentVolumeClaim

CreatePvc creates PVC

func CreatePvcInStorageClass

func CreatePvcInStorageClass(name, ns string, storageClassName *string, annotations, labels map[string]string, phase corev1.PersistentVolumeClaimPhase) *corev1.PersistentVolumeClaim

CreatePvcInStorageClass creates PVC with storgae class

func CreateStorageClass

func CreateStorageClass(name string, annotations map[string]string) *storagev1.StorageClass

CreateStorageClass creates storage class CR

func CreateStorageClassWithProvisioner

func CreateStorageClassWithProvisioner(name string, annotations, labels map[string]string, provisioner string) *storagev1.StorageClass

CreateStorageClassWithProvisioner creates CR of storage class with provisioner

func ErrConnectionRefused added in v1.57.0

func ErrConnectionRefused(err error) bool

ErrConnectionRefused checks for connection refused errors

func ErrQuotaExceeded

func ErrQuotaExceeded(err error) bool

ErrQuotaExceeded checked is the error is of exceeded quota

func GetAPIServerKey

func GetAPIServerKey() *rsa.PrivateKey

GetAPIServerKey returns API server RSA key

func GetActiveCDI

func GetActiveCDI(ctx context.Context, c client.Client) (*cdiv1.CDI, error)

GetActiveCDI returns the active CDI CR

func GetAnnotatedEventSource added in v1.57.0

func GetAnnotatedEventSource(ctx context.Context, c client.Client, obj client.Object) (client.Object, error)

GetAnnotatedEventSource returns resource referenced by AnnEventSource annotations

func GetCloneSourceInfo added in v1.57.0

func GetCloneSourceInfo(dv *cdiv1.DataVolume) (sourceType, sourceName, sourceNamespace string)

GetCloneSourceInfo returns the type, name and namespace of the cloning source

func GetContentType

func GetContentType(contentType cdiv1.DataVolumeContentType) cdiv1.DataVolumeContentType

GetContentType returns the content type. If invalid or not set, default to kubevirt

func GetDataVolumeTTLSeconds

func GetDataVolumeTTLSeconds(config *cdiv1.CDIConfig) int32

GetDataVolumeTTLSeconds gets the current DataVolume TTL in seconds if GC is enabled, or < 0 if GC is disabled Garbage collection is disabled by default

func GetDefaultPodResourceRequirements

func GetDefaultPodResourceRequirements(client client.Client) (*corev1.ResourceRequirements, error)

GetDefaultPodResourceRequirements gets default pod resource requirements from cdi config status

func GetEndpoint

func GetEndpoint(pvc *corev1.PersistentVolumeClaim) (string, error)

GetEndpoint returns the endpoint string which contains the full path URI of the target object to be copied.

func GetFilesystemOverheadForStorageClass

func GetFilesystemOverheadForStorageClass(ctx context.Context, client client.Client, storageClassName *string) (cdiv1.Percent, error)

GetFilesystemOverheadForStorageClass determines the filesystem overhead defined in CDIConfig for the storageClass.

func GetImagePullSecrets added in v1.57.0

func GetImagePullSecrets(client client.Client) ([]corev1.LocalObjectReference, error)

GetImagePullSecrets gets the imagePullSecrets needed to pull images from the cdi config

func GetMetricsURL added in v1.57.0

func GetMetricsURL(pod *corev1.Pod) (string, error)

GetMetricsURL builds the metrics URL according to the specified pod

func GetNamespace

func GetNamespace(namespace, defaultNamespace string) string

GetNamespace returns the given namespace if not empty, otherwise the default namespace

func GetPVCContentType added in v1.57.0

GetPVCContentType returns the content type of the source image. If invalid or not set, default to kubevirt

func GetPlatformDefaultStorageClass added in v1.58.0

func GetPlatformDefaultStorageClass(storageClasses *storagev1.StorageClassList, defaultAnnotationKey string) *storagev1.StorageClass

GetPlatformDefaultStorageClass returns the default storage class according to the provided annotation or nil if none found

func GetPodFromPvc added in v1.58.0

func GetPodFromPvc(c client.Client, namespace string, pvc *corev1.PersistentVolumeClaim) (*corev1.Pod, error)

GetPodFromPvc determines the pod associated with the pvc passed in.

func GetPodMetricsPort added in v1.57.0

func GetPodMetricsPort(pod *corev1.Pod) (int, error)

GetPodMetricsPort returns, if exists, the metrics port from the passed pod

func GetPodsUsingPVCs

func GetPodsUsingPVCs(ctx context.Context, c client.Client, namespace string, names sets.Set[string], allowReadOnly bool) ([]corev1.Pod, error)

GetPodsUsingPVCs returns Pods currently using PVCs

func GetPreallocation

func GetPreallocation(ctx context.Context, client client.Client, preallocation *bool) bool

GetPreallocation retuns the preallocation setting for the specified object (DV or VolumeImportSource), falling back to StorageClass and global setting (in this order)

func GetPriorityClass

func GetPriorityClass(pvc *corev1.PersistentVolumeClaim) string

GetPriorityClass gets PVC priority class

func GetProgressReportFromURL added in v1.57.0

func GetProgressReportFromURL(url string, regExp *regexp.Regexp, httpClient *http.Client) (string, error)

GetProgressReportFromURL fetches the progress report from the passed URL according to an specific regular expression

func GetRequestedImageSize

func GetRequestedImageSize(pvc *corev1.PersistentVolumeClaim) (string, error)

GetRequestedImageSize returns the PVC requested size

func GetRequiredSpace added in v1.57.0

func GetRequiredSpace(filesystemOverhead float64, requestedSpace int64) int64

GetRequiredSpace calculates space required taking file system overhead into account

func GetResource added in v1.57.0

func GetResource(ctx context.Context, c client.Client, namespace, name string, obj client.Object) (bool, error)

GetResource updates given obj with the data of the object with the same name and namespace

func GetSnapshotClassForSmartClone added in v1.57.0

func GetSnapshotClassForSmartClone(pvc *corev1.PersistentVolumeClaim, targetPvcStorageClassName, snapshotClassName *string, log logr.Logger, client client.Client, recorder record.EventRecorder) (string, error)

GetSnapshotClassForSmartClone looks up the snapshot class based on the storage class

func GetSource

func GetSource(pvc *corev1.PersistentVolumeClaim) string

GetSource returns the source string which determines the type of source. If no source or invalid source found, default to http

func GetStorageClassByNameWithK8sFallback added in v1.58.0

func GetStorageClassByNameWithK8sFallback(ctx context.Context, client client.Client, name *string) (*storagev1.StorageClass, error)

GetStorageClassByNameWithK8sFallback looks up the storage class based on the name If name is nil, it looks for the default k8s storage class storageclass.kubernetes.io/is-default-class If no storage class is found, returns nil

func GetStorageClassByNameWithVirtFallback added in v1.58.0

func GetStorageClassByNameWithVirtFallback(ctx context.Context, client client.Client, name *string, contentType cdiv1.DataVolumeContentType) (*storagev1.StorageClass, error)

GetStorageClassByNameWithVirtFallback looks up the storage class based on the name If name is nil, it looks for the following, in this order: default kubevirt storage class (if the caller is interested) storageclass.kubevirt.io/is-default-class default k8s storage class storageclass.kubernetes.io/is-default-class If no storage class is found, returns nil

func GetStorageClassFromDVSpec added in v1.58.1

func GetStorageClassFromDVSpec(dv *cdiv1.DataVolume) *string

GetStorageClassFromDVSpec returns the StorageClassName from DataVolume PVC or Storage spec

func GetVolumeMode

GetVolumeMode returns the volumeMode from PVC handling default empty value

func GetVolumeSnapshotClass added in v1.58.0

func GetVolumeSnapshotClass(ctx context.Context, c client.Client, pvc *corev1.PersistentVolumeClaim, driver string, snapshotClassName *string, log logr.Logger, recorder record.EventRecorder) (*string, error)

GetVolumeSnapshotClass looks up the snapshot class based on the driver and an optional specific name In case of multiple candidates, it returns the default-annotated one, or the sorted list first one if no such default

func GetWorkloadNodePlacement

func GetWorkloadNodePlacement(ctx context.Context, c client.Client) (*sdkapi.NodePlacement, error)

GetWorkloadNodePlacement extracts the workload-specific nodeplacement values from the CDI CR

func HandleFailedPod

func HandleFailedPod(err error, podName string, pvc *corev1.PersistentVolumeClaim, recorder record.EventRecorder, c client.Client) error

HandleFailedPod handles pod-creation errors and updates the pod's PVC without providing sensitive information

func HasFinalizer

func HasFinalizer(object metav1.Object, value string) bool

HasFinalizer returns true if a resource has a specific finalizer

func IgnoreIsNoMatchError

func IgnoreIsNoMatchError(err error) error

IgnoreIsNoMatchError returns nil if the error is a IsNoMatchError. We will want to ignore this error for optional CRDs, if it is not found, just ignore it.

func IgnoreNotFound

func IgnoreNotFound(err error) error

IgnoreNotFound returns nil if the error is a NotFound error. We generally want to ignore (not requeue) NotFound errors, since we'll get a reconciliation request once the object exists, and requeuing in the meantime won't help.

func ImmediateBindingRequested added in v1.57.0

func ImmediateBindingRequested(obj metav1.Object) bool

ImmediateBindingRequested returns if an object has the ImmediateBinding annotation

func InflateSizeWithOverhead added in v1.57.0

func InflateSizeWithOverhead(ctx context.Context, c client.Client, imgSize int64, pvcSpec *corev1.PersistentVolumeClaimSpec) (resource.Quantity, error)

InflateSizeWithOverhead inflates a storage size with proper overhead calculations

func IsBound added in v1.57.0

func IsBound(pvc *corev1.PersistentVolumeClaim) bool

IsBound returns if the pvc is bound

func IsErrCacheNotStarted

func IsErrCacheNotStarted(err error) bool

IsErrCacheNotStarted checked is the error is of cache not started

func IsImageStream added in v1.57.0

func IsImageStream(pvc *corev1.PersistentVolumeClaim) bool

IsImageStream returns true if registry source is ImageStream

func IsMultiStageImportInProgress added in v1.58.0

func IsMultiStageImportInProgress(pvc *corev1.PersistentVolumeClaim) bool

IsMultiStageImportInProgress returns true when a PVC is being part of an ongoing multi-stage import

func IsPVBoundToPVC added in v1.57.0

func IsPVBoundToPVC(pv *corev1.PersistentVolume, pvc *corev1.PersistentVolumeClaim) bool

IsPVBoundToPVC checks if a PV is bound to a specific PVC

func IsPVCComplete

func IsPVCComplete(pvc *corev1.PersistentVolumeClaim) bool

IsPVCComplete returns true if a PVC is in 'Succeeded' phase, false if not

func IsPopulated

func IsPopulated(pvc *corev1.PersistentVolumeClaim, c client.Client) (bool, error)

IsPopulated returns if the passed in PVC has been populated according to the rules outlined in pkg/apis/core/<version>/utils.go

func IsSnapshotReady added in v1.57.0

func IsSnapshotReady(snapshot *snapshotv1.VolumeSnapshot) bool

IsSnapshotReady indicates if a volume snapshot is ready to be used

func IsUnbound added in v1.57.0

func IsUnbound(pvc *corev1.PersistentVolumeClaim) bool

IsUnbound returns if the pvc is not bound yet

func IsWaitForFirstConsumerEnabled

func IsWaitForFirstConsumerEnabled(obj metav1.Object, gates featuregates.FeatureGates) (bool, error)

IsWaitForFirstConsumerEnabled tells us if we should respect "real" WFFC behavior or just let our worker pods randomly spawn

func MakeEmptyCDICR

func MakeEmptyCDICR() *cdiv1.CDI

MakeEmptyCDICR creates CDI CustomResouce manifest

func MakeEmptyCDIConfigSpec

func MakeEmptyCDIConfigSpec(name string) *cdiv1.CDIConfig

MakeEmptyCDIConfigSpec creates cdi config manifest

func MaybeSetPvcMultiStageAnnotation added in v1.58.0

func MaybeSetPvcMultiStageAnnotation(pvc *corev1.PersistentVolumeClaim, args *CheckpointArgs) error

MaybeSetPvcMultiStageAnnotation sets the annotation if pvc needs it, and does not have it yet

func NewCloneTokenValidator

func NewCloneTokenValidator(issuer string, key *rsa.PublicKey) token.Validator

NewCloneTokenValidator returns a new token validator

func NewImportDataVolume

func NewImportDataVolume(name string) *cdiv1.DataVolume

NewImportDataVolume returns new import DataVolume CR

func OwnedByDataVolume added in v1.57.0

func OwnedByDataVolume(obj metav1.Object) bool

OwnedByDataVolume returns true if the object is owned by a DataVolume

func ProgressFromClaim added in v1.57.0

func ProgressFromClaim(ctx context.Context, args *ProgressFromClaimArgs) (string, error)

ProgressFromClaim returns the progres

func Rebind added in v1.57.0

func Rebind(ctx context.Context, c client.Client, source, target *corev1.PersistentVolumeClaim) error

Rebind binds the PV of source to target

func RemoveFinalizer

func RemoveFinalizer(obj metav1.Object, name string)

RemoveFinalizer removes a finalizer from a resource

func SetNodeNameIfPopulator added in v1.57.0

func SetNodeNameIfPopulator(pvc *corev1.PersistentVolumeClaim, podSpec *corev1.PodSpec)

SetNodeNameIfPopulator sets NodeName in a pod spec when the PVC is being handled by a CDI volume populator

func SetPvcAllowedAnnotations added in v1.57.0

func SetPvcAllowedAnnotations(obj metav1.Object, pvc *corev1.PersistentVolumeClaim)

SetPvcAllowedAnnotations applies PVC annotations on the given obj

func SetRestrictedSecurityContext

func SetRestrictedSecurityContext(podSpec *corev1.PodSpec)

SetRestrictedSecurityContext sets the pod security params to be compatible with restricted PSA

func ShouldDeletePod

func ShouldDeletePod(pvc *corev1.PersistentVolumeClaim) bool

ShouldDeletePod returns whether the PVC workload pod should be deleted

func ShouldIgnorePod added in v1.57.0

func ShouldIgnorePod(pod *corev1.Pod, pvc *corev1.PersistentVolumeClaim) bool

ShouldIgnorePod checks if a pod should be ignored. If this is a completed pod that was used for one checkpoint of a multi-stage import, it should be ignored by pod lookups as long as the retainAfterCompletion annotation is set.

func UpdateGCSAnnotations added in v1.57.0

func UpdateGCSAnnotations(annotations map[string]string, gcs *cdiv1.DataVolumeSourceGCS)

UpdateGCSAnnotations updates the passed annotations for proper GCS import

func UpdateHTTPAnnotations added in v1.57.0

func UpdateHTTPAnnotations(annotations map[string]string, http *cdiv1.DataVolumeSourceHTTP)

UpdateHTTPAnnotations updates the passed annotations for proper http import

func UpdateImageIOAnnotations added in v1.57.0

func UpdateImageIOAnnotations(annotations map[string]string, imageio *cdiv1.DataVolumeSourceImageIO)

UpdateImageIOAnnotations updates the passed annotations for proper imageIO import

func UpdateRegistryAnnotations added in v1.57.0

func UpdateRegistryAnnotations(annotations map[string]string, registry *cdiv1.DataVolumeSourceRegistry)

UpdateRegistryAnnotations updates the passed annotations for proper registry import

func UpdateS3Annotations added in v1.57.0

func UpdateS3Annotations(annotations map[string]string, s3 *cdiv1.DataVolumeSourceS3)

UpdateS3Annotations updates the passed annotations for proper S3 import

func UpdateVDDKAnnotations added in v1.57.0

func UpdateVDDKAnnotations(annotations map[string]string, vddk *cdiv1.DataVolumeSourceVDDK)

UpdateVDDKAnnotations updates the passed annotations for proper VDDK import

func UpdatesMultistageImportSucceeded added in v1.58.0

func UpdatesMultistageImportSucceeded(pvc *corev1.PersistentVolumeClaim, args *CheckpointArgs) error

UpdatesMultistageImportSucceeded handles multi-stage annotations when the importer pod is succeeded

func ValidateClone

func ValidateClone(sourcePVC *corev1.PersistentVolumeClaim, spec *cdiv1.DataVolumeSpec) error

ValidateClone compares a clone spec against its source PVC to validate its creation

func ValidateCloneTokenDV

func ValidateCloneTokenDV(validator token.Validator, dv *cdiv1.DataVolume) error

ValidateCloneTokenDV validates clone token for DV

func ValidateCloneTokenPVC

func ValidateCloneTokenPVC(t string, v token.Validator, source, target *corev1.PersistentVolumeClaim) error

ValidateCloneTokenPVC validates clone token for source and target PVCs

func ValidateRequestedCloneSize

func ValidateRequestedCloneSize(sourceResources corev1.ResourceRequirements, targetResources corev1.ResourceRequirements) error

ValidateRequestedCloneSize validates the clone size requirements on block

func ValidateSnapshotClone

func ValidateSnapshotClone(sourceSnapshot *snapshotv1.VolumeSnapshot, spec *cdiv1.DataVolumeSpec) error

ValidateSnapshotClone compares a snapshot clone spec against its source snapshot to validate its creation

func ValidateSnapshotCloneProvisioners added in v1.57.0

func ValidateSnapshotCloneProvisioners(ctx context.Context, c client.Client, snapshot *snapshotv1.VolumeSnapshot, storageClass *storagev1.StorageClass) (bool, error)

ValidateSnapshotCloneProvisioners validates the target PVC storage class against the snapshot class provisioner

func ValidateSnapshotCloneSize added in v1.57.0

func ValidateSnapshotCloneSize(snapshot *snapshotv1.VolumeSnapshot, pvcSpec *corev1.PersistentVolumeClaimSpec, targetSC *storagev1.StorageClass, log logr.Logger) (bool, error)

ValidateSnapshotCloneSize does proper size validation when doing a clone from snapshot operation

Types

type CheckpointArgs added in v1.58.0

type CheckpointArgs struct {
	Client client.Client
	Log    logr.Logger
	// Checkpoints is a list of DataVolumeCheckpoints, representing stages in a multistage import.
	Checkpoints []cdiv1.DataVolumeCheckpoint
	// IsFinal indicates whether the current DataVolumeCheckpoint is the final checkpoint.
	IsFinal bool
}

CheckpointArgs is a struct used to store all checkpoint-related arguments to simplify passing them.

type CheckpointRecord added in v1.58.0

type CheckpointRecord struct {
	cdiv1.DataVolumeCheckpoint
	IsFinal bool
}

CheckpointRecord is set after comparing the list of checkpoints in the DataVolume/VolumeImportSource spec with the annotations on the PVC indicating which checkpoints have already been copied. Return the first checkpoint that does not have this annotation, meaning the first checkpoint that has not yet been copied.

func GetNextCheckpoint added in v1.58.0

func GetNextCheckpoint(pvc *corev1.PersistentVolumeClaim, args *CheckpointArgs) *CheckpointRecord

GetNextCheckpoint returns the appropriate checkpoint according to multistage annotations

type FakeValidator

type FakeValidator struct {
	Match     string
	Operation token.Operation
	Name      string
	Namespace string
	Resource  metav1.GroupVersionResource
	Params    map[string]string
}

FakeValidator is a fake token validator

func (*FakeValidator) Validate

func (v *FakeValidator) Validate(value string) (*token.Payload, error)

Validate is a fake token validation

type MultiTokenValidator added in v1.57.0

type MultiTokenValidator struct {
	ShortTokenValidator token.Validator
	LongTokenValidator  token.Validator
}

MultiTokenValidator is a token validator that can validate both short and long tokens

func NewMultiTokenValidator added in v1.57.0

func NewMultiTokenValidator(key *rsa.PublicKey) *MultiTokenValidator

NewMultiTokenValidator returns a new multi token validator

func (*MultiTokenValidator) ValidatePVC added in v1.57.0

func (mtv *MultiTokenValidator) ValidatePVC(source, target *corev1.PersistentVolumeClaim) error

ValidatePVC validates a PVC

func (*MultiTokenValidator) ValidatePopulator added in v1.57.0

func (mtv *MultiTokenValidator) ValidatePopulator(vcs *cdiv1.VolumeCloneSource, pvc *corev1.PersistentVolumeClaim) error

ValidatePopulator valades a token for a populator

type PatchArgs added in v1.57.0

type PatchArgs struct {
	Client client.Client
	Log    logr.Logger
	Obj    client.Object
	OldObj client.Object
}

PatchArgs are the args for Patch

type ProgressFromClaimArgs added in v1.57.0

type ProgressFromClaimArgs struct {
	Client       client.Client
	HTTPClient   *http.Client
	Claim        *corev1.PersistentVolumeClaim
	OwnerUID     string
	PodNamespace string
	PodName      string
}

ProgressFromClaimArgs are the args for ProgressFromClaim

Jump to

Keyboard shortcuts

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