common

package
v0.0.0-...-4a83c52 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 31 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"

	// 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"
)

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 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 CreateLocalPV

func CreateLocalPV(
	obj runtime.Object,
	runtimeConfig *provCommon.RuntimeConfig,
	storageClass storagev1.StorageClass,
	mountPointMap sets.String,
	client client.Client,
	symLinkPath string,
	deviceName string,
	idExists bool,
	extraLabelsForPV map[string]string,
) error

CreateLocalPV is used to create a local PV against a symlink after passing the same validations against that symlink that local-static-provisioner uses

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.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 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.RateLimitingInterface, watchNamespace string, isDelete 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 PVMatchesProvisioner

func PVMatchesProvisioner(pv *corev1.PersistentVolume, provisionerName 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.

Types

type ConditionalSymlinkRemoval

type ConditionalSymlinkRemoval func() bool

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)

Jump to

Keyboard shortcuts

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