util

package
v0.0.0-...-bf9fd61 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 39 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// PathSeparator is the separator between path elements.
	PathSeparator = "."

	// InsertIndex is the index that means "insert" when setting values
	InsertIndex = -1

	// EscapedPathSeparator is what to use when the path shouldn't separate
	EscapedPathSeparator = "\\" + PathSeparator
)

Variables

View Source
var ValidKeyRegex = regexp.MustCompile("^[a-zA-Z0-9_-]*$")

ValidKeyRegex is a regex for a valid path key element.

Functions

func ConsolidateLog

func ConsolidateLog(logMessage string) string

ConsolidateLog is a helper function to dedup the log message.

func CreateNamespace

func CreateNamespace(cs kubernetes.Interface, namespace string, network string, dryRun bool) error

CreateNamespace creates a namespace using the given k8s interface.

func DeleteFromMap

func DeleteFromMap(parentMap any, key any) error

DeleteFromMap deletes an entry with the given key parent, which must be a map.

func DeleteFromSlicePtr

func DeleteFromSlicePtr(parentSlice any, index int) error

DeleteFromSlicePtr deletes an entry at index from the parent, which must be a slice ptr.

func EqualErrors

func EqualErrors(a, b Errors) bool

EqualErrors reports whether a and b are equal, regardless of ordering.

func FindFiles

func FindFiles(path string, filter FileFilter) ([]string, error)

FindFiles reads files from path, and returns the file names that match the filter.

func GKString

func GKString(gvk schema.GroupKind) string

GKString differs from default representation of GroupKind

func InsertIntoMap

func InsertIntoMap(parentMap any, key any, value any) error

InsertIntoMap inserts value with key into parent which must be a map, map ptr, or interface to map.

func IsEmptyString

func IsEmptyString(value any) bool

IsEmptyString returns true if value is an empty string.

func IsFilePath

func IsFilePath(path string) bool

IsFilePath reports whether the given URL is a local file path.

func IsHTTPURL

func IsHTTPURL(path string) (bool, error)

IsHTTPURL checks whether the given URL is a HTTP URL.

func IsIntKind

func IsIntKind(k reflect.Kind) bool

IsIntKind reports whether k is an integer kind of any size.

func IsKVPathElement

func IsKVPathElement(pe string) bool

IsKVPathElement report whether pe is a key/value path element.

func IsMap

func IsMap(value any) bool

IsMap reports whether value is a map type.

func IsMapPtr

func IsMapPtr(v any) bool

IsMapPtr reports whether v is a map ptr type.

func IsNPathElement

func IsNPathElement(pe string) bool

IsNPathElement report whether pe is an index path element.

func IsNilOrInvalidValue

func IsNilOrInvalidValue(v reflect.Value) bool

IsNilOrInvalidValue reports whether v is nil or reflect.Zero.

func IsPtr

func IsPtr(value any) bool

IsPtr reports whether value is a ptr type.

func IsSlice

func IsSlice(value any) bool

IsSlice reports whether value is a slice type.

func IsSliceInterfacePtr

func IsSliceInterfacePtr(v any) bool

IsSliceInterfacePtr reports whether v is a slice ptr type.

func IsSlicePtr

func IsSlicePtr(v any) bool

IsSlicePtr reports whether v is a slice ptr type.

func IsString

func IsString(value any) bool

IsString reports whether value is a string type.

func IsStruct

func IsStruct(value any) bool

IsStruct reports whether value is a struct type

func IsTypeInterface

func IsTypeInterface(t reflect.Type) bool

IsTypeInterface reports whether v is an interface.

func IsTypeMap

func IsTypeMap(t reflect.Type) bool

IsTypeMap reports whether v is a map type.

func IsTypeSliceOfInterface

func IsTypeSliceOfInterface(t reflect.Type) bool

IsTypeSliceOfInterface reports whether v is a slice of interface.

func IsTypeSlicePtr

func IsTypeSlicePtr(t reflect.Type) bool

IsTypeSlicePtr reports whether v is a slice ptr type.

func IsTypeStructPtr

func IsTypeStructPtr(t reflect.Type) bool

IsTypeStructPtr reports whether v is a struct ptr type.

func IsUintKind

func IsUintKind(k reflect.Kind) bool

IsUintKind reports whether k is an unsigned integer kind of any size.

func IsVPathElement

func IsVPathElement(pe string) bool

IsVPathElement report whether pe is a value path element.

func IsValidPathElement

func IsValidPathElement(pe string) bool

IsValidPathElement reports whether pe is a valid path element.

func IsValueInterface

func IsValueInterface(v reflect.Value) bool

IsValueInterface reports whether v is an interface type.

func IsValueMap

func IsValueMap(v reflect.Value) bool

IsValueMap reports whether v is a map type.

func IsValueNil

func IsValueNil(value any) bool

IsValueNil returns true if either value is nil, or has dynamic type {ptr, map, slice} with value nil.

func IsValueNilOrDefault

func IsValueNilOrDefault(value any) bool

IsValueNilOrDefault returns true if either IsValueNil(value) or the default value for the type.

func IsValuePtr

func IsValuePtr(v reflect.Value) bool

IsValuePtr reports whether v is a ptr type.

func IsValueScalar

func IsValueScalar(v reflect.Value) bool

IsValueScalar reports whether v is a scalar type.

func IsValueSlice

func IsValueSlice(v reflect.Value) bool

IsValueSlice reports whether v is a slice type.

func IsValueStruct

func IsValueStruct(v reflect.Value) bool

IsValueStruct reports whether v is a struct type.

func IsValueStructPtr

func IsValueStructPtr(v reflect.Value) bool

IsValueStructPtr reports whether v is a struct ptr type.

func IsYAMLEmpty

func IsYAMLEmpty(y string) bool

IsYAMLEmpty reports whether the YAML string y is logically empty.

func IsYAMLEqual

func IsYAMLEqual(a, b string) bool

IsYAMLEqual reports whether the YAML in strings a and b are equal.

func MarshalWithJSONPB

func MarshalWithJSONPB(val proto.Message) (string, error)

MarshalWithJSONPB returns a YAML string representation of val (using jsonpb).

func MustStruct

func MustStruct(m map[string]any) *structpb.Struct

func MustToYAMLGeneric

func MustToYAMLGeneric(root any) string

func OverlayIOP

func OverlayIOP(base, overlay string) (string, error)

OverlayIOP overlays over base using JSON strategic merge.

func OverlayTrees

func OverlayTrees(base map[string]any, overlays ...map[string]any) (map[string]any, error)

OverlayTrees performs a sequential JSON strategic of overlays over base.

func OverlayYAML

func OverlayYAML(base, overlay string) (string, error)

OverlayYAML patches the overlay tree over the base tree and returns the result. All trees are expressed as YAML strings.

func ParseValue

func ParseValue(valueStr string) any

ParseValue parses string into a value

func PathKV

func PathKV(pe string) (k, v string, err error)

PathKV returns the key and value string parts of the entire key/value path element. It returns an error if pe is not a key/value path element.

func PathN

func PathN(pe string) (int, error)

PathN returns the index part of the entire value path element. It returns an error if pe is not an index path element.

func PathV

func PathV(pe string) (string, error)

PathV returns the value string part of the entire value path element. It returns an error if pe is not a value path element.

func PrometheusPathAndPort

func PrometheusPathAndPort(pod *v1.Pod) (string, int, error)

func ReadFilesWithFilter

func ReadFilesWithFilter(path string, filter FileFilter) (string, error)

ReadFilesWithFilter reads files from path, for a directory it recursively reads files and filters the results for single file it directly reads the file. It returns a concatenated output of all matching files' content.

func RemoveBrackets

func RemoveBrackets(pe string) (string, bool)

RemoveBrackets removes the [] around pe and returns the resulting string. It returns false if pe is not surrounded by [].

func RenderTemplate

func RenderTemplate(tmpl string, ts any) (string, error)

RenderTemplate is a helper method to render a template with the given values.

func SetLabel

func SetLabel(resource runtime.Object, label, value string) error

SetLabel is a helper function which sets the specified label and value on the specified object.

func StringBoolMapToSlice

func StringBoolMapToSlice(m map[string]bool) []string

StringBoolMapToSlice creates and returns a slice of all the map keys with true.

func ToIntValue

func ToIntValue(val any) (int, bool)

ToIntValue returns 0, false if val is not a number type, otherwise it returns the int value of val.

func ToString

func ToString(errors []error, separator string) string

ToString returns a string representation of errors, with elements separated by separator string. Any nil errors in the slice are skipped.

func ToYAML

func ToYAML(val any) string

ToYAML returns a YAML string representation of val, or the error string if an error occurs.

func ToYAMLGeneric

func ToYAMLGeneric(root any) ([]byte, error)

func ToYAMLPathString

func ToYAMLPathString(path string) string

ToYAMLPathString converts a path string such that the first letter of each path element is lower case.

func ToYAMLWithJSONPB

func ToYAMLWithJSONPB(val proto.Message) string

ToYAMLWithJSONPB returns a YAML string representation of val (using jsonpb), or the error string if an error occurs.

func UnmarshalWithJSONPB

func UnmarshalWithJSONPB(y string, out proto.Message, allowUnknownField bool) error

UnmarshalWithJSONPB unmarshals y into out using gogo jsonpb (required for many proto defined structs).

func UpdateSlicePtr

func UpdateSlicePtr(parentSlice any, index int, value any) error

UpdateSlicePtr updates an entry at index in the parent, which must be a slice ptr, with the given value.

func ValidateIOPCAConfig

func ValidateIOPCAConfig(client kube.Client, iop *iopv1alpha1.IstioOperator) error

ValidateIOPCAConfig validates if the IstioOperator CA configs are applicable to the K8s cluster

func ValueString

func ValueString(v *structpb.Value) string

func ValuesAreSameType

func ValuesAreSameType(v1 reflect.Value, v2 reflect.Value) bool

ValuesAreSameType returns true if v1 and v2 has the same reflect.Type, otherwise it returns false.

func YAMLDiff

func YAMLDiff(a, b string) string

YAMLDiff compares multiple YAML files and single YAML file

Types

type Errors

type Errors []error

Errors is a slice of error.

func AppendErr

func AppendErr(errors []error, err error) Errors

AppendErr appends err to errors if it is not nil and returns the result. If err is nil, it is not appended.

func AppendErrs

func AppendErrs(errors []error, newErrs []error) Errors

AppendErrs appends newErrs to errors and returns the result. If newErrs is empty, nothing is appended.

func NewErrs

func NewErrs(err error) Errors

NewErrs returns a slice of error with a single element err. If err is nil, returns nil.

func (Errors) Dedup

func (e Errors) Dedup() Errors

Dedup removes any duplicated errors.

func (Errors) Error

func (e Errors) Error() string

Error implements the error#Error method.

func (Errors) String

func (e Errors) String() string

String implements the stringer#String method.

func (Errors) ToError

func (e Errors) ToError() error

ToError returns an error from Errors.

type FileFilter

type FileFilter func(fileName string) bool

type Path

type Path []string

Path is a path in slice form.

func PathFromString

func PathFromString(path string) Path

PathFromString converts a string path of form a.b.c to a string slice representation.

func ToYAMLPath

func ToYAMLPath(path string) Path

ToYAMLPath converts a path string to path such that the first letter of each path element is lower case.

func (Path) Equals

func (p Path) Equals(p2 Path) bool

func (Path) String

func (p Path) String() string

String converts a string slice path representation of form ["a", "b", "c"] to a string representation like "a.b.c".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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