Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v1.11.12 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogTypeShort       = log.LstdFlags
	LogType            = log.LstdFlags | log.Lshortfile
	PKG_SUBPATH        = "/pkg/"
	CONTROLLER_SUBPATH = "/controller"
	IC_REPO            = "kubernetes-ingress/"
	IC_EE_REPO         = "kubernetes-ingress-ee/"
)
View Source
const (
	LogFieldTransactionID = "transactionID"
)

Variables

This section is empty.

Functions

func CopyMap added in v1.10.0

func CopyMap[K comparable, V any](mapArg map[K]V) map[K]V

func CopyMapOfMap added in v1.10.0

func CopyMapOfMap[K comparable, K2 any, V map[K]K2](mapArg map[K]V) map[K]V

func EqualSliceByIDFunc added in v1.10.0

func EqualSliceByIDFunc[T any](a, b []T, id func(x T) string) bool

EqualSliceByIDFunc checks equality of two slices. No duplication check.

func EqualSliceStringsWithoutOrder

func EqualSliceStringsWithoutOrder(a, b []string) bool

func GetBoolValue

func GetBoolValue(dataValue, dataName string) (result bool, err error)

func GetK8sLogger added in v1.11.0

func GetK8sLogger() *logger

func GetLogger

func GetLogger() *logger

func GetPodPrefix

func GetPodPrefix(podName string) (prefix string, err error)

func Hash

func Hash(input []byte) string

func HomeDir

func HomeDir() string

func ParseInt

func ParseInt(data string) (v int64, err error)

func ParseSize

func ParseSize(size string) (*int64, error)

func ParseTime

func ParseTime(data string) (*int64, error)

func PointerDefaultValueIfNil added in v1.10.0

func PointerDefaultValueIfNil[T any](arg *T) T

func PointerIfNotDefault added in v1.11.0

func PointerIfNotDefault[T comparable](arg T) *T

PointerIfNotDefault returns a pointer to the argument if it's not a default value for type T

func Ptr added in v1.11.0

func Ptr[V any](v V) *V

Ptr return pointer to a given value

func PtrInt64

func PtrInt64(value int64) *int64

func PtrString

func PtrString(value string) *string

Types

type Errors

type Errors []error

func (*Errors) Add

func (e *Errors) Add(errors ...error)

func (*Errors) Result

func (e *Errors) Result() error

type LogLevel

type LogLevel int8
const (
	Panic   LogLevel = 1
	Error   LogLevel = 2
	Warning LogLevel = 3
	Info    LogLevel = 4
	Debug   LogLevel = 5
	Trace   LogLevel = 6
)

type LogLevelValue

type LogLevelValue struct {
	LogLevel LogLevel
}

LogLevel used to automatically distinct namespace/name string

func (*LogLevelValue) UnmarshalFlag

func (n *LogLevelValue) UnmarshalFlag(value string) error

UnmarshalFlag Unmarshal flag

type Logger

type Logger interface {
	Print(args ...interface{}) // always print regardless of Log level
	Trace(args ...interface{}) // used for heavy duty output everything, not recommended for production
	Debug(args ...interface{}) // used to have detailed output of application flow
	Info(args ...interface{})
	InfoSkipCaller(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Err(args ...interface{}) []error
	Panic(args ...interface{})

	Printf(format string, args ...interface{})          // similar to fmt.SPrintf function
	Tracef(format string, args ...interface{})          // similar to fmt.SPrintf function
	Debugf(format string, args ...interface{})          // similar to fmt.SPrintf function
	Infof(format string, args ...interface{})           // similar to fmt.SPrintf function
	InfoSkipCallerf(format string, args ...interface{}) // similar to fmt.SPrintf function
	Warningf(format string, args ...interface{})        // similar to fmt.SPrintf function
	Errorf(format string, args ...interface{})          // similar to fmt.SPrintf function
	Panicf(format string, args ...interface{})          // similar to fmt.SPrintf function

	SetLevel(level LogLevel)
	ShowFilename(show bool)
	WithField(key string, value interface{})
	ResetFields()
}

Logger provides functions to writing log messages level can be defined only as `trace`, `debug`, `info`, `warning`, `error` error and panic are always printed, panic also exits application.

if nil is sent, it won't be printed. This is useful for printing errors only if they exist.

```

if err != nil {
  logger.Error(err)
}

``` can be shortened to ``` logger.Error(err) ```

type NamespaceValue

type NamespaceValue struct {
	Namespace, Name string
}

NamespaceValue used to automatically distinct namespace/name string

func (NamespaceValue) MarshalFlag

func (n NamespaceValue) MarshalFlag() (string, error)

MarshalFlag Marshals flag

func (NamespaceValue) String

func (n NamespaceValue) String() string

func (*NamespaceValue) UnmarshalFlag

func (n *NamespaceValue) UnmarshalFlag(value string) error

UnmarshalFlag Unmarshal flag

type OSArgs

type OSArgs struct {
	ConfigMapPatternFiles      NamespaceValue `` /* 137-byte string literal not displayed */
	ConfigMapTCPServices       NamespaceValue `long:"configmap-tcp-services" description:"configmap used to define tcp services" default:""`
	DefaultBackendService      NamespaceValue `` /* 131-byte string literal not displayed */
	ConfigMapErrorFiles        NamespaceValue `` /* 127-byte string literal not displayed */
	DefaultCertificate         NamespaceValue `long:"default-ssl-certificate" default:"" description:"secret name of the certificate"`
	ConfigMap                  NamespaceValue `long:"configmap" description:"configmap designated for HAProxy" default:""`
	IPV6BindAddr               string         `long:"ipv6-bind-address" default:"::" description:"IPv6 address the Ingress Controller listens on (if enabled)"`
	GatewayControllerName      string         `long:"gateway-controller-name" description:"sets the controller name of gatewayclass managed by the controller"`
	IPV4BindAddr               string         `long:"ipv4-bind-address" default:"0.0.0.0" description:"IPv4 address the Ingress Controller listens on (if enabled)"`
	RuntimeDir                 string         `long:"runtime-dir" description:"path to HAProxy runtime directory. NOTE: works only in External mode"`
	IngressClass               string         `long:"ingress.class" default:"" description:"ingress.class to monitor in multiple controllers environment"`
	PublishService             string         `` /* 205-byte string literal not displayed */
	CfgDir                     string         `long:"config-dir" description:"path to HAProxy configuration directory. NOTE: works only in External mode"`
	Program                    string         `long:"program" description:"path to HAProxy program. NOTE: works only with External mode"`
	KubeConfig                 string         `long:"kubeconfig" default:"" description:"combined with -e. location of kube config file"`
	DisableConfigSnippets      string         `` /* 156-byte string literal not displayed */
	Version                    []bool         `short:"v" long:"version" description:"version"`
	NamespaceWhitelist         []string       `long:"namespace-whitelist" description:"whitelisted namespaces"`
	NamespaceBlacklist         []string       `long:"namespace-blacklist" description:"blacklisted namespaces"`
	Help                       []bool         `short:"h" long:"help" description:"show this help message"`
	LocalPeerPort              int64          `long:"localpeer-port" default:"10000" description:"port to listen on for local peer"`
	StatsBindPort              int64          `long:"stats-bind-port" default:"1024" description:"port to listen on for stats page"`
	DefaultBackendPort         int            `long:"default-backend-port" description:"port to use for default service" default:"6061"`
	ChannelSize                int64          `` /* 172-byte string literal not displayed */
	ControllerPort             int            `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof" default:"6060"`
	HTTPBindPort               int64          `long:"http-bind-port" default:"8080" description:"port to listen on for HTTP traffic"`
	HTTPSBindPort              int64          `long:"https-bind-port" default:"8443" description:"port to listen on for HTTPS traffic"`
	SyncPeriod                 time.Duration  `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"`
	CacheResyncPeriod          time.Duration  `` /* 147-byte string literal not displayed */
	HealthzBindPort            int64          `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"`
	QuicAnnouncePort           int64          `long:"quic-announce-port" description:"sets the port in the alt-svc header"`
	QuicBindPort               int64          `long:"quic-bind-port" description:"sets the binding port for quic in HTTPS frontend"`
	LogLevel                   LogLevelValue  `long:"log" default:"info" description:"level of log messages you can see"`
	DisableIPV4                bool           `long:"disable-ipv4" description:"toggle to disable the IPv4 protocol from all frontends"`
	External                   bool           `short:"e" long:"external" description:"use as external Ingress Controller (out of k8s cluster)"`
	Test                       bool           `short:"t" description:"simulate running HAProxy"`
	EmptyIngressClass          bool           `` /* 175-byte string literal not displayed */
	DisableServiceExternalName bool           `long:"disable-service-external-name" description:"disable forwarding to ExternalName Services due to CVE-2021-25740"`
	UseWiths6Overlay           bool           `long:"with-s6-overlay" description:"use s6 overlay to start/stpop/reload HAProxy"`
	DisableHTTPS               bool           `long:"disable-https" description:"toggle to disable the HTTPs frontend"`
	PprofEnabled               bool           `long:"pprof" short:"p" description:"enable pprof"`
	PrometheusEnabled          bool           `long:"prometheus" description:"enable prometheus of IC data"`
	DisableHTTP                bool           `long:"disable-http" description:"toggle to disable the HTTP frontend"`
	DisableIPV6                bool           `long:"disable-ipv6" description:"toggle to disable the IPv6 protocol from all frontends"`
	UseWithPebble              bool           `long:"with-pebble" description:"use pebble to start/stop/reload HAProxy"`
	JobCheckCRD                bool           `long:"job-check-crd" description:"does not execute IC, but adds/updates CRDs"`
	DisableQuic                bool           `long:"disable-quic" description:"disable quic protocol in http frontend bindings"`
}

OSArgs contains arguments that can be sent to controller

type Pair added in v1.10.0

type Pair[T, U any] struct {
	P1 T
	P2 U
}

func NewPair added in v1.10.0

func NewPair[T, U any](p1 T, p2 U) Pair[T, U]

NewPair creates a new Pair with type inference.

Jump to

Keyboard shortcuts

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