utils

package
v0.0.0-...-fb5a1ab Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

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

Variables

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

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

NoOptions is used to pass empty options

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 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 GetOption

func GetOption[T any](options Options, name string, ifNotFound T) (T, bool)

GetOption from the named value from the list of options and convert it as needed

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.

func InitStaticLogger

func InitStaticLogger(component string) logr.Logger

InitStaticLogger creates a logger and optionally initializes the verbosity with the value in LOG_LEVEL and replaces the static logger with the newly-created logger.

func OutputMap

func OutputMap(spec *obs.ClusterLogForwarderSpec) map[string]*obs.OutputSpec

OutputMap returns a map of names to outputs.

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 Update

func Update[T any](options Options, name string, value T, updater func(T) T)

Update sets the named options with the provided value processing it using the provided function if not nil

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 Options

type Options map[string]interface{}

Options is a map of Options used to customize the config generation. E.g. Debugging, legacy config generation

func (Options) AddToStringSet

func (o Options) AddToStringSet(name string, values ...string)

func (Options) GetStringSet

func (o Options) GetStringSet(name string) []string

func (Options) Has

func (o Options) Has(key string) bool

Has takes a key and returns true if it exists

func (Options) Set

func (o Options) Set(key string, value interface{}) Options

Set the option to the given value and return the options

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

Directories

Path Synopsis
scc

Jump to

Keyboard shortcuts

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