utils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SocketDir = "/csi"

	CsiConfigMapConfigKey  = "config.json"
	CsiConfigMapMappingKey = "cluster-mapping.json"
)

Variables

View Source
var AlsoLogToStdErrContainerArg = "--alsologtostderr=true"
View Source
var ControllerPluginCsiAddonsContainerCephFsPort = corev1.ContainerPort{
	ContainerPort: int32(9080),
}
View Source
var ControllerPluginCsiAddonsContainerRbdPort = corev1.ContainerPort{
	ContainerPort: int32(9070),
}

CSI Addons container port definitions

View Source
var ControllerServerContainerArg = "--controllerserver=true"
View Source
var CsiAddonsAddressContainerArg = fmt.Sprintf("--csi-addons-address=%s", csiAddonsEndpoint)
View Source
var CsiAddonsEndpointContainerArg = fmt.Sprintf("--csi-addons-endpoint=%s", csiAddonsEndpoint)
View Source
var CsiAddonsNodeIdContainerArg = fmt.Sprintf("--node-id=$(%s)", NodeIdEnvVar.Name)
View Source
var CsiAddonsVolumeConditionArg = "--enable-volume-condition=true"
View Source
var CsiAddressContainerArg = fmt.Sprintf("--csi-address=%s", csiEndpoint)

Ceph CSI common container arguments

View Source
var CsiConfigVolume = corev1.Volume{
	Name: "ceph-csi-config",
	VolumeSource: corev1.VolumeSource{
		ConfigMap: &corev1.ConfigMapVolumeSource{
			LocalObjectReference: corev1.LocalObjectReference{
				Name: "ceph-csi-config",
			},
		},
	},
}
View Source
var CsiConfigVolumeMount = corev1.VolumeMount{
	Name:      CsiConfigVolume.Name,
	MountPath: "/etc/ceph-csi-config",
}
View Source
var CsiMountInfoVolumeMount = corev1.VolumeMount{
	Name:      csiMountInfoVolumeName,
	MountPath: "/csi/mountinfo",
}
View Source
var DefaultFsTypeContainerArg = "--default-fstype=ext4"
View Source
var DriverNamespaceContainerArg = fmt.Sprintf("--drivernamespace=$(%s)", DriverNamespaceEnvVar.Name)
View Source
var DriverNamespaceEnvVar = corev1.EnvVar{
	Name: "DRIVER_NAMESPACE",
	ValueFrom: &corev1.EnvVarSource{
		FieldRef: &corev1.ObjectFieldSelector{
			FieldPath: "metadata.namespace",
		},
	},
}
View Source
var EnableVolumeGroupSnapshotsContainerArg = "--feature-gates=CSIVolumeGroupSnapshot=true"
View Source
var EndpointContainerArg = fmt.Sprintf("--endpoint=%s", csiEndpoint)
View Source
var EtcSelinuxVolume = corev1.Volume{
	Name: "etc-selinux",
	VolumeSource: corev1.VolumeSource{
		HostPath: &corev1.HostPathVolumeSource{
			Path: "/etc/selinux",
		},
	},
}
View Source
var EtcSelinuxVolumeMount = corev1.VolumeMount{
	Name:      EtcSelinuxVolume.Name,
	MountPath: "/etc/selinux",
	ReadOnly:  true,
}
View Source
var ExtraCreateMetadataContainerArg = "--extra-create-metadata=true"
View Source
var ForceCephKernelClientContainerArg = "--forcecephkernelclient=true"
View Source
var HandleVolumeInuseErrorContainerArg = "--handle-volume-inuse-error=false"
View Source
var HonorPVReclaimPolicyContainerArg = "--feature-gates=HonorPVReclaimPolicy=true"
View Source
var HostDevVolume = corev1.Volume{
	Name: "host-dev",
	VolumeSource: corev1.VolumeSource{
		HostPath: &corev1.HostPathVolumeSource{
			Path: "/dev",
		},
	},
}
View Source
var HostDevVolumeMount = corev1.VolumeMount{
	Name:      HostDevVolume.Name,
	MountPath: "/dev",
}
View Source
var HostRunMountVolume = corev1.Volume{
	Name: "host-run-mount",
	VolumeSource: corev1.VolumeSource{
		HostPath: &corev1.HostPathVolumeSource{
			Path: "/run/mount",
		},
	},
}
View Source
var HostRunMountVolumeMount = corev1.VolumeMount{
	Name:      HostRunMountVolume.Name,
	MountPath: "/run/mount",
}
View Source
var HostSysVolume = corev1.Volume{
	Name: "host-sys",
	VolumeSource: corev1.VolumeSource{
		HostPath: &corev1.HostPathVolumeSource{
			Path: "/sys",
		},
	},
}
View Source
var HostSysVolumeMount = corev1.VolumeMount{
	Name:      HostSysVolume.Name,
	MountPath: "/sys",
}
View Source
var KeysTmpDirVolume = corev1.Volume{
	Name: "keys-tmp-dir",
	VolumeSource: corev1.VolumeSource{
		EmptyDir: &corev1.EmptyDirVolumeSource{
			Medium: corev1.StorageMediumMemory,
		},
	},
}
View Source
var KeysTmpDirVolumeMount = corev1.VolumeMount{
	Name:      KeysTmpDirVolume.Name,
	MountPath: "/tmp/csi/keys",
}
View Source
var KmsConfigVolumeMount = corev1.VolumeMount{
	Name:      kmsConfigVolumeName,
	MountPath: "/etc/ceph-csi-encryption-kms-config/",
	ReadOnly:  true,
}
View Source
var LeaderElectionContainerArg = "--leader-election=true"
View Source
var LibModulesVolume = corev1.Volume{
	Name: "lib-modules",
	VolumeSource: corev1.VolumeSource{
		HostPath: &corev1.HostPathVolumeSource{
			Path: "/lib/modules",
		},
	},
}
View Source
var LibModulesVolumeMount = corev1.VolumeMount{
	Name:      LibModulesVolume.Name,
	MountPath: "/lib/modules",
	ReadOnly:  true,
}
View Source
var LogRotateDirVolumeMount = corev1.VolumeMount{
	Name:      logRotateDirVolumeName,
	MountPath: "/logrotate-config",
}
View Source
var LogToStdErrContainerArg = "--logtostderr=false"
View Source
var LogsDirVolumeMount = corev1.VolumeMount{
	Name:      logsDirVolumeName,
	MountPath: "/csi-logs",
}
View Source
var MetricsPathContainerArg = "--metricspath=/metrics"
View Source
var NamespaceContainerArg = fmt.Sprintf("--namespace=$(%s)", PodNamespaceEnvVar.Name)
View Source
var NodeIdContainerArg = fmt.Sprintf("--nodeid=$(%s)", NodeIdEnvVar.Name)
View Source
var NodeIdEnvVar = corev1.EnvVar{
	Name: "NODE_ID",
	ValueFrom: &corev1.EnvVarSource{
		FieldRef: &corev1.ObjectFieldSelector{
			FieldPath: "spec.nodeName",
		},
	},
}
View Source
var NodePluginCsiAddonsContainerPort = corev1.ContainerPort{
	ContainerPort: int32(9071),
}
View Source
var NodeServerContainerArg = "--nodeserver=true"
View Source
var OidcTokenVolume = corev1.Volume{
	Name: "oidc-token",
	VolumeSource: corev1.VolumeSource{
		Projected: &corev1.ProjectedVolumeSource{
			Sources: []corev1.VolumeProjection{
				{
					ServiceAccountToken: &corev1.ServiceAccountTokenProjection{
						Path:              "oidc-token",
						ExpirationSeconds: ptr.To(int64(3600)),
						Audience:          "ceph-csi-kms",
					},
				},
			},
		},
	},
}
View Source
var OidcTokenVolumeMount = corev1.VolumeMount{
	Name:      OidcTokenVolume.Name,
	MountPath: "/run/secrets/tokens",
	ReadOnly:  true,
}
View Source
var PidlimitContainerArg = "--pidlimit=-1"
View Source
var PluginDirVolumeMount = corev1.VolumeMount{
	Name:      pluginDirVolumeName,
	MountPath: "/csi",
}
View Source
var PodContainerArg = fmt.Sprintf("--pod=$(%s)", PodNameEnvVar.Name)
View Source
var PodIpEnvVar = corev1.EnvVar{
	Name: "POD_IP",
	ValueFrom: &corev1.EnvVarSource{
		FieldRef: &corev1.ObjectFieldSelector{
			FieldPath: "status.podIP",
		},
	},
}

Ceph CSI Common env var definition

View Source
var PodNameEnvVar = corev1.EnvVar{
	Name: "POD_NAME",
	ValueFrom: &corev1.EnvVarSource{
		FieldRef: &corev1.ObjectFieldSelector{
			FieldPath: "metadata.name",
		},
	},
}
View Source
var PodNamespaceEnvVar = corev1.EnvVar{
	Name: "POD_NAMESPACE",
	ValueFrom: &corev1.EnvVarSource{
		FieldRef: &corev1.ObjectFieldSelector{
			FieldPath: "metadata.namespace",
		},
	},
}
View Source
var PodUidContainerArg = fmt.Sprintf("--pod-uid=$(%s)", PodUidEnvVar.Name)
View Source
var PodUidEnvVar = corev1.EnvVar{
	Name: "POD_UID",
	ValueFrom: &corev1.EnvVarSource{
		FieldRef: &corev1.ObjectFieldSelector{
			FieldPath: "metadata.uid",
		},
	},
}
View Source
var PoolTimeContainerArg = "--polltime=60s"
View Source
var PreventVolumeModeConversionContainerArg = "--prevent-volume-mode-conversion=true"
View Source
var RecoverVolumeExpansionFailureContainerArg = "--feature-gates=RecoverVolumeExpansionFailure=true"
View Source
var RegistrationDirVolumeMount = corev1.VolumeMount{
	Name:      registrationVolumeName,
	MountPath: "/registration",
}
View Source
var RetryIntervalStartContainerArg = "--retry-interval-start=500ms"
View Source
var SnapshotMetadataGrpcPort = corev1.ContainerPort{
	ContainerPort: int32(50051),
}

CSI snapshot-metadata sidecar container port definitions

View Source
var SnapshotMetadataGrpcServicePortArg = fmt.Sprintf("--port=%d", SnapshotMetadataGrpcPort.ContainerPort)
View Source
var SnapshotMetadataTlsCertArg = "--tls-cert=/tmp/certificates/tls.crt"
View Source
var SnapshotMetadataTlsKeyArg = "--tls-key=/tmp/certificates/tls.key"
View Source
var SocketDirVolume = corev1.Volume{
	Name: "socket-dir",
	VolumeSource: corev1.VolumeSource{
		EmptyDir: &corev1.EmptyDirVolumeSource{
			Medium: corev1.StorageMediumMemory,
		},
	},
}

Ceph CSI common volumes

View Source
var SocketDirVolumeMount = corev1.VolumeMount{
	Name:      SocketDirVolume.Name,
	MountPath: SocketDir,
}

Ceph CSI common volume Mounts

Functions

func AddAnnotation

func AddAnnotation(obj metav1.Object, key string, value string) bool

AddAnnotation adds an annotation to a resource metadata, returns true if added else false

func Call

func Call[T any](fn func() T) T

Call calls the provided zero-argument function. This util is used whenever we need to define a function and call it immediately and only once, as a more readable alternative to (func() { ... })(). The common use case is "inline" func invoation as part of a data staructure initializtaoin code.

func ChannelToSlice

func ChannelToSlice[T any](c chan T) []T

ChannelToSlice consumes a channel return values in a slice

func Clamp

func Clamp[T cmp.Ordered](val, low, high T) T

Clamp a number between min and max

func ClusterNameContainerArg

func ClusterNameContainerArg(name string) string

func ContainerPortArg added in v0.3.0

func ContainerPortArg(port corev1.ContainerPort) string

func CsiMountInfoVolume added in v0.3.0

func CsiMountInfoVolume(kubeletDirPath string, driverName string) corev1.Volume

func DeleteZeroValues

func DeleteZeroValues[T comparable](slice []T) []T

RemoveZeroValues return a new slice form the provided slice where all zero-valued items are removed

func DomainLabelsContainerArg

func DomainLabelsContainerArg(options []string) string

func DriverNameContainerArg

func DriverNameContainerArg(name string) string

func EventTypePredicate

func EventTypePredicate(create, update, del, generic bool) predicate.Predicate

EventTypePredicate return a predicate the filter events based on their respective event type. This helper allows for the selection of multiple types resulting in a predicate that can filter in more then a single event type

func FuseMountOptionsContainerArg

func FuseMountOptionsContainerArg(options map[string]string) string

func GetOperatorNamespace added in v0.2.0

func GetOperatorNamespace() (string, error)

func If

func If[T any](cond bool, trueVal, falseVal T) T

If implements an if/else expression

func IsOwnedBy

func IsOwnedBy(obj, owner metav1.Object) bool

IsOwnedBy returns true if the object has an owner ref for the provided owner

func KernelMountOptionsContainerArg

func KernelMountOptionsContainerArg(options map[string]string) string

func KmsConfigVolume

func KmsConfigVolume(configRef *corev1.LocalObjectReference) corev1.Volume

func KubeletRegistrationPathContainerArg

func KubeletRegistrationPathContainerArg(kubeletDirPath string, driverName string) string

func LeaderElectionLeaseDurationContainerArg

func LeaderElectionLeaseDurationContainerArg(duration int) string

func LeaderElectionNamespaceContainerArg

func LeaderElectionNamespaceContainerArg(ns string) string

func LeaderElectionRenewDeadlineContainerArg

func LeaderElectionRenewDeadlineContainerArg(deadline int) string

func LeaderElectionRetryPeriodContainerArg

func LeaderElectionRetryPeriodContainerArg(period int) string

func LogFileContainerArg

func LogFileContainerArg(containerName string) string

func LogRotateConfigMapName

func LogRotateConfigMapName(driverName string) string

func LogRotateDirVolumeName

func LogRotateDirVolumeName(driverName string) corev1.Volume

func LogVerbosityContainerArg

func LogVerbosityContainerArg(level int) string

func LogsDirVolume

func LogsDirVolume(logHostPath, pluginName string) corev1.Volume

func MapSlice

func MapSlice[T, K any](in []T, mapper func(item T) K) []K

MapSlice maps the iteas of a given slice into a new slice using a mapper function

func MapToString

func MapToString[K, T ~string](m map[K]T, keyValueSeperator, itemSeperator string) string

MapToString serializes the provided map into a a string.

func MetricsPortContainerArg

func MetricsPortContainerArg(port int) string

func NamePredicate

func NamePredicate(name string) predicate.Predicate

Name Predicate return a predicate the filter events produced by resources that matches the given name

func PluginDirVolume

func PluginDirVolume(kubeletDirPath string, driverNamePrefix string) corev1.Volume

func PluginMountDirVolume

func PluginMountDirVolume(kubeletDirPath string) corev1.Volume

func PluginMountDirVolumeMount

func PluginMountDirVolumeMount(kubletDirPath string) corev1.VolumeMount

func PodsMountDirVolume

func PodsMountDirVolume(kubeletDirPath string) corev1.Volume

func PodsMountDirVolumeMount

func PodsMountDirVolumeMount(kubletDirPath string) corev1.VolumeMount

func RegistrationDirVolume

func RegistrationDirVolume(kubeletDirPath string) corev1.Volume

func RunConcurrently

func RunConcurrently(fnList ...func() error) chan error

RunConcurrently runs all the of the given functions concurrently returning a channel with the functions' return values (of type error) then closes the channel when all functions return.

func SetFencingContainerArg added in v0.4.0

func SetFencingContainerArg(on bool) string

func SetMetadataContainerArg

func SetMetadataContainerArg(on bool) string

func StagingPathContainerArg

func StagingPathContainerArg(kubeletDirPath string) string

func TimeoutContainerArg

func TimeoutContainerArg(timeout int) string

func ToggleOwnerReference

func ToggleOwnerReference(on bool, obj, owner metav1.Object, scheme *runtime.Scheme) (bool, error)

ToggleOwnerReference adds or remove an owner reference for the given owner based on the first argument. The function return true if the owner reference list had changed and false it it didn't

func TopologyContainerArg added in v0.3.0

func TopologyContainerArg(topology bool) string

func TypeContainerArg

func TypeContainerArg(t string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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