utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DoNotDeleteLabelKey = volsyncLabelPrefix + "/do-not-delete"
	OwnedByLabelKey     = "app.kubernetes.io/created-by"
	OwnedByLabelValue   = "volsync"
)
View Source
const DefaultSCCName = "volsync-privileged-mover"

DefaultSCCName is the default name of the volsync security context constraint

View Source
const (
	ErrUnableToSetControllerRef = "unable to set controller reference"
)

Define the error messages to be returned by VolSync.

Variables

View Source
var SCCName string

SCCName is the name of the SCC to use for the mover Jobs

Functions

func AddAllLabels added in v0.5.0

func AddAllLabels(obj Labelable, labels map[string]string) bool

Ensures that all labels in the provided map are present and returns True if an update was made

func AddLabel added in v0.5.0

func AddLabel(obj Labelable, key string, value string) bool

Ensures that a given key/value label is present and returns True if an update was made

func CleanupObjects

func CleanupObjects(ctx context.Context, c client.Client,
	logger logr.Logger, owner client.Object, types []client.Object) error

CleanupObjects deletes all objects that have been marked. The objects to be cleaned up must have been previously marked via MarkForCleanup() and associated with "owner". The "types" array should contain one object of each type to clean up.

func CleanupSnapshotsWithLabelCheck added in v0.5.0

func CleanupSnapshotsWithLabelCheck(ctx context.Context, c client.Client,
	logger logr.Logger, owner client.Object, snapList *snapv1.VolumeSnapshotList) error

func CreateOrUpdateDeleteOnImmutableErr added in v0.5.0

func CreateOrUpdateDeleteOnImmutableErr(ctx context.Context, k8sClient client.Client, obj client.Object,
	log logr.Logger, f ctrlutil.MutateFn) (ctrlutil.OperationResult, error)

If an update causes an immutable error, delete the object and return an error (or potentially an error from the delete if the delete fails). The caller should ensure (usually via a requeue) that createOrUpdate is called on the resource again in order for it to be recreated.

func EnvFromSecret

func EnvFromSecret(secretName string, field string, optional bool) corev1.EnvVar

func GetAndValidateSecret

func GetAndValidateSecret(ctx context.Context, cl client.Client,
	logger logr.Logger, secret *corev1.Secret, fields ...string) error

func GetServiceAddress added in v0.5.0

func GetServiceAddress(svc *corev1.Service) string

GetServiceAddress Returns the address of the given service as a string.

func HasLabel added in v0.5.0

func HasLabel(obj Labelable, key string) bool

func HasLabelWithValue added in v0.5.0

func HasLabelWithValue(obj Labelable, key string, value string) bool

func IsMarkedDoNotDelete added in v0.5.0

func IsMarkedDoNotDelete(snapshot *snapv1.VolumeSnapshot) bool

func IsOwnedByVolsync added in v0.5.0

func IsOwnedByVolsync(obj Labelable) bool

Returns True if the object contains a label indicating that it was created by VolSync

func KindAndName added in v0.5.0

func KindAndName(scheme *runtime.Scheme, obj client.Object) string

func MarkForCleanup

func MarkForCleanup(owner metav1.Object, obj metav1.Object) bool

MarkForCleanup marks the provided "obj" to be deleted at the end of the synchronization iteration.

func MarkOldSnapshotForCleanup added in v0.4.0

func MarkOldSnapshotForCleanup(ctx context.Context, c client.Client, logger logr.Logger,
	owner metav1.Object, oldImage, latestImage *corev1.TypedLocalObjectReference) error

func PrivilegedMoversOk added in v0.6.0

func PrivilegedMoversOk(ctx context.Context, cl client.Client, logger logr.Logger,
	namespace string) (bool, error)

func PvcIsReadOnly added in v0.6.0

func PvcIsReadOnly(pvc *corev1.PersistentVolumeClaim) bool

func ReconcileBatch

func ReconcileBatch(l logr.Logger, reconcileFuncs ...ReconcileFunc) (bool, error)

reconcileBatch steps through a list of reconcile functions until one returns false or an error.

func RelinquishOwnedSnapshotsWithDoNotDeleteLabel added in v0.5.0

func RelinquishOwnedSnapshotsWithDoNotDeleteLabel(ctx context.Context, c client.Client,
	logger logr.Logger, owner client.Object) error

func RemoveLabel added in v0.5.0

func RemoveLabel(obj Labelable, key string) bool

Removes the given key from the object's labels and returns True if an update was made

func RemoveOwnedByVolSync added in v0.5.0

func RemoveOwnedByVolSync(obj Labelable) bool

Removes the "created by Volsync" label

func RemoveSnapshotOwnershipIfRequestedAndUpdate added in v0.5.0

func RemoveSnapshotOwnershipIfRequestedAndUpdate(ctx context.Context, c client.Client, logger logr.Logger,
	owner client.Object, snapshot *snapv1.VolumeSnapshot) (bool, error)

func SecretHasFields added in v0.4.0

func SecretHasFields(secret *corev1.Secret, fields ...string) error

func SetOwnedByVolSync added in v0.5.0

func SetOwnedByVolSync(obj Labelable) bool

Sets a label on the object to indicate it was created by VolSync

func UnMarkForCleanupAndRemoveOwnership added in v0.5.0

func UnMarkForCleanupAndRemoveOwnership(obj metav1.Object, owner client.Object) bool

func UnmarkForCleanup added in v0.5.0

func UnmarkForCleanup(obj metav1.Object) bool

UnmarkForCleanup removes any previously applied cleanup label

Types

type AffinityInfo added in v0.5.0

type AffinityInfo struct {
	NodeSelector map[string]string
	Tolerations  []corev1.Toleration
}

func AffinityFromVolume added in v0.5.0

func AffinityFromVolume(ctx context.Context, c client.Client, logger logr.Logger,
	pvc *corev1.PersistentVolumeClaim) (*AffinityInfo, error)

Determine the proper affinity to apply based on the current users of a PVC

type Labelable added in v0.5.0

type Labelable interface {
	GetLabels() map[string]string
	SetLabels(labels map[string]string)
}

type ReconcileFunc

type ReconcileFunc func(logr.Logger) (bool, error)

reconcileFunc is a function that partially reconciles an object. It returns a bool indicating whether reconciling should continue and an error.

type SAHandler

type SAHandler struct {
	Context    context.Context
	Client     client.Client
	SA         *corev1.ServiceAccount
	Owner      metav1.Object
	Privileged bool
	// contains filtered or unexported fields
}

func NewSAHandler

func NewSAHandler(ctx context.Context, c client.Client, owner metav1.Object, sa *corev1.ServiceAccount,
	privileged bool) SAHandler

func (*SAHandler) Reconcile

func (d *SAHandler) Reconcile(l logr.Logger) (bool, error)

Jump to

Keyboard shortcuts

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