helpers

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GatewaySecretIndex indexes Gateways by referenced TLS Secrets.
	GatewaySecretIndex = "gatewaySecretIndex"

	// ListenerSetSecretIndex indexes ListenerSets by referenced TLS Secrets.
	ListenerSetSecretIndex = "listenerSetSecretIndex"
)
View Source
const (
	GatewayClassKind     string = "gatewayclasses"
	GatewayKind          string = "gateways"
	HTTPRouteKind        string = "httproutes"
	GRPCRouteKind        string = "grpcroutes"
	ReferenceGrantKind   string = "referencegrants"
	BackendTLSPolicyKind string = "backendtlspolicies"
	TLSRouteKind         string = "tlsroutes"
	TCPRouteKind         string = "tcproutes"
	UDPRouteKind         string = "udproutes"
	ListenerSetKind      string = "listenersets"
	ServiceImportKind    string = "serviceimports"
)

Variables

Functions

func ConditionChanged added in v1.20.0

func ConditionChanged(a, b metav1.Condition) bool

func ContainsCommonHTTPRoute added in v1.20.0

func ContainsCommonHTTPRoute(a, b []gatewayv1.HTTPRoute) (bool, error)

ContainsCommonHTTPRoute checks to see if the two slices of HTTPRoutes contain at least one identical HTTPRoute. If so, returns true.

Returns an error if the two lists contain a HTTPRoute that is the same object with a different generation; this means there has been a HTTPRoute update between when the two lists were generated, and the whole reconciliation must be restarted.

func GatewayClassMatchesControllerName added in v1.20.0

func GatewayClassMatchesControllerName(controllerName string) func(object client.Object) bool

GatewayClassMatchesControllerName is a closure that returns a function that satisfies the controller-runtime predicate signature, allowing this to be used in predicate contexts as well as others.

func GatewayHasMatchingControllerFn added in v1.20.0

func GatewayHasMatchingControllerFn(ctx context.Context, c client.Client, controllerName string, logger *slog.Logger) func(object client.Object) bool

func GatewayV1GVK added in v1.20.0

func GatewayV1GVK(kind string) schema.GroupVersionKind

GatewayV1GVK returns the GroupVersionKind for a given Gateway API v1 kind.

func GetBackendServiceName added in v1.16.0

func GetBackendServiceName(k8sclient client.Client, namespace string, backendObjectReference gatewayv1.BackendObjectReference) (string, error)

func GetConcreteListObject added in v1.20.0

func GetConcreteListObject(schemaType schema.GroupVersionKind) runtime.Object

getConcreteListObject returns a list instance of a concrete object type based on the given GroupVersionKind.

func GetConcreteObject added in v1.17.0

func GetConcreteObject(schemaType schema.GroupVersionKind) runtime.Object

getConcreteObject returns an instance of a concrete object type based on the given GroupVersionKind.

func GetGatewaysForSecret added in v1.20.0

func GetGatewaysForSecret(ctx context.Context, c client.Client, obj client.Object, controllerName string, logger *slog.Logger) []*gatewayv1.Gateway

func GetServiceName added in v1.16.0

func GetServiceName(svcImport *mcsapiv1beta1.ServiceImport) (string, error)

func HasListenerSetSupport added in v1.20.0

func HasListenerSetSupport(scheme *runtime.Scheme) bool

func HasServiceImportSupport added in v1.16.0

func HasServiceImportSupport(scheme *runtime.Scheme) bool

HasServiceImportSupport return if the ServiceImport CRD is supported. This checks if the MCS API group ServiceImport CRD is registered in the client scheme and it is expected that it is registered only if the ServiceImport CRD has been installed prior to the client setup.

func HasTCPRouteSupport added in v1.20.0

func HasTCPRouteSupport(scheme *runtime.Scheme) bool

HasTCPRouteSupport returns if the TCPRoute CRD is supported. This checks if the Gateway API v1 TCPRoute CRD is registered in the client scheme.

func HasTLSRouteSupport added in v1.17.4

func HasTLSRouteSupport(scheme *runtime.Scheme) bool

HasTLSRouteSupport returns if the TLSRoute CRD is supported. This checks if the Gateway API v1alpha2 TLSRoute CRD is registered in the client scheme and it is expected that it is registered only if the TLSRoute CRD has been installed prior to the client setup.

func HasUDPRouteSupport added in v1.20.0

func HasUDPRouteSupport(scheme *runtime.Scheme) bool

HasUDPRouteSupport returns if the UDPRoute CRD is supported. This checks if the Gateway API v1 UDPRoute CRD is registered in the client scheme.

func IsAccepted added in v1.20.0

func IsAccepted(conds []metav1.Condition) bool

func IsBackendReferenceAllowed

func IsBackendReferenceAllowed(originatingNamespace string, be gatewayv1.BackendRef, gvk schema.GroupVersionKind, grants []gatewayv1.ReferenceGrant) bool

IsBackendReferenceAllowed returns true if the backend reference is allowed by the reference grant.

func IsConditionPresent added in v1.18.3

func IsConditionPresent(conds []metav1.Condition, condType string) bool

func IsConfigMap added in v1.20.0

func IsConfigMap(certRef gatewayv1.LocalObjectReference) bool

func IsGammaService added in v1.16.0

func IsGammaService(parent gatewayv1.ParentReference) bool

func IsGammaServiceEqual added in v1.17.8

func IsGammaServiceEqual(parent gatewayv1.ParentReference, gammaService *corev1.Service, objNamespace string) bool

func IsGateway

func IsGateway(parent gatewayv1.ParentReference) bool

func IsHTTPSTerminatedListener added in v1.19.6

func IsHTTPSTerminatedListener(listener *gatewayv1.Listener) bool

IsHTTPSTerminatedListener returns true for HTTPS listeners that terminate TLS.

func IsListenerNamespaceAllowed added in v1.19.6

func IsListenerNamespaceAllowed(listener gatewayv1.Listener, routeNamespace, gatewayNamespace string, namespaces NamespaceLabelIndex) bool

IsListenerNamespaceAllowed checks whether a route in routeNamespace is permitted to attach to the given listener based on AllowedRoutes.Namespaces.

func IsListenerSet added in v1.20.0

func IsListenerSet(parent gatewayv1.ParentReference) bool

func IsParentAttachable added in v1.20.0

func IsParentAttachable(
	_ context.Context,
	reconcileParent metav1.Object,
	route metav1.Object,
	parents []gatewayv1.RouteParentStatus,
	attachedListenerSets []gatewayv1.ListenerSet,
) bool

func IsSecret

func IsSecret(secret gatewayv1.SecretObjectReference) bool

func IsSecretReferenceAllowed

func IsSecretReferenceAllowed(originatingNamespace string, sr gatewayv1.SecretObjectReference, gvk schema.GroupVersionKind, grants []gatewayv1.ReferenceGrant) bool

IsSecretReferenceAllowed returns true if the secret reference is allowed by the reference grant.

func IsServiceImport added in v1.16.0

func IsServiceImport(be gatewayv1.BackendObjectReference) bool

func IsServiceTargetRef added in v1.20.0

func IsTLSPassthroughListener added in v1.19.6

func IsTLSPassthroughListener(listener *gatewayv1.Listener) bool

IsTLSPassthroughListener returns true for TLS listeners configured for passthrough mode.

func IsValidGammaService added in v1.20.0

func IsValidGammaService(svc *corev1.Service) bool

func IsValidPemFormat added in v1.20.0

func IsValidPemFormat(b []byte) bool

IsValidPemFormat checks if the given byte array contains at least one valid PEM formatted object, either certificate or key. This function is not intended to be used for validating the actual content of the PEM block.

func ListenerEntryToListener added in v1.20.0

func ListenerEntryToListener(entry gatewayv1.ListenerEntry) gatewayv1.Listener

func ListenerHostname added in v1.19.6

func ListenerHostname(listener *gatewayv1.Listener) string

ListenerHostname returns the listener hostname, or an empty string for catch-all listeners.

func ListenerSetParentGateway added in v1.20.0

func ListenerSetParentGateway(ls *gatewayv1.ListenerSet) *types.NamespacedName

func MergeConditions added in v1.20.0

func MergeConditions(existingConditions []metav1.Condition, updates ...metav1.Condition) []metav1.Condition

func NamespaceDerefOr

func NamespaceDerefOr(namespace *gatewayv1.Namespace, defaultNamespace string) string

func ObjectsEqual added in v1.20.0

func ObjectsEqual(a, b client.Object) (bool, error)

ObjectsEqual checks to see if two Kubernetes objects are the same object (meaning same Kind, Namespace, Name, and Generation). Returns true if all of those are the same.

Kind, Namespace, and Name being the same means that they are the same object but if the Generation is different, then there has been an update to the object between when the two objects were fetched, so any reconciliation should be retried. In this case, returns true but an error, so that we can catch this and fail the reconciliation.

func RegisterGatewayAPITypesToScheme added in v1.20.0

func RegisterGatewayAPITypesToScheme(scheme *runtime.Scheme, optionalKinds []schema.GroupVersionKind) error

func ResolveListenerSetToGateway added in v1.20.0

func ResolveListenerSetToGateway(
	ctx context.Context, c client.Client,
	lsName string, lsNamespace string,
) *types.NamespacedName

func SNIHostnamesIntersect added in v1.19.6

func SNIHostnamesIntersect(a, b string) bool

SNIHostnamesIntersect returns true when two hostnames can match the same SNI value. Empty hostnames are normalized to catch-all.

func TestScheme added in v1.20.0

func TestScheme(optionalKinds []schema.GroupVersionKind) *runtime.Scheme

Types

type BackendTLSPolicyServiceMap added in v1.20.0

type BackendTLSPolicyServiceMap map[types.NamespacedName]*BackendTLSPolicyTargetServiceCollection

BackendTLSPolicyServiceMap is a lookup map that tracks valid and invalid BackendTLSPolicies by the relevant targetRef service full name.

func BuildBackendTLSPolicyLookup added in v1.20.0

func BuildBackendTLSPolicyLookup(btlspList *gatewayv1.BackendTLSPolicyList) BackendTLSPolicyServiceMap

BuildBackendTLSPolicyLookup builds a lookup map of BackendTLSPolicy by the NamespacedName of referenced backend Services. These are deduplicated using the Gateway API conflict resolution rules (oldest wins, then first lexicographically wins).

type BackendTLSPolicyTargetServiceCollection added in v1.20.0

type BackendTLSPolicyTargetServiceCollection struct {
	// Valid holds the map of the section name on the Service
	// to the relevant BackendTLSPolicy.
	//
	// Note that the an empty value for SectionName means
	// "all sections", and will conflict with any other section name.
	Valid map[gatewayv1.SectionName]*gatewayv1.BackendTLSPolicy
	// Invalid holds the map of the section name on the Service
	// to the BackendTLSPolicy that failed Cilium-specific validation.
	Invalid map[gatewayv1.SectionName]*gatewayv1.BackendTLSPolicy
	// Conflicted holds the all the conflicted BackendTLSPolicies that
	// target this Service, with the map key being the object's full name.
	// This avoids traversing a slice to find a match all the time.
	Conflicted map[types.NamespacedName]*gatewayv1.BackendTLSPolicy
}

BackendTLSPolicyTargetServiceCollection holds all the BackendTLSPolicy objects that targetRef Service, including which ones are valid and which conflicted.

This is required because BackendTLSPolicy objects can: * target multiple Services * target the same Service, with different ports

And, multiple BackendTLSPolicies can also do the same.

Gateway API conflict resolution rules dictate that, when two BackendTLSPolicies target the same Service, the precedence goes, continuing on ties:

1. Oldest BackendTLSPolicy, by creation time 2. First BackendTLSPolicy, lexigraphically sorted.

The BackendTLSPolicyTargetServiceCollection struct holds details about which are the Valid (chosen) policies, and which are Conflicted. This is then used by the status-setting functions to figure out what status to set.

func (*BackendTLSPolicyTargetServiceCollection) DeleteValidPolicy added in v1.20.0

func (b *BackendTLSPolicyTargetServiceCollection) DeleteValidPolicy(sectionName gatewayv1.SectionName)

func (*BackendTLSPolicyTargetServiceCollection) UpsertConflictedPolicy added in v1.20.0

func (b *BackendTLSPolicyTargetServiceCollection) UpsertConflictedPolicy(btlspFullName types.NamespacedName, btlsp *gatewayv1.BackendTLSPolicy)

func (*BackendTLSPolicyTargetServiceCollection) UpsertInvalidPolicy added in v1.20.0

func (b *BackendTLSPolicyTargetServiceCollection) UpsertInvalidPolicy(sectionName gatewayv1.SectionName, btlsp *gatewayv1.BackendTLSPolicy)

func (*BackendTLSPolicyTargetServiceCollection) UpsertValidPolicy added in v1.20.0

type NamespaceLabelIndex added in v1.19.6

type NamespaceLabelIndex map[string]map[string]string

NamespaceLabelIndex indexes namespace labels by namespace name.

func NewNamespaceLabelIndex added in v1.19.6

func NewNamespaceLabelIndex(namespaces []corev1.Namespace) NamespaceLabelIndex

Directories

Path Synopsis
testhelpers contains functions and fixtures that are helpful for testing multiple parts of the Gateway API code.
testhelpers contains functions and fixtures that are helpful for testing multiple parts of the Gateway API code.

Jump to

Keyboard shortcuts

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