utils

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterName               = "clusterName"
	PowerScaleLogger LogConst = "powerscalelog"
	LogFields        LogConst = "fields"
	RequestID                 = "requestid"
	RunID                     = "runid"
)

Constants used for logging

Variables

View Source
var CSIQuotaIDPrefix = "CSI_QUOTA_ID:"

CSIQuotaIDPrefix is the CSI tag for quota id stored in the export's description field set by csi driver

View Source
var DummyHostNodeID = "localhost=#=#=localhost=#=#=127.0.0.1"

DummyHostNodeID is nodeID used for adding dummy client in client field of export

View Source
var ExportConflictMessagePattern = regexp.MustCompile(fmt.Sprintf("^Export rules (\\d+) and (\\d+) conflict on '(.+)'$"))

ExportConflictMessagePattern is the regex pattern that identifies the error message of export conflict

View Source
var NodeIDPattern = regexp.MustCompile(fmt.Sprintf("^(.+)%s(.+)%s(.+)$", NodeIDSeparator, NodeIDSeparator))

NodeIDPattern is the regex pattern that identifies the NodeID

View Source
var NodeIDSeparator = "=#=#="

NodeIDSeparator is the separator that separates node name and IP Address

View Source
var QuotaIDPattern = regexp.MustCompile(fmt.Sprintf("^%s(.*)", CSIQuotaIDPrefix))

QuotaIDPattern the regex pattern that identifies the quota id set in the export's description field set by csi driver

View Source
var SnapshotIDSeparator = "=_=_="

SnapshotIDSeparator is the separator that separates snapshot id and cluster name (two components that a normalized snapshot ID is comprised of)

View Source
var VolumeIDPattern = regexp.MustCompile(fmt.Sprintf("^(.+)%s(\\d+)%s(.+)$", VolumeIDSeparator, VolumeIDSeparator))

VolumeIDPattern is the regex pattern that identifies the quota id set in the export's description field set by csi driver

View Source
var VolumeIDSeparator = "=_=_="

VolumeIDSeparator is the separator that separates volume name and export ID (two components that a normalized volume ID is comprised of)

Functions

func CombineTwoStrings

func CombineTwoStrings(s1 string, s2 string, sign string) string

CombineTwoStrings combines two string variables isolated by defined sign

func GetAccessMode

GetAccessMode extracts the access mode from the given *csi.ControllerPublishVolumeRequest instance

func GetCurrentLogLevel

func GetCurrentLogLevel() logrus.Level

GetCurrentLogLevel updates the log level

func GetExportIDFromConflictMessage

func GetExportIDFromConflictMessage(message string) int

GetExportIDFromConflictMessage returns the export id of the export which is creating or just created when there occurs a conflict

func GetFQDNByIP

func GetFQDNByIP(ctx context.Context, ip string) (string, error)

GetFQDNByIP returns the FQDN based on the parsed ip address

func GetIsiPathFromExportPath

func GetIsiPathFromExportPath(exportPath string) string

GetIsiPathFromExportPath returns isiPath based on the export path

func GetIsiPathFromPgID

func GetIsiPathFromPgID(exportPath string) string

GetIsiPathFromPgID returns isiPath based on the pg id

func GetLogger

func GetLogger() *logrus.Logger

GetLogger function to get custom logging

func GetMessageWithRunID

func GetMessageWithRunID(runid string, format string, args ...interface{}) string

GetMessageWithRunID returns message with runID information

func GetNewUUID

func GetNewUUID() (string, error)

GetNewUUID generates a UUID

func GetNormalizedSnapshotID

func GetNormalizedSnapshotID(ctx context.Context, snapshotID, clusterName string) string

GetNormalizedSnapshotID combines snapshotID ID and cluster name to form the normalized snapshot ID e.g. 12345 + cluster1 => 12345=_=_=cluster1

func GetNormalizedVolumeID

func GetNormalizedVolumeID(ctx context.Context, volName string, exportID int, accessZone, clusterName string) string

GetNormalizedVolumeID combines volume name (i.e. the directory name), export ID, access zone and clusterName to form the normalized volume ID e.g. k8s-e89c9d089e + 19 + csi0zone + cluster1 => k8s-e89c9d089e=_=_=19=_=_=csi0zone=_=_=cluster1

func GetOwnFQDN

func GetOwnFQDN() (string, error)

GetOwnFQDN returns the FQDN of the node or controller itself

func GetPathForVolume

func GetPathForVolume(isiPath, volName string) string

GetPathForVolume gets the volume full path by the combination of isiPath and volumeName

func GetQuotaIDFromDescription

func GetQuotaIDFromDescription(ctx context.Context, export isi.Export) (string, error)

GetQuotaIDFromDescription extracts quota id from the description field of export

func GetQuotaIDWithCSITag

func GetQuotaIDWithCSITag(quotaID string) string

GetQuotaIDWithCSITag formats a given quota id with the CSI tag, e.g. AABpAQEAAAAAAAAAAAAAQA0AAAAAAAAA -> CSI_QUOTA_ID:AABpAQEAAAAAAAAAAAAAQA0AAAAAAAAA

func GetRunIDLogger

func GetRunIDLogger(ctx context.Context) *logrus.Entry

GetRunIDLogger returns the current runID logger

func GetVolumeNameFromExportPath

func GetVolumeNameFromExportPath(exportPath string) string

GetVolumeNameFromExportPath returns volume name based on the export path

func IsStringInSlice

func IsStringInSlice(str string, list []string) bool

IsStringInSlice checks if a string is an element of a string slice

func IsStringInSlices

func IsStringInSlices(str string, list ...[]string) bool

IsStringInSlices checks if a string is an element of a any of the string slices

func LogMap

func LogMap(ctx context.Context, mapName string, m map[string]string)

LogMap logs the key-value entries of a given map

func ParseArrayFromContext

func ParseArrayFromContext(ctx context.Context, key string) ([]string, error)

ParseArrayFromContext parses an environment variable into an array of string

func ParseBooleanFromContext

func ParseBooleanFromContext(ctx context.Context, key string) bool

ParseBooleanFromContext parses an environment variable into a boolean value. If an error is encountered, default is set to false, and error is logged

func ParseInt64FromContext

func ParseInt64FromContext(ctx context.Context, key string) (int64, error)

ParseInt64FromContext parses an environment variable into an int64 value.

func ParseLogLevel

func ParseLogLevel(lvl string) (logrus.Level, error)

ParseLogLevel returns the logrus.Level of input log level string

func ParseNodeID

func ParseNodeID(ctx context.Context, nodeID string) (string, string, string, error)

ParseNodeID parses NodeID to node name, node FQDN and IP address using pattern '^(.+)=#=#=(.+)=#=#=(.+)'

func ParseNormalizedSnapshotID

func ParseNormalizedSnapshotID(ctx context.Context, snapID string) (string, string, error)

ParseNormalizedSnapshotID parses the normalized snapshot ID(using SnapshotIDSeparator) to extract the snapshot ID and cluster name(optional) that make up the normalized snapshot ID e.g. 12345 => 12345, "" e.g. 12345=_=_=cluster1 => 12345, cluster1

func ParseNormalizedVolumeID

func ParseNormalizedVolumeID(ctx context.Context, volID string) (string, int, string, string, error)

ParseNormalizedVolumeID parses the volume ID(using VolumeIDSeparator) to extract the volume name, export ID, access zone and cluster name(optional) that make up the volume ID e.g. k8s-e89c9d089e=_=_=19=_=_=csi0zone => k8s-e89c9d089e, 19, csi0zone, "" e.g. k8s-e89c9d089e=_=_=19=_=_=csi0zone=_=_=cluster1 => k8s-e89c9d089e, 19, csi0zone, cluster1

func ParseUintFromContext

func ParseUintFromContext(ctx context.Context, key string) uint

ParseUintFromContext parses an environment variable into a uint value. If an error is encountered, default is set to 0, and error is logged

func RemoveExistingCSISockFile

func RemoveExistingCSISockFile() error

RemoveExistingCSISockFile When the sock file that the gRPC server is going to be listening on already exists, error will be thrown saying the address is already in use, thus remove it first

func RemoveStringFromSlice

func RemoveStringFromSlice(str string, list []string) []string

RemoveStringFromSlice returns a slice that is a copy of the input "list" slice with the input "str" string removed

func RemoveStringsFromSlice

func RemoveStringsFromSlice(filters []string, list []string) []string

RemoveStringsFromSlice generates a slice that is a copy of the input "list" slice with elements from the input "strs" slice removed

func RemoveSurroundingQuotes

func RemoveSurroundingQuotes(s string) string

RemoveSurroundingQuotes removes the surrounding double quotes of a given string (if there are no surrounding quotes, do nothing)

func UpdateLogLevel

func UpdateLogLevel(lvl logrus.Level)

UpdateLogLevel updates the log level

Types

type Formatter

type Formatter struct {
	//logrus.TextFormatter
	// Timestamp format
	TimestampFormat string
	// Available standard keys: time, msg, lvl
	// Also can include custom fields but limited to strings.
	// All of fields need to be wrapped inside %% i.e %time% %msg%
	LogFormat string

	CallerPrettyfier func(*runtime.Frame) (function string, file string)
}

Formatter implements logrus.Formatter interface.

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format building log message.

type LogConst

type LogConst string

LogConst represents string in context.WithValue

Jump to

Keyboard shortcuts

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