utils

package
v0.0.0-...-c6c896d Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OsNodeLabel = "kubernetes.io/os"
	LinuxValue  = "linux"
)

Variables

COMPONENT_IMAGES are thee keys are based on the "container name" + "-{image,version}"

View Source
var (
	DefaultNodeSelector = map[string]string{OsNodeLabel: LinuxValue}
)

Functions

func AddLabels

func AddLabels(object metav1.Object, labels map[string]string)

func AddOwnerRefToObject

func AddOwnerRefToObject(object metav1.Object, ownerRef metav1.OwnerReference)

AddOwnerRefToObject adds the parent as an owner to the child

func AreMapsSame

func AreMapsSame(lhs, rhs map[string]string) bool

func AreResourcesDifferent

func AreResourcesDifferent(current, desired *v1.PodSpec) bool

func AreResourcesSame

func AreResourcesSame(current, desired *v1.ResourceRequirements) bool

func AreTolerationsSame

func AreTolerationsSame(lhs, rhs []v1.Toleration) bool

func AsOwner

func CalculateMD5Hash

func CalculateMD5Hash(text string) (string, error)

CalculateMD5Hash returns a MD5 hash of the give text

func EnsureLinuxNodeSelector

func EnsureLinuxNodeSelector(selectors map[string]string) map[string]string

EnsureLinuxNodeSelector takes given selector map and returns a selector map with linux node selector added into it. If there is already a node type selector and is different from "linux" then it is overridden and warning is logged. See https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#interlude-built-in-node-labels

func EnvValueEqual

func EnvValueEqual(env1, env2 []v1.EnvVar) bool

* EnvValueEqual - check if 2 EnvValues are equal or not Notes: - reflect.DeepEqual does not return expected results if the to-be-compared value is a pointer. - needs to adjust with k8s.io/api/core/v#/types.go when the types are updated. *

func EnvVarResourceFieldSelectorEqual

func EnvVarResourceFieldSelectorEqual(resource1, resource2 v1.ResourceFieldSelector) bool

func EnvVarSourceEqual

func EnvVarSourceEqual(esource1, esource2 v1.EnvVarSource) bool

func GetCollectorName

func GetCollectorName(collectorType logging.LogCollectionType) string

func GetComponentImage

func GetComponentImage(component string) string

GetComponentImage returns a full image pull spec for a given component based on the component type

func GetEnvVar

func GetEnvVar(name string, envVars []v1.EnvVar) (v1.EnvVar, bool)

GetEnvVar returns EnvVar entry that matches the given name

func GetFileContents

func GetFileContents(filePath string) []byte

func GetProxyEnvVars

func GetProxyEnvVars() []v1.EnvVar

func GetPtr

func GetPtr[T any](value T) *T

func HasSameOwner

func HasSameOwner(curr []metav1.OwnerReference, desired []metav1.OwnerReference) bool

func InitLogger

func InitLogger(component string) logr.Logger

InitLogger creates a logger and optionally initializes the verbosity with the value in LOG_LEVEL.

It also replaces the static logger with the newly-created logger.

func PodVolumeEquivalent

func PodVolumeEquivalent(lhs, rhs []v1.Volume) bool

func RemoveString

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

func ToJsonLogs

func ToJsonLogs(logs []string) string

func WrapError

func WrapError(err error) error

WrapError wraps some types of error to provide more informative Error() message. If err is exec.ExitError and has Stderr text, include it in Error() Otherwise return err unchanged.

Types

type Float64Map

type Float64Map struct {
	// contains filtered or unexported fields
}

func InitFloat64Map

func InitFloat64Map(m map[string]float64) *Float64Map

func (*Float64Map) Get

func (fm *Float64Map) Get(key string) float64

for prometheus gauge metric getting a value of float64

func (*Float64Map) Inc

func (fm *Float64Map) Inc(key string)

for prometheus gauge metric setting up a value of float64

func (*Float64Map) Range

func (fm *Float64Map) Range(f func(key, value interface{}) bool)

type StringMap

type StringMap struct {
	// contains filtered or unexported fields
}

StringMap is a concurrent-safe map[string]string based on sync.Map

func InitStringMap

func InitStringMap(m map[string]string) *StringMap

func (*StringMap) Get

func (sm *StringMap) Get(key string) string

Get is a wrapper for getting the value from the underlying map

func (*StringMap) Range

func (sm *StringMap) Range(f func(key, value interface{}) bool)

func (*StringMap) Set

func (sm *StringMap) Set(key string, val string)

Set is a wrapper for setting the value of a key in the underlying map

Jump to

Keyboard shortcuts

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