util

package
v2.12.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	K8sNamespaceTagPrefix = "k8s-namespace:"
	K8sNameTagPrefix      = "k8s-name:"
	K8sUIDTagPrefix       = "k8s-uid:"
	K8sKindTagPrefix      = "k8s-kind:"
	K8sGroupTagPrefix     = "k8s-group:"
	K8sVersionTagPrefix   = "k8s-version:"
)
View Source
const (

	// InfoLevel is the converted logging level from logrus to go-logr for
	// information level logging. Note that the logrusr middleware technically
	// flattens all levels prior to this level into this level as well.
	InfoLevel = int(logrus.InfoLevel) - logrusrDiff

	// DebugLevel is the converted logging level from logrus to go-logr for
	// debug level logging.
	DebugLevel = int(logrus.DebugLevel) - logrusrDiff

	// WarnLevel is the converted logrus level to go-logr for warnings.
	WarnLevel = int(logrus.WarnLevel) - logrusrDiff
)

we currently implement two different loggers and use a middleware called logrusr to translate logrus loggers into go-logrs (used by controller-runtime). The middleware currently squashes loglevels 0-4 together and effectively starts the "info" level logging at 0 (whereas logrus starts that at 4 (range from 0)). Since the middleware at the time of writing made all of this part of the private implementation these options are used for convenience until a time when we unify our logging implementations into one or the other.

See: https://github.com/Kong/kubernetes-ingress-controller/issues/1893

Variables

This section is empty.

Functions

func CheckCondition added in v2.7.0

func CheckCondition(
	conditions []metav1.Condition,
	typ ConditionType,
	reason ConditionReason,
	status metav1.ConditionStatus,
	resourceGeneration int64,
) bool

CheckCondition tells if there's a condition matching the given type, reason, and status in conditions. It also makes sure that the condition's observed generation is no older than the resource's actual generation.

func GenerateTagsForObject added in v2.9.0

func GenerateTagsForObject(obj client.Object) []*string

GenerateTagsForObject returns a subset of an object's metadata as a slice of prefixed string pointers.

func GetNodeIPOrName

func GetNodeIPOrName(ctx context.Context, kubeClient clientset.Interface, name string) string

GetNodeIPOrName returns the IP address or the name of a node in the cluster.

func GetPodNN added in v2.9.0

func GetPodNN() (k8stypes.NamespacedName, error)

GetPodNN returns NamespacedName of pod that this process is running in.

func HostnamesIntersect added in v2.6.0

func HostnamesIntersect[H1, H2 types.HostnameT](hostnameA H1, hostnameB H2) bool

HostnamesIntersect checks if the hostnameA and hostnameB have an intersection. To perform this check, the function HostnamesMatch is called twice swapping the parameters and using first hostnameA as a mask, then hostnameB. If there is at least one match, the hostnames intersect.

func HostnamesMatch added in v2.6.0

func HostnamesMatch(hostnameA, hostnameB string) bool

HostnamesMatch checks that the hostnameB matches the hostnameA. HostnameA is treated as mask to be checked against the hostnameB.

func IsBackendRefGroupKindSupported added in v2.6.0

func IsBackendRefGroupKindSupported(gatewayAPIGroup *gatewayv1beta1.Group, gatewayAPIKind *gatewayv1beta1.Kind) bool

IsBackendRefGroupKindSupported checks if the GroupKind of the object used as BackendRef for the HTTPRoute is supported.

func MakeDebugLoggerWithReducedRedudancy

func MakeDebugLoggerWithReducedRedudancy(writer io.Writer, formatter logrus.Formatter,
	redudantLogEntryAllowedConsecutively int, redundantLogEntryBackoff time.Duration,
) *logrus.Logger

MakeDebugLoggerWithReducedRedudancy is a logrus.Logger that "stifles" repetitive logs.

The "stifling" mechanism is triggered by one of two conditions the result of which is that the "stifled" log entry will be dropped entirely.

The conditions checked are:

  1. This logger will drop log entries where an identical log entry has posted within the last "redundantLogEntryBackoff". For example, you could set this to "time.Second * 3" and the result would be that if the logger had already logged an identical message within the previous 3 seconds it will be dropped.

  2. This logger will "stifle" redudant entries which are logged consecutively a number of times equal to the provided "redudantLogEntryAllowedConsecutively" number. For example, you could set this to 3 and then if the last 3 log entries emitted were the same message further entries of the same message would be dropped.

The caller can choose to set either argument to "0" to disable that check, but setting both to zero will result in no redundancy reduction.

NOTE: Please consider this logger a "debug" only logging implementation. This logger was originally created to help reduce the noise coming from the controller during integration tests for better human readability, so keep in mind it was built for testing environments if you're currently reading this and you're considering using it somewhere that would produce production environment logs: there's significant performance overhead triggered by the logging hooks this adds.

func MakeLogger

func MakeLogger(level string, formatter string, output io.Writer) (logrus.FieldLogger, error)

func ParseNameNS

func ParseNameNS(input string) (string, string, error)

ParseNameNS parses a string searching a namespace and name.

func StringToGatewayAPIHostname added in v2.6.0

func StringToGatewayAPIHostname(hostname string) gatewayv1alpha2.Hostname

StringToGatewayAPIHostname converts a string to a gatewayv1alpha2.Hostname.

func StringToGatewayAPIHostnamePtr added in v2.6.0

func StringToGatewayAPIHostnamePtr(hostname string) *gatewayv1beta1.Hostname

StringToGatewayAPIHostnamePtr converts a string to a *gatewayv1beta1.Hostname.

func StringToGatewayAPIHostnameV1Beta1 added in v2.6.0

func StringToGatewayAPIHostnameV1Beta1(hostname string) gatewayv1beta1.Hostname

StringToGatewayAPIHostnameV1Beta1 converts a string to a gatewayv1beta1.Hostname.

func StringToGatewayAPIHostnameV1Beta1Ptr added in v2.6.0

func StringToGatewayAPIHostnameV1Beta1Ptr(hostname string) *gatewayv1beta1.Hostname

StringToGatewayAPIHostnameV1Beta1Ptr converts a string to a *gatewayv1beta1.Hostname.

func StringToGatewayAPIKindPtr added in v2.6.0

func StringToGatewayAPIKindPtr(kind string) *gatewayv1beta1.Kind

StringToGatewayAPIKindPtr converts a string to a *gatewayv1beta1.Kind.

func StringToGatewayAPIKindV1Alpha2Ptr added in v2.8.0

func StringToGatewayAPIKindV1Alpha2Ptr(kind string) *gatewayv1alpha2.Kind

StringToGatewayAPIKindV1Alpha2Ptr converts a string to a *gatewayv1alpha2.Kind.

func ValidateProtocol

func ValidateProtocol(protocol string) bool

ValidateProtocol returns a bool of whether string is a valid protocol.

Types

type ConditionReason added in v2.7.0

type ConditionReason string

ConditionReason can be any condition reason, e.g. `gatewayv1beta1.GatewayReasonProgrammed`.

type ConditionType added in v2.7.0

type ConditionType string

ConditionType can be any condition type, e.g. `gatewayv1beta1.GatewayConditionProgrammed`.

type ConfigDump

type ConfigDump struct {
	Config file.Content
	Failed bool
}

ConfigDump contains a config dump and a flag indicating that the config was not successfully applid.

type ConfigDumpDiagnostic

type ConfigDumpDiagnostic struct {
	DumpsIncludeSensitive bool
	Configs               chan ConfigDump
}

ConfigDumpDiagnostic contains settings and channels for receiving diagnostic configuration dumps.

type Endpoint

type Endpoint struct {
	// Address IP address of the endpoint
	Address string `json:"address"`
	// Port number of the TCP port
	Port string `json:"port"`
}

Endpoint describes a kubernetes endpoint, same as a target in Kong.

type ForeignRelations

type ForeignRelations struct {
	Consumer, ConsumerGroup, Route, Service []string
}

func (*ForeignRelations) GetCombinations

func (relations *ForeignRelations) GetCombinations() []Rel

type K8sObjectInfo

type K8sObjectInfo struct {
	Name             string
	Namespace        string
	Annotations      map[string]string
	GroupVersionKind schema.GroupVersionKind
}

K8sObjectInfo describes a Kubernetes object.

func FromK8sObject

func FromK8sObject(obj client.Object) K8sObjectInfo

type PluginSchemaStore

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

PluginSchemaStore retrives a schema of a Plugin from Kong.

func NewPluginSchemaStore

func NewPluginSchemaStore(client *kong.Client) *PluginSchemaStore

NewPluginSchemaStore creates a PluginSchemaStore.

func (*PluginSchemaStore) Schema

func (p *PluginSchemaStore) Schema(ctx context.Context, pluginName string) (map[string]interface{}, error)

Schema retrives schema of a plugin. A cache is used to save the responses and subsequent queries are served from the cache.

type PodInfo

type PodInfo struct {
	Name      string
	Namespace string
	NodeIP    string
	// Labels selectors of the running pod
	// This is used to search for other Ingress controller pods
	Labels map[string]string
}

PodInfo contains runtime information about the pod running the Ingres controller.

func GetPodDetails

func GetPodDetails(ctx context.Context, kubeClient clientset.Interface) (*PodInfo, error)

GetPodDetails returns runtime information about the pod: name, namespace and IP of the node where it is running.

type Rel

type Rel struct {
	Consumer, ConsumerGroup, Route, Service string
}

Directories

Path Synopsis
kubernetes

Jump to

Keyboard shortcuts

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