Documentation ¶
Overview ¶
CheckForIscsi is blocking call for checking status of istgt in cstor-istgt container.
Package util provides functions based on k8s.io/apimachinery/pkg/apis/meta/v1/unstructured They are copied here to make them exported.
TODO Check if it makes sense to import the entire unstructured package of k8s.io/apimachinery/pkg/apis/meta/v1/unstructured versus. copying
TODO Move to maya/pkg/unstructured/v1alpha1 as helpers.go
Index ¶
- Constants
- Variables
- func CheckErr(err error, handleErr func(string))
- func CheckFalsy(falsy string) bool
- func CheckForIscsi(UnixSockVar UnixSock)
- func CheckTruthy(truth string) bool
- func ContainKeys(mapOfObjs map[string]interface{}, keys []string) bool
- func ContainsKey(mapOfObjs map[string]interface{}, key string) bool
- func ContainsString(stringarr []string, element string) bool
- func DeleteNestedField(obj map[string]interface{}, fields ...string)
- func Fatal(msg string)
- func FormatKV(in []string) string
- func FormatList(in []string) string
- func FormatListWithSpaces(in []string) string
- func FormatTime(t time.Time) string
- func FormatTimeDifference(first, second time.Time, d time.Duration) string
- func FormatUnixNanoTime(nano int64) string
- func GetEnv(envKey string) (value string)
- func GetMapOfStrings(obj map[string]interface{}, field string) map[string]string
- func GetNamespace() string
- func GetNestedArray(obj map[string]interface{}, fields ...string) []interface{}
- func GetNestedField(obj map[string]interface{}, fields ...string) interface{}
- func GetNestedFieldInto(out interface{}, obj map[string]interface{}, fields ...string) error
- func GetNestedInt64(obj map[string]interface{}, fields ...string) int64
- func GetNestedInt64Pointer(obj map[string]interface{}, fields ...string) *int64
- func GetNestedMap(obj map[string]interface{}, fields ...string) map[string]string
- func GetNestedSlice(obj map[string]interface{}, fields ...string) []string
- func GetNestedString(obj map[string]interface{}, fields ...string) string
- func GetOpenEBSImagePullSecrets() string
- func GetOpenebsBaseDirPath() string
- func GetServiceAccountName() string
- func Hash(obj interface{}) (string, error)
- func IsChangeInLists(listA, listB []string) bool
- func IsResponseEOD(resp []string, cmd string) bool
- func ListDiff(listA []string, listB []string) []string
- func ListIntersection(listA []string, listB []string) []string
- func LookupOrFalse(envKey string) string
- func MergeMapOfObjects(dest map[string]interface{}, src map[string]interface{}) bool
- func MergeMapOfStrings(dest map[string]string, src map[string]string) bool
- func MergeMaps(maps ...map[string]interface{}) map[string]interface{}
- func Reader(r io.Reader, cmd string) []string
- func RemoveString(slice []string, s string) (result []string)
- func SetNestedField(obj map[string]interface{}, value interface{}, fields ...string)
- func SetNestedMap(obj map[string]interface{}, value map[string]string, fields ...string)
- func SetNestedSlice(obj map[string]interface{}, value []string, fields ...string)
- func StrToInt32(val string) *int32
- func StringToInt32(val string) (*int32, error)
- func Writer(w io.Writer, msg string) error
- type FileOperator
- type LineLimitReader
- type RealFileOperator
- func (r RealFileOperator) GetLineDetails(filename, searchString string) (int, string, error)
- func (r RealFileOperator) UpdateOrAppendMultipleLines(fileName string, keyUpdateValue map[string]string, perm os.FileMode) error
- func (r RealFileOperator) Updatefile(fileName, updatedVal, searchString string, perm os.FileMode) error
- func (r RealFileOperator) Write(filename string, data []byte, perm os.FileMode) error
- type RealRunner
- func (r RealRunner) RunCombinedOutput(command string, args ...string) ([]byte, error)
- func (r RealRunner) RunCommandWithLog(command string, args ...string) ([]byte, error)
- func (r RealRunner) RunCommandWithTimeoutContext(timeout time.Duration, command string, args ...string) ([]byte, error)
- func (r RealRunner) RunStdoutPipe(command string, args ...string) ([]byte, error)
- type RealUnixSock
- type Runner
- type TestFileOperator
- func (r TestFileOperator) GetLineDetails(filename, searchString string) (int, string, error)
- func (r TestFileOperator) UpdateOrAppendMultipleLines(fileName string, keyUpdateValue map[string]string, perm os.FileMode) error
- func (r TestFileOperator) Updatefile(fileName, updateStorageVal, searchString string, perm os.FileMode) error
- func (r TestFileOperator) Write(filename string, data []byte, perm os.FileMode) error
- type TestRunner
- func (r TestRunner) RunCombinedOutput(command string, args ...string) ([]byte, error)
- func (r TestRunner) RunCommandWithLog(command string, args ...string) ([]byte, error)
- func (r TestRunner) RunCommandWithTimeoutContext(timeout time.Duration, command string, args ...string) ([]byte, error)
- func (r TestRunner) RunStdoutPipe(command string, args ...string) ([]byte, error)
- type TestUnixSock
- type UnixSock
Constants ¶
const ( // OpenEBSNamespace is the environment variable to get openebs namespace // // This environment variable is set via kubernetes downward API OpenEBSNamespace = "OPENEBS_NAMESPACE" // OpenEBSBaseDir is the environment variable to get base directory of // openebs OpenEBSBaseDir = "OPENEBS_IO_BASE_DIR" // Namespace is the environment variable to get openebs namespace // // This environment variable is set via kubernetes downward API Namespace = "NAMESPACE" // DefaultOpenEBSServiceAccount name of the default openebs service account with // required permissions DefaultOpenEBSServiceAccount = "openebs-maya-operator" // OpenEBSServiceAccount is the environment variable to get operator service // account name // // This environment variable is set via kubernetes downward API in cvc and // cspc operators deployments OpenEBSServiceAccount = "OPENEBS_SERVICEACCOUNT_NAME" // OpenEBSImagePullSecret is the environment variable that provides the image pull secrets OpenEBSImagePullSecret = "OPENEBS_IO_IMAGE_PULL_SECRETS" )
const ( IstgtConfPath = "/usr/local/etc/istgt/istgt.conf" IstgtStatusCmd = "STATUS" IstgtRefreshCmd = "REFRESH" IstgtReplicaCmd = "REPLICA" IstgtExecuteQuietCmd = "-q" ReplicaStatus = "Replica status" WaitTimeForIscsi = 3 * time.Second // IstgtResizeCmd holds the command to trigger resize IstgtResizeCmd = "RESIZE" IstgtDRFCmd = "DRF" )
const ( IstgtUctlUnxpath = "/var/run/istgt_ctl_sock" EndOfLine = "\r\n" IstgtHeader = "iSCSI Target Controller version" )
IstgtUctlUnxpath is the storage path for the UNIX domain socket from istgt
Variables ¶
var ( // ErrMAPIADDRNotSet is the new error to display this error if MAPI_ADDR is not set. ErrMAPIADDRNotSet = errors.New("MAPI_ADDR environment variable not set") // ErrInternalServerError is the new error to raise if an error occurs while rendering the service ErrInternalServerError = errors.New("Internal Server Error") ErrServerUnavailable = errors.New("Server Unavailable") // ErrServerNotReachable is the new error to raise if the server is not reachable ErrServerNotReachable = errors.New("Server Not Reachable") // ErrPageNotFound is the new error to raise if the page is not found ErrPageNotFound = errors.New("Page Not Found") )
Functions ¶
func CheckFalsy ¶
CheckFalsy checks for non-truthiness of the passed argument.
func CheckForIscsi ¶
func CheckForIscsi(UnixSockVar UnixSock)
func CheckTruthy ¶
CheckTruthy checks for truthiness of the passed argument.
func ContainKeys ¶
ContainKeys returns true if all the provided keys are present in the provided map
func ContainsKey ¶
ContainsKey returns true if the provided key is present in the provided map
func ContainsString ¶
ContainsString returns true if the provided element is present in the provided array
func DeleteNestedField ¶
DeleteNestedField deletes a nested field from the provided map
func Fatal ¶
func Fatal(msg string)
Fatal prints the message (if provided) and then exits. If V(2) or greater, klog.Fatal is invoked for extended information.
func FormatKV ¶
FormatKV takes a set of strings and formats them into properly aligned k = v pairs using the columnize library.
func FormatList ¶
FormatList takes a set of strings and formats them into properly aligned output, replacing any blank fields with a placeholder for awk-ability.
func FormatListWithSpaces ¶
FormatListWithSpaces takes a set of strings and formats them into properly aligned output. It should be used sparingly since it doesn't replace empty values and hence not awk/sed friendly
func FormatTime ¶
FormatTime formats the time to string based on RFC822
func FormatTimeDifference ¶
FormatTimeDifference takes two times and determines their duration difference truncating to a passed unit. E.g. formatTimeDifference(first=1m22s33ms, second=1m28s55ms, time.Second) -> 6s
func FormatUnixNanoTime ¶
FormatUnixNanoTime is a helper for formatting time for output.
func GetMapOfStrings ¶
GetMapOfStrings gets the direct value from the passed obj & the field path The value returned should be expected of the form map[string]string
func GetNamespace ¶
func GetNamespace() string
GetNamespace gets the namespace OPENEBS_NAMESPACE env value which is set by the downward API where CVC-Operator has been deployed
func GetNestedArray ¶
GetNestedArray returns an nested array from the provided map
func GetNestedField ¶
GetNestedField returns a nested field from the provided map
func GetNestedFieldInto ¶
GetNestedFieldInto converts a nested field to requested type from the provided map
func GetNestedInt64 ¶
GetNestedInt64 returns an nested int64 from the provided map
func GetNestedInt64Pointer ¶
GetNestedInt64Pointer returns a nested int64 pointer from the provided map
func GetNestedMap ¶
GetNestedMap returns a nested map from the provided map
func GetNestedSlice ¶
GetNestedSlice returns a nested slice from the provided map
func GetNestedString ¶
GetNestedString returns a nested string from the provided map
func GetOpenEBSImagePullSecrets ¶ added in v2.2.0
func GetOpenEBSImagePullSecrets() string
GetOpenEBSImagePullSecrets gets the image pull secrets as string from the environment variable
func GetOpenebsBaseDirPath ¶
func GetOpenebsBaseDirPath() string
GetOpenebsBaseDirPath returns the base path to store openebs related files on host machine
func GetServiceAccountName ¶
func GetServiceAccountName() string
GetServiceAccountName gets the name of OPENEBS_SERVICEACCOUNT_NAME env value which is set by the downward API of cvc and cspc operator deployments
func IsChangeInLists ¶
IsChangeInLists returns true if there is any difference in listA and listB
func IsResponseEOD ¶
IsResponseEOD will detect if the data coming from UNIX pipe is completely received
func ListIntersection ¶
ListIntersection returns list of string which are in listA and listB
func LookupOrFalse ¶
LookupOrFalse looks up an environment variable and returns a string "false" if environment variable is not present. It returns appropriate values for other cases.
func MergeMapOfObjects ¶
MergeMapOfObjects will merge the map from src to dest. It will override existing keys of the destination
func MergeMapOfStrings ¶
MergeMapOfStrings will merge the map from src to dest
func MergeMaps ¶
MergeMaps merges maps and returns the resulting map. map priority increases with order i.e. MergeMaps(m1,m2) will result in a map with overriding values from m2
func RemoveString ¶
RemoveString removes all occurrences of a string from slice and returns a new updated slice
func SetNestedField ¶
SetNestedField sets a nested field into the provided map
func SetNestedMap ¶
SetNestedMap sets a nested map from the provided map
func SetNestedSlice ¶
SetNestedSlice sets a nested slice from the provided map
func StrToInt32 ¶
StrToInt32 converts a string type to corresponding *int32 type
NOTE:
This swallows the error if any
func StringToInt32 ¶
StringToInt32 converts a string type to corresponding *int32 type
Types ¶
type FileOperator ¶
type FileOperator interface { Write(filename string, data []byte, perm os.FileMode) error Updatefile(fileName, updateVal, searchString string, perm os.FileMode) error GetLineDetails(filename, searchString string) (int, string, error) UpdateOrAppendMultipleLines(fileName string, keyUpdateValue map[string]string, perm os.FileMode) error }
FileOperator operates on files
type LineLimitReader ¶
type LineLimitReader struct { io.ReadCloser // contains filtered or unexported fields }
LineLimitReader wraps another reader and provides `tail -n` like behavior. LineLimitReader buffers up to the searchLimit and returns `-n` number of lines. After those lines have been returned, LineLimitReader streams the underlying ReadCloser
func NewLineLimitReader ¶
func NewLineLimitReader(r io.ReadCloser, lines, searchLimit int, timeLimit time.Duration) *LineLimitReader
NewLineLimitReader takes the ReadCloser to wrap, the number of lines to find searching backwards in the first searchLimit bytes. timeLimit can optionally be specified by passing a non-zero duration. When set, the search for the last n lines is aborted if no data has been read in the duration. This can be used to flush what is had if no extra data is being received. When used, the underlying reader must not block forever and must periodically unblock even when no data has been read.
type RealFileOperator ¶
type RealFileOperator struct{}
RealFileOperator is used for writing the actual files without mocking
func (RealFileOperator) GetLineDetails ¶
func (r RealFileOperator) GetLineDetails(filename, searchString string) (int, string, error)
GetLineDetails return the line number and line content of matched string in file
func (RealFileOperator) UpdateOrAppendMultipleLines ¶
func (r RealFileOperator) UpdateOrAppendMultipleLines(fileName string, keyUpdateValue map[string]string, perm os.FileMode) error
UpdateOrAppendMultipleLines will update or append multiple lines based on the given string
func (RealFileOperator) Updatefile ¶
func (r RealFileOperator) Updatefile(fileName, updatedVal, searchString string, perm os.FileMode) error
Updatefile updates the line number with the given string
type RealRunner ¶
type RealRunner struct{}
RealRunner is the real runner for the program that actually execs the command.
func (RealRunner) RunCombinedOutput ¶
func (r RealRunner) RunCombinedOutput(command string, args ...string) ([]byte, error)
RunCombinedOutput runs the command and returns its combined standard output and standard error.
func (RealRunner) RunCommandWithLog ¶
func (r RealRunner) RunCommandWithLog(command string, args ...string) ([]byte, error)
RunCommandWithLog triggers command passed as arguments and it also does the following things before command completion 1. Logs the stdout of command to stdout(standard output) 2. Logs stderr of the command to standard error
func (RealRunner) RunCommandWithTimeoutContext ¶
func (r RealRunner) RunCommandWithTimeoutContext(timeout time.Duration, command string, args ...string) ([]byte, error)
RunCommandWithTimeoutContext executes command provides and returns stdout error. If command does not returns within given timout interval command will be killed and return "Context time exceeded"
func (RealRunner) RunStdoutPipe ¶
func (r RealRunner) RunStdoutPipe(command string, args ...string) ([]byte, error)
RunStdoutPipe returns a pipe that will be connected to the command's standard output when the command starts.
type RealUnixSock ¶
type RealUnixSock struct{}
RealUnixSock is used for sending data through real unix domain sockets
func (RealUnixSock) SendCommand ¶
func (r RealUnixSock) SendCommand(cmd string) ([]string, error)
SendCommand for the real unix sock for the actual program,
type Runner ¶
type Runner interface { RunCombinedOutput(string, ...string) ([]byte, error) RunStdoutPipe(string, ...string) ([]byte, error) RunCommandWithTimeoutContext(time.Duration, string, ...string) ([]byte, error) RunCommandWithLog(string, ...string) ([]byte, error) }
Runner interface implements various methods of running binaries which can be modified for unit testing.
type TestFileOperator ¶
type TestFileOperator struct{}
TestFileOperator is used as a dummy FileOperator
func (TestFileOperator) GetLineDetails ¶
func (r TestFileOperator) GetLineDetails(filename, searchString string) (int, string, error)
GetLineDetails is to mock operation for FileOperator interface
func (TestFileOperator) UpdateOrAppendMultipleLines ¶
func (r TestFileOperator) UpdateOrAppendMultipleLines( fileName string, keyUpdateValue map[string]string, perm os.FileMode) error
UpdateOrAppendMultipleLines is to mock operation for FileOperator interface
func (TestFileOperator) Updatefile ¶
func (r TestFileOperator) Updatefile(fileName, updateStorageVal, searchString string, perm os.FileMode) error
Updatefile is to mock Updatefile operation for FileOperator interface
type TestRunner ¶
type TestRunner struct{}
TestRunner is used as a dummy Runner
func (TestRunner) RunCombinedOutput ¶
func (r TestRunner) RunCombinedOutput(command string, args ...string) ([]byte, error)
RunCombinedOutput is to mock Real runner exec.
func (TestRunner) RunCommandWithLog ¶
func (r TestRunner) RunCommandWithLog(command string, args ...string) ([]byte, error)
RunCommandWithLog is to mock real runner exec with stdoutpipe.
func (TestRunner) RunCommandWithTimeoutContext ¶
func (r TestRunner) RunCommandWithTimeoutContext(timeout time.Duration, command string, args ...string) ([]byte, error)
RunCommandWithTimeoutContext is to mock Real runner exec.
func (TestRunner) RunStdoutPipe ¶
func (r TestRunner) RunStdoutPipe(command string, args ...string) ([]byte, error)
RunStdoutPipe is to mock real runner exec with stdoutpipe.
type TestUnixSock ¶
type TestUnixSock struct{}
TestUnixSock is used as a dummy UnixSock
func (TestUnixSock) SendCommand ¶
func (r TestUnixSock) SendCommand(cmd string) ([]string, error)
SendCommand for the real unix sock for the actual program,