util

package
v3.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 22 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 (
	// ErrorLevel is the logr verbosity level for errors.
	ErrorLevel = 0

	// WarnLevel is the logr verbosity level for warnings.
	WarnLevel = 0

	// InfoLevel is the logr verbosity level for info logs.
	InfoLevel = 0

	// DebugLevel is the logr verbosity level for debug logs.
	DebugLevel = 1

	// TraceLevel is the logr verbosity level for trace logs.
	TraceLevel = 2
)

Variables

This section is empty.

Functions

func CheckCondition

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

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

func GetPodNN() (k8stypes.NamespacedName, error)

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

func GetZapEncoding

func GetZapEncoding(typ string) (zapcore.Encoder, error)

func HostnamesIntersect

func HostnamesIntersect[H1, H2 gatewayapi.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

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

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

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

func MakeLogger

func MakeLogger(level string, formatter string, output io.Writer) (*zap.Logger, error)

func ParseNameNS

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

ParseNameNS parses a string searching a namespace and name.

func PopulateTypeMeta

func PopulateTypeMeta(obj runtime.Object, s *runtime.Scheme) error

PopulateTypeMeta adds GVK information to a runtime.Object that may not have it available in the object TypeMeta.

func StringToGatewayAPIHostname

func StringToGatewayAPIHostname(hostname string) gatewayapi.Hostname

StringToGatewayAPIHostname converts a string to a gatewayapi.Hostname.

func StringToGatewayAPIHostnamePtr

func StringToGatewayAPIHostnamePtr(hostname string) *gatewayapi.Hostname

StringToGatewayAPIHostnamePtr converts a string to a *gatewayapi.Hostname.

func StringToGatewayAPIHostnameV1Beta1Ptr

func StringToGatewayAPIHostnameV1Beta1Ptr(hostname string) *gatewayapi.Hostname

StringToGatewayAPIHostnameV1Beta1Ptr converts a string to a *gatewayapi.Hostname.

func StringToGatewayAPIKindPtr

func StringToGatewayAPIKindPtr(kind string) *gatewayapi.Kind

StringToGatewayAPIKindPtr converts a string to a *gatewayapi.Kind.

func StringToGatewayAPIKindV1Alpha2Ptr

func StringToGatewayAPIKindV1Alpha2Ptr(kind string) *gatewayapi.Kind

StringToGatewayAPIKindV1Alpha2Ptr converts a string to a *gatewayapi.Kind.

func ValidateProtocol

func ValidateProtocol(protocol string) bool

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

Types

type ConditionReason

type ConditionReason string

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

type ConditionType

type ConditionType string

ConditionType can be any condition type, e.g. `gatewayapi.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 CredentialTypeSource

type CredentialTypeSource int

CredentialTypeSource indicates the source of credential type information (or lack thereof) in a Secret.

const (
	// CredentialTypeAbsent indicates that no credential information is present in a Secret.
	CredentialTypeAbsent CredentialTypeSource = iota
	// CredentialTypeFromLabel indicates that a Secret's credential type was determined from a label.
	CredentialTypeFromLabel
	// CredentialTypeFromField indicates that a Secret's credential type was determined from a data field.
	CredentialTypeFromField
)

func ExtractKongCredentialType

func ExtractKongCredentialType(secret *corev1.Secret) (string, CredentialTypeSource)

ExtractKongCredentialType returns the credential type of a Secret and a code indicating whether the credential type was obtained from a label, field, or not at all. Labels take precedence over fields if both are present.

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