utils

package
v8.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PrefixedSnapshotterSecretNameKey      = csiParameterPrefix + "snapshotter-secret-name"      // Prefixed name key for DeleteSnapshot secret
	PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" // Prefixed namespace key for DeleteSnapshot secret

	PrefixedGroupSnapshotterSecretNameKey      = csiParameterPrefix + "group-snapshotter-secret-name"      // Prefixed name key for CreateGroupSnapshot secret
	PrefixedGroupSnapshotterSecretNamespaceKey = csiParameterPrefix + "group-snapshotter-secret-namespace" // Prefixed namespace key for DeleteGroupSnapshot secret

	PrefixedSnapshotterListSecretNameKey      = csiParameterPrefix + "snapshotter-list-secret-name"      // Prefixed name key for ListSnapshots secret
	PrefixedSnapshotterListSecretNamespaceKey = csiParameterPrefix + "snapshotter-list-secret-namespace" // Prefixed namespace key for ListSnapshots secret

	PrefixedGroupSnapshotterGetSecretNameKey      = csiParameterPrefix + "group-snapshotter-get-secret-name"      // Prefixed name key for GetVolumeGroupSnapshot secret
	PrefixedGroupSnapshotterGetSecretNamespaceKey = csiParameterPrefix + "group-snapshotter-get-secret-namespace" // Prefixed namespace key for GetVolumeGroupSnapshot secret

	PrefixedVolumeSnapshotNameKey        = csiParameterPrefix + "volumesnapshot/name"        // Prefixed VolumeSnapshot name key
	PrefixedVolumeSnapshotNamespaceKey   = csiParameterPrefix + "volumesnapshot/namespace"   // Prefixed VolumeSnapshot namespace key
	PrefixedVolumeSnapshotContentNameKey = csiParameterPrefix + "volumesnapshotcontent/name" // Prefixed VolumeSnapshotContent name key

	PrefixedVolumeGroupSnapshotNameKey        = csiParameterPrefix + "volumegroupsnapshot/name"        // Prefixed VolumeGroupSnapshot name key
	PrefixedVolumeGroupSnapshotNamespaceKey   = csiParameterPrefix + "volumegroupsnapshot/namespace"   // Prefixed VolumeGroupSnapshot namespace key
	PrefixedVolumeGroupSnapshotContentNameKey = csiParameterPrefix + "volumegroupsnapshotcontent/name" // Prefixed VolumeGroupSnapshotContent name key

	// Name of finalizer on VolumeSnapshotContents that are bound by VolumeSnapshots
	VolumeSnapshotContentFinalizer = "snapshot.storage.kubernetes.io/volumesnapshotcontent-bound-protection"
	// Name of finalizer on VolumeSnapshot that is being used as a source to create a PVC
	VolumeSnapshotBoundFinalizer = "snapshot.storage.kubernetes.io/volumesnapshot-bound-protection"
	// Name of finalizer on VolumeSnapshot that is used as a source to create a PVC
	VolumeSnapshotAsSourceFinalizer = "snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection"
	// Name of finalizer on VolumeSnapshot that is a part of a VolumeGroupSnapshot
	VolumeSnapshotInGroupFinalizer = "snapshot.storage.kubernetes.io/volumesnapshot-in-group-protection"
	// Name of finalizer on PVCs that is being used as a source to create VolumeSnapshots
	PVCFinalizer = "snapshot.storage.kubernetes.io/pvc-as-source-protection"
	// Name of finalizer on VolumeGroupSnapshotContents that are bound by VolumeGroupSnapshots
	VolumeGroupSnapshotContentFinalizer = "groupsnapshot.storage.kubernetes.io/volumegroupsnapshotcontent-bound-protection"
	// Name of finalizer on VolumeGroupSnapshots that are bound to VolumeGroupSnapshotContents
	VolumeGroupSnapshotBoundFinalizer = "groupsnapshot.storage.kubernetes.io/volumegroupsnapshot-bound-protection"

	IsDefaultSnapshotClassAnnotation      = "snapshot.storage.kubernetes.io/is-default-class"
	IsDefaultGroupSnapshotClassAnnotation = "groupsnapshot.storage.kubernetes.io/is-default-class"

	// AnnVolumeSnapshotBeingDeleted annotation applies to VolumeSnapshotContents.
	// It indicates that the common snapshot controller has verified that volume
	// snapshot has a deletion timestamp and is being deleted.
	// Sidecar controller needs to check the deletion policy on the
	// VolumeSnapshotContentand and decide whether to delete the volume snapshot
	// backing the snapshot content.
	AnnVolumeSnapshotBeingDeleted = "snapshot.storage.kubernetes.io/volumesnapshot-being-deleted"

	// AnnVolumeSnapshotBeingCreated annotation applies to VolumeSnapshotContents.
	// If it is set, it indicates that the csi-snapshotter
	// sidecar has sent the create snapshot request to the storage system and
	// is waiting for a response of success or failure.
	// This annotation will be removed once the driver's CreateSnapshot
	// CSI function returns success or a final error (determined by isFinalError()).
	// If the create snapshot request fails with a non-final error such as timeout,
	// retry will happen and the annotation will remain.
	// This only applies to dynamic provisioning of snapshots because
	// the create snapshot CSI method will not be called for pre-provisioned
	// snapshots.
	AnnVolumeSnapshotBeingCreated = "snapshot.storage.kubernetes.io/volumesnapshot-being-created"

	// AnnVolumeGroupSnapshotBeingCreated annotation applies to VolumeGroupSnapshotContents.
	// If it is set, it indicates that the csi-snapshotter
	// sidecar has sent the create group snapshot request to the storage system and
	// is waiting for a response of success or failure.
	// This annotation will be removed once the driver's CreateGroupSnapshot
	// CSI function returns success or a final error (determined by isFinalError()).
	// If the create group snapshot request fails with a non-final error such as timeout,
	// retry will happen and the annotation will remain.
	// This only applies to dynamic provisioning of group snapshots because
	// the create group snapshot CSI method will not be called for pre-provisioned
	// group snapshots.
	AnnVolumeGroupSnapshotBeingCreated = "groupsnapshot.storage.kubernetes.io/volumegroupsnapshot-being-created"

	// AnnVolumeGroupSnapshotBeingDeleted annotation applies to VolumeGroupSnapshotContents.
	// It indicates that the common snapshot controller has verified that volume
	// group snapshot has a deletion timestamp and is being deleted.
	// Sidecar controller needs to check the deletion policy on the
	// VolumeGroupSnapshotContent and decide whether to delete the volume group snapshot
	// backing the group snapshot content.
	AnnVolumeGroupSnapshotBeingDeleted = "groupsnapshot.storage.kubernetes.io/volumegroupsnapshot-being-deleted"

	// Annotation for secret name and namespace will be added to the content
	// and used at snapshot content deletion time.
	AnnDeletionSecretRefName      = "snapshot.storage.kubernetes.io/deletion-secret-name"
	AnnDeletionSecretRefNamespace = "snapshot.storage.kubernetes.io/deletion-secret-namespace"

	// Annotation for secret name and namespace will be added to the group
	// snapshot content and used at group snapshot content deletion time.
	AnnDeletionGroupSecretRefName      = "groupsnapshot.storage.kubernetes.io/deletion-secret-name"
	AnnDeletionGroupSecretRefNamespace = "groupsnapshot.storage.kubernetes.io/deletion-secret-namespace"

	// VolumeGroupSnapshotHandleAnnotation is applied to VolumeSnapshotContents that are member
	// of a VolumeGroupSnapshotContent, and indicates the handle of the latter.
	//
	// This annotation is applied to inform the sidecar not to call CSI driver
	// to create snapshot if the snapshot belongs to a group.
	VolumeGroupSnapshotHandleAnnotation = "groupsnapshot.storage.k8s.io/volumeGroupSnapshotHandle"

	// VolumeSnapshotContentManagedByLabel is applied by the snapshot controller to the VolumeSnapshotContent object in case distributed snapshotting is enabled.
	// The value contains the name of the node that handles the snapshot for the volume local to that node.
	VolumeSnapshotContentManagedByLabel = "snapshot.storage.kubernetes.io/managed-by"
)
View Source
const CSIDriverHandleIndexName = "ByVolumeHandle"
View Source
const VolumeSnapshotParentGroupIndex = "ByVolumeGroupSnapshotMembership"

VolumeSnapshotParentGroupIndex is the name of the cache index hosting the relationship between volume snapshots and their volume group snapshot owner

Variables

View Source
var GroupSnapshotterGetSecretParams = secretParamsMap{
	// contains filtered or unexported fields
}
View Source
var GroupSnapshotterSecretParams = secretParamsMap{
	// contains filtered or unexported fields
}
View Source
var SnapshotterListSecretParams = secretParamsMap{
	// contains filtered or unexported fields
}
View Source
var SnapshotterSecretParams = secretParamsMap{
	// contains filtered or unexported fields
}

Functions

func BuildVolumeGroupSnapshotOwnerReference added in v8.2.0

func BuildVolumeGroupSnapshotOwnerReference(parentGroup *crdv1beta1.VolumeGroupSnapshot) metav1.OwnerReference

BuildVolumeGroupSnapshotOwnerReference creates a OwnerReference record declaring an object as a child of passed VolumeGroupSnapshot

func GetCredentials

func GetCredentials(k8s kubernetes.Interface, ref *v1.SecretReference) (map[string]string, error)

GetCredentials retrieves credentials stored in v1.SecretReference

func GetDynamicSnapshotContentNameForGroupSnapshot

func GetDynamicSnapshotContentNameForGroupSnapshot(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) string

GetDynamicSnapshotContentNameFoGrouprSnapshot returns a unique content name for the passed in VolumeGroupSnapshot to dynamically provision a group snapshot.

func GetDynamicSnapshotContentNameForSnapshot

func GetDynamicSnapshotContentNameForSnapshot(snapshot *crdv1.VolumeSnapshot) string

GetDynamicSnapshotContentNameForSnapshot returns a unique content name for the passed in VolumeSnapshot to dynamically provision a snapshot.

func GetGroupSnapshotSecretReference

func GetGroupSnapshotSecretReference(secretParams secretParamsMap, volumeGroupSnapshotClassParams map[string]string, groupSnapContentName string, volumeGroupSnapshot *crdv1beta1.VolumeGroupSnapshot) (*v1.SecretReference, error)

GetSecretReference for the group snapshot

func GetGroupSnapshotStatusForLogging

func GetGroupSnapshotStatusForLogging(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) string

func GetSecretReference

func GetSecretReference(secretParams secretParamsMap, snapshotClassParams map[string]string, snapContentName string, snapshot *crdv1.VolumeSnapshot) (*v1.SecretReference, error)

getSecretReference returns a reference to the secret specified in the given nameTemplate and namespaceTemplate, or an error if the templates are not specified correctly. No lookup of the referenced secret is performed, and the secret may or may not exist.

supported tokens for name resolution: - ${volumesnapshotcontent.name} - ${volumesnapshot.namespace} - ${volumesnapshot.name}

supported tokens for namespace resolution: - ${volumesnapshotcontent.name} - ${volumesnapshot.namespace}

an error is returned in the following situations: - the nameTemplate or namespaceTemplate contains a token that cannot be resolved - the resolved name is not a valid secret name - the resolved namespace is not a valid namespace name

func GetSnapshotStatusForLogging

func GetSnapshotStatusForLogging(snapshot *crdv1.VolumeSnapshot) string

Stateless functions

func GroupSnapshotKey

func GroupSnapshotKey(vgs *crdv1beta1.VolumeGroupSnapshot) string

func GroupSnapshotRefKey

func GroupSnapshotRefKey(vgsref *v1.ObjectReference) string

func IsBoundVolumeGroupSnapshotContentNameSet

func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) bool

func IsBoundVolumeSnapshotContentNameSet

func IsBoundVolumeSnapshotContentNameSet(snapshot *crdv1.VolumeSnapshot) bool

func IsGroupSnapshotCreated

func IsGroupSnapshotCreated(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) bool

IsGroupSnapshotCreated indicates that the group snapshot has been cut on a storage system

func IsGroupSnapshotDeletionCandidate

func IsGroupSnapshotDeletionCandidate(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) bool

IsGroupSnapshotDeletionCandidate checks if a volume group snapshot deletionTimestamp is set and any finalizer is on the group snapshot.

func IsGroupSnapshotReady

func IsGroupSnapshotReady(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) bool

func IsSnapshotCreated

func IsSnapshotCreated(snapshot *crdv1.VolumeSnapshot) bool

IsSnapshotCreated indicates that the snapshot has been cut on a storage system

func IsSnapshotDeletionCandidate

func IsSnapshotDeletionCandidate(snapshot *crdv1.VolumeSnapshot) bool

IsSnapshotDeletionCandidate checks if a volume snapshot deletionTimestamp is set and any finalizer is on the snapshot.

func IsSnapshotReady

func IsSnapshotReady(snapshot *crdv1.VolumeSnapshot) bool

func IsVolumeGroupSnapshotClassDefaultAnnotation added in v8.1.0

func IsVolumeGroupSnapshotClassDefaultAnnotation(obj metav1.ObjectMeta) bool

IsVolumeGroupSnapshotClassDefaultAnnotation returns a true boolean if a VolumeGroupSnapshotClass is marked as the default one

func IsVolumeGroupSnapshotMember added in v8.2.0

func IsVolumeGroupSnapshotMember(snapshot *crdv1.VolumeSnapshot) bool

IsVolumeGroupSnapshotMember returns true if the passed VolumeSnapshot object is a member of a VolumeGroupSnapshot.

func IsVolumeGroupSnapshotRefSet

func IsVolumeGroupSnapshotRefSet(groupSnapshot *crdv1beta1.VolumeGroupSnapshot, content *crdv1beta1.VolumeGroupSnapshotContent) bool

func IsVolumeSnapshotClassDefaultAnnotation added in v8.1.0

func IsVolumeSnapshotClassDefaultAnnotation(obj metav1.ObjectMeta) bool

IsVolumeSnapshotClassDefaultAnnotation returns a true boolean if a VolumeSnapshotClass is marked as the default one

func IsVolumeSnapshotRefSet

func IsVolumeSnapshotRefSet(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) bool

func MapContainsKey

func MapContainsKey(m map[string]string, s string) bool

MapContainsKey checks if a given map of string to string contains the provided string.

func NeedToAddContentFinalizer

func NeedToAddContentFinalizer(content *crdv1.VolumeSnapshotContent) bool

NeedToAddContentFinalizer checks if a Finalizer needs to be added for the volume snapshot content.

func NeedToAddGroupSnapshotBoundFinalizer

func NeedToAddGroupSnapshotBoundFinalizer(groupSnapshot *crdv1beta1.VolumeGroupSnapshot) bool

NeedToAddGroupSnapshotBoundFinalizer checks if a Finalizer needs to be added for the bound volume group snapshot.

func NeedToAddGroupSnapshotContentFinalizer

func NeedToAddGroupSnapshotContentFinalizer(groupSnapshotContent *crdv1beta1.VolumeGroupSnapshotContent) bool

NeedToAddGroupSnapshotContentFinalizer checks if a Finalizer needs to be added for the volume group snapshot content.

func NeedToAddSnapshotAsSourceFinalizer

func NeedToAddSnapshotAsSourceFinalizer(snapshot *crdv1.VolumeSnapshot) bool

NeedToAddSnapshotAsSourceFinalizer checks if a Finalizer needs to be added for the volume snapshot as a source for PVC.

func NeedToAddSnapshotBoundFinalizer

func NeedToAddSnapshotBoundFinalizer(snapshot *crdv1.VolumeSnapshot) bool

NeedToAddSnapshotBoundFinalizer checks if a Finalizer needs to be added for the bound volume snapshot.

func NeedToAddVolumeGroupSnapshotOwnership added in v8.2.0

func NeedToAddVolumeGroupSnapshotOwnership(snapshot *crdv1.VolumeSnapshot) bool

NeedToAddVolumeGroupSnapshotOwnership checks if the passed snapshot is a member of a volume group snapshot but the ownership is missing

func NoResyncPeriodFunc

func NoResyncPeriodFunc() time.Duration

NoResyncPeriodFunc Returns 0 for resyncPeriod in case resyncing is not needed.

func PatchVolumeGroupSnapshot

func PatchVolumeGroupSnapshot(
	existingGroupSnapshot *crdv1beta1.VolumeGroupSnapshot,
	patch []PatchOp,
	client clientset.Interface,
	subresources ...string,
) (*crdv1beta1.VolumeGroupSnapshot, error)

PatchVolumeGroupSnapshot patches a volume group snapshot object

func PatchVolumeGroupSnapshotContent

func PatchVolumeGroupSnapshotContent(
	existingGroupSnapshotContent *crdv1beta1.VolumeGroupSnapshotContent,
	patch []PatchOp,
	client clientset.Interface,
	subresources ...string,
) (*crdv1beta1.VolumeGroupSnapshotContent, error)

PatchVolumeGroupSnapshotContent patches a volume group snapshot content object

func PatchVolumeSnapshot

func PatchVolumeSnapshot(
	existingSnapshot *crdv1.VolumeSnapshot,
	patch []PatchOp,
	client clientset.Interface,
	subresources ...string,
) (*crdv1.VolumeSnapshot, error)

PatchVolumeSnapshot patches a volume snapshot object

func PatchVolumeSnapshotContent

func PatchVolumeSnapshotContent(
	existingSnapshotContent *crdv1.VolumeSnapshotContent,
	patch []PatchOp,
	client clientset.Interface,
	subresources ...string,
) (*crdv1.VolumeSnapshotContent, error)

PatchVolumeSnapshotContent patches a volume snapshot content object

func PersistentVolumeKeyFunc added in v8.2.0

func PersistentVolumeKeyFunc(pv *v1.PersistentVolume) string

PersistentVolumeKeyFunc maps a persistent volume to a string usable as KeyFunc to recover it from the CSI driver name and the volume handle. If the passed PV is not CSI-based, it will return the empty string

func PersistentVolumeKeyFuncByCSIDriverHandle added in v8.2.0

func PersistentVolumeKeyFuncByCSIDriverHandle(driverName, volumeHandle string) string

PersistentVolumeKeyFuncByCSIDriverHandle returns the key to be used form the individual data components

func RemovePrefixedParameters

func RemovePrefixedParameters(param map[string]string) (map[string]string, error)

func RemoveString

func RemoveString(slice []string, s string) []string

RemoveString returns a newly created []string that contains all items from slice that are not equal to s.

func ShouldEnqueueContentChange

func ShouldEnqueueContentChange(old *crdv1.VolumeSnapshotContent, new *crdv1.VolumeSnapshotContent) bool

ShouldEnqueueContentChange indicated whether or not a change to a VolumeSnapshotContent object is a change that should be enqueued for sync

The following changes are sanitized (and thus, not considered for determining whether to sync)

  • Resource Version (always changed between objects)
  • Status (owned and updated only by the sidecar)
  • Managed Fields (updated by sidecar, and will not change the sync status)
  • Finalizers (updated by sidecar, and will not change the sync status)
  • Sidecar-Owned Annotations (annotations that are owned and updated only by the sidecar) (some annotations, such as AnnVolumeSnapshotBeingDeleted, are applied by the controller - so only annotatinons entirely controlled by the sidecar are ignored)

If the VolumeSnapshotContent object still contains other changes after this sanitization, the changes are potentially meaningful and the object is enqueued to be considered for syncing

func SnapshotKey

func SnapshotKey(vs *crdv1.VolumeSnapshot) string

func SnapshotRefKey

func SnapshotRefKey(vsref *v1.ObjectReference) string

func StoreObjectUpdate

func StoreObjectUpdate(store cache.Store, obj interface{}, className string) (bool, error)

storeObjectUpdate updates given cache with a new object version from Informer callback (i.e. with events from etcd) or with an object modified by the controller itself. Returns "true", if the cache was updated, false if the object is an old version and should be ignored.

func VolumeSnapshotParentGroupKeyFunc added in v8.2.0

func VolumeSnapshotParentGroupKeyFunc(snapshot *crdv1.VolumeSnapshot) string

VolumeSnapshotParentGroupKeyFunc maps a member snapshot to the name of the parent VolumeGroupSnapshot

func VolumeSnapshotParentGroupKeyFuncByComponents added in v8.2.0

func VolumeSnapshotParentGroupKeyFuncByComponents(objectKey types.NamespacedName) string

VolumeSnapshotParentGroupKeyFuncByComponents computes the index key for a certain name and namespace pair

Types

type PatchOp

type PatchOp struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value,omitempty"`
}

PatchOp represents a json patch operation

Jump to

Keyboard shortcuts

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