common

package
v0.0.0-...-aaeb662 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KiB is is 1024 bytes
	KiB int64 = 1024
	// MiB is is 1024 KiB
	MiB = 1024 * KiB
	// GiB is 1024 MiB
	GiB = 1024 * MiB
	// TiB is 1024 GiB
	TiB = 1024 * GiB
)
View Source
const (

	// OwnerNamespaceLabel references the owning object's namespace
	OwnerNamespaceLabel = "local.storage.openshift.io/owner-namespace"
	// OwnerNameLabel references the owning object
	OwnerNameLabel = "local.storage.openshift.io/owner-name"
	// OwnerKindLabel references the owning object's kind
	OwnerKindLabel = "local.storage.openshift.io/owner-kind"

	// DiskMakerImageEnv is used by the operator to read the DISKMAKER_IMAGE from the environment
	DiskMakerImageEnv = "DISKMAKER_IMAGE"
	// KubeRBACProxyImageEnv is used by the operator to read the KUBE_RBAC_PROXY_IMAGE from the environment
	KubeRBACProxyImageEnv = "KUBE_RBAC_PROXY_IMAGE"
	// LocalDiskLocationEnv is passed to the operator to override the LOCAL_DISK_LOCATION host directory
	LocalDiskLocationEnv = "LOCAL_DISK_LOCATION"

	// ProvisionerConfigMapName is the name of the local-static-provisioner configmap
	ProvisionerConfigMapName = "local-provisioner"

	// DiscoveryNodeLabelKey is the label key on the discovery result CR used to identify the node it belongs to.
	// the value is the node's name
	DiscoveryNodeLabel = "discovery-result-node"

	LocalVolumeStorageClassTemplate     = "templates/localvolume-storageclass.yaml"
	LocalProvisionerConfigMapTemplate   = "templates/local-provisioner-configmap.yaml"
	DiskMakerManagerDaemonSetTemplate   = "templates/diskmaker-manager-daemonset.yaml"
	DiskMakerDiscoveryDaemonSetTemplate = "templates/diskmaker-discovery-daemonset.yaml"
	MetricsServiceTemplate              = "templates/localmetrics/service.yaml"
	MetricsServiceMonitorTemplate       = "templates/localmetrics/service-monitor.yaml"
	PrometheusRuleTemplate              = "templates/localmetrics/prometheus-rule.yaml"

	// DiskMakerServiceName is the name of the service created for the diskmaker daemon
	DiskMakerServiceName = "local-storage-diskmaker-metrics"

	// DiscoveryServiceName is the name of the service created for the diskmaker discovery daemon
	DiscoveryServiceName = "local-storage-discovery-metrics"

	// DiskMakerMetricsServingCert is the name of secret created for diskmaker service to store TLS config
	DiskMakerMetricsServingCert = "diskmaker-metric-serving-cert"

	// DiscoveryMetricsServingCert is the name of secret created for discovery service to store TLS config
	DiscoveryMetricsServingCert = "discovery-metric-serving-cert"
	// LocalVolumeProtectionFinalizer is set to ensure the provisioner daemonset and owning object stick around long
	// enough to handle the PV reclaim policy.
	LocalVolumeProtectionFinalizer = "storage.openshift.com/local-volume-protection"
	// LSOSymlinkDeleterFinalizer is set to ensure diskmaker has a chance
	// to remove the symlink used by the PV before it is deleted.
	LSOSymlinkDeleterFinalizer = "storage.openshift.com/lso-symlink-deleter"
)
View Source
const (
	// LocalVolumeOwnerNameForPV stores name of LocalVolume that created this PV
	LocalVolumeOwnerNameForPV = "storage.openshift.com/local-volume-owner-name"
	// LocalVolumeOwnerNamespaceForPV stores namespace of LocalVolume that created this PV
	LocalVolumeOwnerNamespaceForPV = "storage.openshift.com/local-volume-owner-namespace"

	// PVOwnerKindLabel stores the namespace of the CR that created this PV
	PVOwnerKindLabel = "storage.openshift.com/owner-kind"
	// PVOwnerNameLabel stores the name of the CR that created this PV
	PVOwnerNameLabel = "storage.openshift.com/owner-name"
	// PVOwnerNamespaceLabel stores the namespace of the CR that created this PV
	PVOwnerNamespaceLabel = "storage.openshift.com/owner-namespace"
	// PVDeviceNameLabel is the KNAME of the device
	PVDeviceNameLabel = "storage.openshift.com/device-name"
	// PVDeviceIDLabel is the id of the device
	PVDeviceIDLabel = "storage.openshift.com/device-id"
)
View Source
const (
	// DeviceLinkSymlinkRecreateConditionType is the condition type set on LVDL when symlink recreation fails.
	DeviceSymlinkErrorType = "SymlinkRecreateError"
)

Variables

View Source
var (

	// SymlinkHostDirVolume is the corev1.Volume definition for the lso symlink host directory.
	// "/mnt/local-storage" is the default, but it can be controlled by env vars.
	// SymlinkMount is the corresponding mount
	SymlinkHostDirVolume = corev1.Volume{
		Name: "local-disks",
		VolumeSource: corev1.VolumeSource{
			HostPath: &corev1.HostPathVolumeSource{
				Path: GetLocalDiskLocationPath(),
			},
		},
	}
	// SymlinkMount is the corresponding mount for SymlinkHostDirVolume
	SymlinkMount = corev1.VolumeMount{
		Name:             "local-disks",
		MountPath:        GetLocalDiskLocationPath(),
		MountPropagation: &hostContainerPropagation,
	}

	// DevHostDirVolume  is the corev1.Volume definition for the "/dev" bind mount used to
	// list block devices.
	// DevMount is the corresponding mount
	DevHostDirVolume = corev1.Volume{
		Name: devDirVolName,
		VolumeSource: corev1.VolumeSource{
			HostPath: &corev1.HostPathVolumeSource{
				Path: devDirPath,
				Type: &directoryHostPath,
			},
		},
	}
	// DevMount is the corresponding mount for DevHostDirVolume
	DevMount = corev1.VolumeMount{
		Name:             devDirVolName,
		MountPath:        devDirPath,
		MountPropagation: &hostContainerPropagation,
	}

	// ProvisionerConfigHostDirVolume is the corev1.Volume definition for the
	// local-static-provisioner configmap
	// ProvisionerConfigMount is the corresponding mount
	ProvisionerConfigHostDirVolume = corev1.Volume{
		Name: provisionerConfigVolName,
		VolumeSource: corev1.VolumeSource{
			ConfigMap: &corev1.ConfigMapVolumeSource{
				LocalObjectReference: corev1.LocalObjectReference{
					Name: ProvisionerConfigMapName,
				},
			},
		},
	}

	// ProvisionerConfigMount is the corresponding mount for ProvisionerConfigHostDirVolume
	ProvisionerConfigMount = corev1.VolumeMount{
		Name:      provisionerConfigVolName,
		ReadOnly:  true,
		MountPath: "/etc/provisioner/config",
	}

	// UDevHostDirVolume is the corev1.Volume definition for the
	// "/run/udev" host bind-mount. This helps lsblk give more accurate output.
	// UDevMount is the corresponding mount
	UDevHostDirVolume = corev1.Volume{
		Name: udevVolName,
		VolumeSource: corev1.VolumeSource{
			HostPath: &corev1.HostPathVolumeSource{Path: udevPath},
		},
	}
	// UDevMount is the corresponding mount for UDevHostDirVolume
	UDevMount = corev1.VolumeMount{
		Name:             udevVolName,
		MountPath:        udevPath,
		MountPropagation: &hostContainerPropagation,
	}
)

DeprecatedLabels: these labels were deprecated because the potential values weren't all compatible label values they have been move to annotations

View Source
var ErrTryAgain = errors.New("retry provisioning")

Functions

func AddOrUpdatePV

func AddOrUpdatePV(r *provCommon.RuntimeConfig, pv *corev1.PersistentVolume)

func ApplyStorageClass

ApplyStorageClass applies the given StorageClass to the cluster if it does not already exist or is different Returns the StorageClass as it exists in the cluster, whether it was created or updated, and any error that occurred.

func CleanupSymlinks(c client.Client, r *provCommon.RuntimeConfig, ownerLabels map[string]string, shouldDeleteSymlinkFnArg ConditionalSymlinkRemoval) error

CleanupSymlinks processes deleted PersistentVolumes with the storage.openshift.com/lso-symlink-deleter finalizer, removes the symlink, and then removes the finalizer to allow the PV deletion to complete. The ownerLabels arg allows the caller to only process PV's with those labels. The shouldDeleteSymlinkFnArg callback allows the caller to selectively remove symlinks for a subset of PV's but still remove the finalizer for all of them.

func EnqueueOnlyLabeledSubcomponents

func EnqueueOnlyLabeledSubcomponents(components ...string) predicate.Predicate

EnqueueOnlyLabeledSubcomponents returns a predicate that filters only objects that have labels["app"] in components

func GenerateMountMap

func GenerateMountMap(runtimeConfig *provCommon.RuntimeConfig) (sets.Set[string], error)

GenerateMountMap is used to get a set of mountpoints that can be quickly looked up

func GeneratePVName

func GeneratePVName(file, node, class string) string

GeneratePVName is used to generate a PV name based on the filename, node, and storageclass Important, this hash value should remain consistent, so this function should not be changed in a way that would change its output.

func GetDiskMakerImage

func GetDiskMakerImage() string

GetDiskMakerImage returns the image to be used for diskmaker daemonset

func GetKubeRBACProxyImage

func GetKubeRBACProxyImage() string

GetKubeRBACProxyImage returns the image to be used for Kube RBAC Proxy sidecar container

func GetLocalDiskLocationPath

func GetLocalDiskLocationPath() string

GetLocalDiskLocationPath return the local disk path

func GetNodeNameEnvVar

func GetNodeNameEnvVar() string

GetNodeNameEnvVar returns the node name from env vars

func GetOwnedPVs

func GetOwnedPVs(obj runtime.Object, c client.Client) ([]corev1.PersistentVolume, error)

GetOwnedPVs returns a list of PV's owned by the object

func GetPVOwnerSelector

func GetPVOwnerSelector(lv *localv1.LocalVolume) labels.Selector

GetPVOwnerSelector returns selector for selecting pvs owned by given volume

func GetProvisionedByValue

func GetProvisionedByValue(node corev1.Node) string

GetProvisionedByValue is the the annotation that indicates which node a PV was originally provisioned on the key is provCommon.AnnProvisionedBy ("pv.kubernetes.io/provisioned-by")

func GetSymLinkSourceAndTarget

func GetSymLinkSourceAndTarget(dev internal.BlockDevice, symlinkDir string) (string, string, bool, error)

GetSymLinkSourceAndTarget returns `source`: the /dev/disk/by-id path of the device if it exists, /dev/KNAME if it doesn't `target`: the path in the symlinkdir to symlink to. device-id if it exists, KNAME if it doesn't `idExists`: is set if the device-id exists `err`

func GetSymlinkedForCurrentSC

func GetSymlinkedForCurrentSC(symlinkDir string, kname string) (string, error)

func GetWatchNamespace

func GetWatchNamespace() (string, error)

GetWatchNamespace returns the namespace the operator should be watching for changes

func HandlePVChange

func HandlePVChange(runtimeConfig *provCommon.RuntimeConfig, pv *corev1.PersistentVolume, q workqueue.TypedRateLimitingInterface[reconcile.Request], watchNamespace string, isDelete bool)

func HasExistingLocalVolumes

func HasExistingLocalVolumes(ctx context.Context, client client.Client, symlinkDir string, blockDevice internal.BlockDevice, pvLinkCache *LocalVolumeDeviceLinkCache) (string, error)
func HasMismatchingSymlink(lvdl *v1.LocalVolumeDeviceLink, blockDevice internal.BlockDevice) bool

func InitMapIfNil

func InitMapIfNil(m *map[string]string)

InitMapIfNil allocates memory to a map if it is nil

func IsLocalVolumePV

func IsLocalVolumePV(pv *corev1.PersistentVolume) bool

func IsLocalVolumeSetPV

func IsLocalVolumeSetPV(pv *corev1.PersistentVolume) bool

func LocalVolumeKey

func LocalVolumeKey(lv *localv1.LocalVolume) string

LocalVolumeKey returns key for the localvolume

func LocalVolumeSetKey

func LocalVolumeSetKey(lvs *localv1alpha1.LocalVolumeSet) string

LocalVolumeSetKey returns key for the localvolumeset

func NodeSelectorMatchesNodeLabels

func NodeSelectorMatchesNodeLabels(node *corev1.Node, nodeSelector *corev1.NodeSelector) (bool, error)

func OwnerHasReleasedPVs

func OwnerHasReleasedPVs(r *provCommon.RuntimeConfig, ownerLabels map[string]string) bool

OwnerHasReleasedPVs returns true if at least one PV in the cache has the provided owner labels and is in the Released phase.

func PVMatchesProvisioner

func PVMatchesProvisioner(pv *corev1.PersistentVolume, provisionerName string) bool

func PolicyNotPreferredLVDL

func PolicyNotPreferredLVDL(err error) (*v1.LocalVolumeDeviceLink, string, bool)

func ReleaseAvailablePVs

func ReleaseAvailablePVs(obj runtime.Object, c client.Client) error

ReleaseAvailablePVs releases available PV's owned by the object.

func ReloadRuntimeConfig

func ReloadRuntimeConfig(ctx context.Context, client client.Client, request ctrl.Request, nodeName string, rc *staticProvisioner.RuntimeConfig) error

ReloadRuntimeConfig obtains all values needed by runtime config during Reconcile and writes them to the existing RuntimeConfig provided

func RoundDownCapacityPretty

func RoundDownCapacityPretty(capacityBytes int64) int64

RoundDownCapacityPretty rounds down to either the closest GiB or Mib if the resulting value is more than 10 of the respective unit.

func SyncPVAndLVDL

func SyncPVAndLVDL(ctx context.Context, args SyncPVAndLVDLArgs) error

SyncPVAndLVDL ensures the PV exists for a symlinked device and keeps its LocalVolumeDeviceLink in sync.

Types

type ConditionalSymlinkRemoval

type ConditionalSymlinkRemoval func() bool

type CurrentBlockDeviceInfo

type CurrentBlockDeviceInfo struct {
	// contains filtered or unexported fields
}

func (CurrentBlockDeviceInfo) RecoverPVSymlinkPath

func (c CurrentBlockDeviceInfo) RecoverPVSymlinkPath(ctx context.Context, symlinkDir, newSymlinkSourcePath string, client client.Client) (string, error)

RecoverPVSymlinkPath finds a symlinkPath in /mnt/local-storage from LVDL for a given newSymlinkSourcePath. If the symlinkPath needs to change and the LVDL policy is not to update existing symlinks, then PolicyNotPreferredError error is returned.

The purpose of this function is to return a new path which may or may not match with actual source specified by newSymlinkSourcePath for existing symlinks. For example - /dev/disk/by-id/wwn-0x12232 newSymlinkSourcePath may generate a targetpath called /mnt/local-storage/foobar/scsi-23232 because scsi-xxx path is already being used by existing volumes.

Arguments: symlinkDir is path in /mnt/local-storage with storageclass name:

example - /mnt/local-storage/foobar/

newSymlinkSourcePath is path in /dev/disk/by-id which points to current device:

example - /dev/disk/by-id/wwn-0x123432

This function MUST be called only when there is no valid symlinks for `newSymlinkSourcePath` in `/mnt/local-storage/<sc>` and yet LSO MUST have created a PV for device pointed by `newSymlinkSourcePath` in previously. So this function is our last resort to find a valid symlink path for PV. Only return valid new SymlinkPath if currentLinkTarget doesn't resolve and user has asked for symlinks to be recreated.

type DeviceLinkHandler

type DeviceLinkHandler struct {
	// contains filtered or unexported fields
}

func NewDeviceLinkHandler

func NewDeviceLinkHandler(client client.Client, clientReader client.Reader, recorder record.EventRecorder, cacheWriter *LocalVolumeDeviceLinkCache, nodeName string) (*DeviceLinkHandler, error)

func (*DeviceLinkHandler) ApplyStatus

func (dl *DeviceLinkHandler) ApplyStatus(ctx context.Context, pvName, namespace string, blockDevice internal.BlockDevice, ownerObj runtime.Object, currentSymlink, symlinkPath string) (*v1.LocalVolumeDeviceLink, error)

func (*DeviceLinkHandler) FindLVDL

func (dl *DeviceLinkHandler) FindLVDL(ctx context.Context, lvdlName, namespace string) (*v1.LocalVolumeDeviceLink, error)

func (*DeviceLinkHandler) RecreateSymlinkIfNeeded

func (dl *DeviceLinkHandler) RecreateSymlinkIfNeeded(ctx context.Context, lvdl *v1.LocalVolumeDeviceLink, symLinkPath string, blockDevice internal.BlockDevice) (*v1.LocalVolumeDeviceLink, error)

RecreateSymlinkIfNeeded checks the LVDL policy and atomically recreates the symlink if policy is PreferredLinkTarget and currentLinkTarget != preferredLinkTarget. symLinkPath is the full path under /mnt/local-storage/<storageClass>/<deviceName>. Returns nil if no action is needed or action succeeded, error if action failed. On error, it sets a failure OperatorCondition on the LVDL object.

func (dl *DeviceLinkHandler) UpdateDeviceLinks(ctx context.Context, existing *v1.LocalVolumeDeviceLink, blockDevice internal.BlockDevice, currentSymlink, symlinkPath string) (*v1.LocalVolumeDeviceLink, error)

type LocalVolumeDeviceLinkCache

type LocalVolumeDeviceLinkCache struct {
	// contains filtered or unexported fields
}

LocalVolumeDeviceLinkCache maintains an in-memory index of LocalVolumeDeviceLink objects keyed by their valid link targets (e.g. /dev/disk/by-id paths). Reconcilers use this cache to recover device-to-PV associations when the on-disk symlink has been lost (e.g. after a node reboot changes /dev/disk/by-id entries), enabling symlink recreation without re-provisioning the PersistentVolume.

func NewLocalVolumeDeviceLinkCache

func NewLocalVolumeDeviceLinkCache(client client.Client, mgr manager.Manager, localNodeName string) *LocalVolumeDeviceLinkCache

func (*LocalVolumeDeviceLinkCache) AddOrUpdateLVDL

func (l *LocalVolumeDeviceLinkCache) AddOrUpdateLVDL(lvdl *v1.LocalVolumeDeviceLink)

AddOrUpdateLVDL updates the in-memory index immediately, enabling write-through cache semantics when called after a successful API server write.

func (*LocalVolumeDeviceLinkCache) FindLSOManagedDeviceInfo

func (l *LocalVolumeDeviceLinkCache) FindLSOManagedDeviceInfo(symlink string, blockDevice internal.BlockDevice) (CurrentBlockDeviceInfo, bool, error)

FindLSOManagedDeviceInfo finds LSO managed device information available about this block device. It checks if device was in-use or managed by LSO. It currently uses LVDLs to determine that.

func (*LocalVolumeDeviceLinkCache) IsSynced

func (l *LocalVolumeDeviceLinkCache) IsSynced() bool

IsSynced returns true once the LVDL informer has synced and event handlers have been registered. Reconcilers should skip cache-dependent work until this returns true.

func (*LocalVolumeDeviceLinkCache) MarkSyncedForTests

func (l *LocalVolumeDeviceLinkCache) MarkSyncedForTests()

MarkSyncedForTests marks the cache as ready without starting informers.

func (*LocalVolumeDeviceLinkCache) SeedForTests

func (l *LocalVolumeDeviceLinkCache) SeedForTests(lvdl *v1.LocalVolumeDeviceLink)

SeedForTests inserts an LVDL entry into the in-memory map. This is used by unit tests that don't run the informer-backed Start() flow.

func (*LocalVolumeDeviceLinkCache) Start

Start implements manager.Runnable. The manager calls this after its own caches are started, but we still need to wait for the LVDL informer (which may have been dynamically added) to complete its initial sync.

type PolicyNotPreferredError

type PolicyNotPreferredError struct {
	SymlinkSource string
	SymlinkDir    string
	PVSymlinkPath string
	LVDL          *v1.LocalVolumeDeviceLink
}

func (PolicyNotPreferredError) Error

func (e PolicyNotPreferredError) Error() string

type StorageClassOwnerMap

type StorageClassOwnerMap struct {
	// contains filtered or unexported fields
}

StorageClassOwnerMap store a one to many association from storageClass to storageclass owner (LocalVolume,LocalVolumeSet,etc), so that one PV/SC event can fan out requests to all owners.

func (*StorageClassOwnerMap) DeregisterStorageClassOwner

func (l *StorageClassOwnerMap) DeregisterStorageClassOwner(storageClass string, name types.NamespacedName)

func (*StorageClassOwnerMap) GetStorageClassOwners

func (l *StorageClassOwnerMap) GetStorageClassOwners(storageClass string) []types.NamespacedName

func (*StorageClassOwnerMap) RegisterStorageClassOwner

func (l *StorageClassOwnerMap) RegisterStorageClassOwner(storageClass string, name types.NamespacedName)

type SyncPVAndLVDLArgs

type SyncPVAndLVDLArgs struct {
	LocalVolumeLikeObject runtime.Object
	RuntimeConfig         *provCommon.RuntimeConfig
	StorageClass          storagev1.StorageClass
	MountPointMap         sets.Set[string]
	Client                client.Client
	// symlinkPath points to path on /mnt/local-storage
	SymLinkPath      string
	ExtraLabelsForPV map[string]string

	// ClientReader is used to read objects from the apiserver
	// skipping cache
	ClientReader client.Reader

	// BlockDevice is the block device backing this PV.
	BlockDevice internal.BlockDevice
	// CacheWriter enables write-through updates to the LVDL in-memory cache.
	CacheWriter *LocalVolumeDeviceLinkCache
}

SyncPVAndLVDLArgs holds the arguments for PV and LocalVolumeDeviceLink synchronization.

Jump to

Keyboard shortcuts

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