util

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Overview

Package util contains common utilities

Index

Constants

View Source
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

func AddCommonFields(ctx context.Context, logger *logrus.Entry, method string) *logrus.Entry

AddCommonFields read common fields from ctx and add them to logger

func ConsistentRead

func ConsistentRead(filename string, retry int, timeout time.Duration) ([]byte, error)

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

func ContainsString(slice []string, str string) bool

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

func ConvertDriveTypeToStorageClass(driveType string) string

ConvertDriveTypeToStorageClass converts type of a drive to AvailableCapacity StorageClass Receives driveType var of string type Returns string of Available Capacity StorageClass

func ConvertStorageClass

func ConvertStorageClass(strSC string) string

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

func GetKernelVersion(kernelVersion string) (version string, err error)

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

func GetOSNameAndVersion(osInfo string) (name, version string, err error)

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

func GetSubStorageClass(sc string) string

GetSubStorageClass return appropriate underlying storage class for storage classes that are based on LVM, or empty string

func GetVolumeUUID

func GetVolumeUUID(volumeID string) (string, error)

GetVolumeUUID extracts UUID from volume ID: pvc-<UUID> Method will remove pvcPrefix `pvc-` and return UUID

func HasNameWithPrefix

func HasNameWithPrefix(names []string) bool

HasNameWithPrefix check whether slice has a string with pvcPrefix pvc or not

func IsStorageClassLVG

func IsStorageClassLVG(sc string) bool

IsStorageClassLVG returns whether provided sc relates to LVG or no

func RemoveString

func RemoveString(slice []string, s string) (result []string)

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

func SplitAndTrimSpace(str, sep string) []string

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

func StrToBytes(str string) (int64, error)

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

func ToBytes

func ToBytes(value int64, from SizeUnit) int64

ToBytes converts size of provided unit to its value in bytes Receives value as size and 'from' as size unit Returns provided size in bytes

func ToSizeUnit

func ToSizeUnit(value int64, from SizeUnit, to SizeUnit) (int64, error)

ToSizeUnit converts value from specified size unit to another unit Receives size as value, 'from' as provided size unit and 'to' as size unit to convert Returns error if conversion leads to precision loss.

Types

type CtxKey

type CtxKey string

CtxKey variable type uses for keys in context WithValue

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

type VolumeInfo struct {
	Namespace string
	Name      string
}

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

Jump to

Keyboard shortcuts

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