utils

package
v7.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

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

	PrefixedSnapshotterListSecretNameKey      = csiParameterPrefix + "snapshotter-list-secret-name"      // Prefixed name key for ListSnapshots secret
	PrefixedSnapshotterListSecretNamespaceKey = csiParameterPrefix + "snapshotter-list-secret-namespace" // Prefixed namespace key for ListSnapshots 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"

	// VolumeSnapshotContentInvalidLabel is applied to invalid content as a label key. The value does not matter.
	// See https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/177-volume-snapshot/tighten-validation-webhook-crd.md#automatic-labelling-of-invalid-objects
	VolumeSnapshotContentInvalidLabel = "snapshot.storage.kubernetes.io/invalid-snapshot-content-resource"
	// VolumeSnapshotInvalidLabel is applied to invalid snapshot as a label key. The value does not matter.
	// See https://github.com/kubernetes/enhancements/blob/master/keps/sig-storage/177-volume-snapshot/tighten-validation-webhook-crd.md#automatic-labelling-of-invalid-objects
	VolumeSnapshotInvalidLabel = "snapshot.storage.kubernetes.io/invalid-snapshot-resource"
	// 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"
)

Variables

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

Functions

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString checks if a given slice of strings contains the provided string.

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 *crdv1alpha1.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 GetGroupSnapshotStatusForLogging

func GetGroupSnapshotStatusForLogging(groupSnapshot *crdv1alpha1.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 *crdv1alpha1.VolumeGroupSnapshot) string

func GroupSnapshotRefKey

func GroupSnapshotRefKey(vgsref *v1.ObjectReference) string

func IsBoundVolumeGroupSnapshotContentNameSet

func IsBoundVolumeGroupSnapshotContentNameSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool

func IsBoundVolumeSnapshotContentNameSet

func IsBoundVolumeSnapshotContentNameSet(snapshot *crdv1.VolumeSnapshot) bool

func IsDefaultAnnotation

func IsDefaultAnnotation(obj metav1.ObjectMeta) bool

IsDefaultAnnotation returns a boolean if the annotation is set

func IsGroupSnapshotCreated

func IsGroupSnapshotCreated(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool

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

func IsGroupSnapshotDeletionCandidate

func IsGroupSnapshotDeletionCandidate(groupSnapshot *crdv1alpha1.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 *crdv1alpha1.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 IsVolumeGroupSnapshotRefSet

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

func IsVolumeSnapshotRefListSet

func IsVolumeSnapshotRefListSet(groupSnapshot *crdv1alpha1.VolumeGroupSnapshot) bool

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 *crdv1alpha1.VolumeGroupSnapshot) bool

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

func NeedToAddGroupSnapshotContentFinalizer

func NeedToAddGroupSnapshotContentFinalizer(groupSnapshotContent *crdv1alpha1.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 NoResyncPeriodFunc

func NoResyncPeriodFunc() time.Duration

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

func PatchVolumeGroupSnapshot

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

PatchVolumeGroupSnapshot patches a volume group snapshot object

func PatchVolumeGroupSnapshotContent

func PatchVolumeGroupSnapshotContent(
	existingGroupSnapshotContent *crdv1alpha1.VolumeGroupSnapshotContent,
	patch []PatchOp,
	client clientset.Interface,
	subresources ...string,
) (*crdv1alpha1.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 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 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.

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