Documentation ¶
Overview ¶
Package util contains common utilities
Index ¶
- Constants
- func AddCommonFields(ctx context.Context, logger *logrus.Entry, method string) *logrus.Entry
- func ConsistentRead(filename string, retry int, timeout time.Duration) ([]byte, error)
- func ContainsString(slice []string, str string) bool
- func ConvertDriveTypeToStorageClass(driveType string) string
- func ConvertStorageClass(strSC string) string
- func GetKernelVersion(kernelVersion string) (version string, err error)
- func GetOSNameAndVersion(osInfo string) (name, version string, err error)
- func GetSubStorageClass(sc string) string
- func GetVolumeUUID(volumeID string) (string, error)
- func HasNameWithPrefix(names []string) bool
- func IsStorageClassLVG(sc string) bool
- func RemoveString(slice []string, s string) (result []string)
- func SetupAndStartHealthCheckServer(c health.HealthServer, logger *logrus.Logger, endpoint string) error
- func SplitAndTrimSpace(str, sep string) []string
- func StrToBytes(str string) (int64, error)
- func ToBytes(value int64, from SizeUnit) int64
- func ToSizeUnit(value int64, from SizeUnit, to SizeUnit) (int64, error)
- type CtxKey
- type SignalHandler
- type SizeUnit
- type VolumeInfo
Constants ¶
const ( // VolumeInfoKey is the constant for context request VolumeInfoKey CtxKey = "VolumeInfo" // ClaimNamespaceKey is a key from volume_context in CreateVolumeRequest of NodePublishVolumeRequest ClaimNamespaceKey = "csi.storage.k8s.io/pvc/namespace" // ClaimNameKey is a key from volume_context in CreateVolumeRequest of NodePublishVolumeRequest ClaimNameKey = "csi.storage.k8s.io/pvc/name" // PodNamespaceKey to read pod namespace from PodInfoOnMount feature PodNamespaceKey = "csi.storage.k8s.io/pod.namespace" // PodNameKey to read pod name from PodInfoOnMount feature PodNameKey = "csi.storage.k8s.io/pod.name" )
Variables ¶
This section is empty.
Functions ¶
func AddCommonFields ¶
AddCommonFields read common fields from ctx and add them to logger
func ConsistentRead ¶
ConsistentRead returns content of the file and ensure that this content is actual (no one modify file during timeout) Receives absolute path to the file as filename, amount of retries to read and timeout of the operation Returns read file or error in case if there were not twice same read content
func ContainsString ¶
ContainsString return true if slice contains string str Receives slice of strings and string to find Returns true if contains or false if not
func ConvertDriveTypeToStorageClass ¶
ConvertDriveTypeToStorageClass converts type of a drive to AvailableCapacity StorageClass Receives driveType var of string type Returns string of Available Capacity StorageClass
func ConvertStorageClass ¶
ConvertStorageClass converts string from k8s StorageClass's manifest to CSI Storage Class string If it is impossible then use api.StorageClassAny Receives string name of StorageClass Returns string of CSI StorageClass
func GetKernelVersion ¶
GetKernelVersion receives string with the kernel version information in the following format: "X.Y.Z-<Number>-<Description>". For example, "5.4.0-66-generic" returns kernel version - major and minor. For example, "5.4"
func GetOSNameAndVersion ¶
GetOSNameAndVersion receives string with the OS information in th following format: "<OS name> <OS version> <Extra information>". For example, "Ubuntu 18.04.4 LTS" returns os name with the lower case and major and minor version. For example, "ubuntu", "18.04"
func GetSubStorageClass ¶
GetSubStorageClass return appropriate underlying storage class for storage classes that are based on LVM, or empty string
func GetVolumeUUID ¶
GetVolumeUUID extracts UUID from volume ID: pvc-<UUID> Method will remove pvcPrefix `pvc-` and return UUID
func HasNameWithPrefix ¶
HasNameWithPrefix check whether slice has a string with pvcPrefix pvc or not
func IsStorageClassLVG ¶
IsStorageClassLVG returns whether provided sc relates to LVG or no
func RemoveString ¶
RemoveString removes string s from slice Receives slice of strings and string to remove Returns slice without mentioned string
func SetupAndStartHealthCheckServer ¶
func SetupAndStartHealthCheckServer(c health.HealthServer, logger *logrus.Logger, endpoint string) error
SetupAndStartHealthCheckServer starts gRPC server to handle Health checking requests
func SplitAndTrimSpace ¶
SplitAndTrimSpace split string str by separator sep and removes all leading and trailing spaces from each string in resulting slice, if some string an empty it is excluded from resulting slice
func StrToBytes ¶
StrToBytes parses provided string and returns its value in bytes. Example: "15 Kb" -> 15360, "1GB" -> 1073741824 Receives string value of information size with literal Returns provided size in bytes or error if something went wrong
Types ¶
type SignalHandler ¶
type SignalHandler struct {
// contains filtered or unexported fields
}
SignalHandler is a structure which contains methods for signal handling
func NewSignalHandler ¶
func NewSignalHandler(logger *logrus.Logger) *SignalHandler
NewSignalHandler is a constructor for SignalHandler
func (*SignalHandler) SetupSIGHUPHandler ¶
func (sh *SignalHandler) SetupSIGHUPHandler(cleanupFn func())
SetupSIGHUPHandler tries to make cleanup, when SIGHUP is caught
func (*SignalHandler) SetupSIGTERMHandler ¶
func (sh *SignalHandler) SetupSIGTERMHandler(server *rpc.ServerRunner)
SetupSIGTERMHandler tries to shutdown service, when SIGTERM is caught
type SizeUnit ¶
type SizeUnit int64
SizeUnit is the type for unit of information
const ( // TBYTE represents 1 terabyte TBYTE SizeUnit = 1024 * 1024 * 1024 * 1024 // GBYTE represents 1 gigabyte GBYTE SizeUnit = 1024 * 1024 * 1024 // MBYTE represents 1 megabyte MBYTE SizeUnit = 1024 * 1024 // KBYTE represents 1 kilobyte KBYTE SizeUnit = 1024 // BYTE represents 1 byte BYTE SizeUnit = 1 )
type VolumeInfo ¶
VolumeInfo holds information about Kubernetes PVC
func NewVolumeInfo ¶
func NewVolumeInfo(parameters map[string]string) (*VolumeInfo, error)
NewVolumeInfo receives parameters from CreateVolumeRequest and returns new VolumeInfo
func (*VolumeInfo) IsDefaultNamespace ¶
func (v *VolumeInfo) IsDefaultNamespace() bool
IsDefaultNamespace returns true when namespace is not defined and false otherwise