gatewayapi

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCPProtocol = "TCP"
	UDPProtocol = "UDP"

	L4Protocol = "L4"
	L7Protocol = "L7"
)
View Source
const (
	KindConfigMap           = "ConfigMap"
	KindClientTrafficPolicy = "ClientTrafficPolicy"
	KindBackendTLSPolicy    = "BackendTLSPolicy"
	KindEnvoyProxy          = "EnvoyProxy"
	KindGateway             = "Gateway"
	KindGatewayClass        = "GatewayClass"
	KindGRPCRoute           = "GRPCRoute"
	KindHTTPRoute           = "HTTPRoute"
	KindNamespace           = "Namespace"
	KindTLSRoute            = "TLSRoute"
	KindTCPRoute            = "TCPRoute"
	KindUDPRoute            = "UDPRoute"
	KindService             = "Service"
	KindServiceImport       = "ServiceImport"
	KindBackend             = "Backend"
	KindSecret              = "Secret"
	KindSecurityPolicy      = "SecurityPolicy"

	GroupApoxyCore           = "core.apoxy.dev"
	GroupMultiClusterService = "multicluster.x-k8s.io"

	// OwningGatewayNamespaceLabel is the owner reference label used for managed infra.
	// The value should be the namespace of the accepted Envoy Gateway.
	OwningGatewayNamespaceLabel = "gateway.envoyproxy.io/owning-gateway-namespace"

	OwningGatewayClassLabel = "gateway.envoyproxy.io/owning-gatewayclass"
	// OwningGatewayNameLabel is the owner reference label used for managed infra.
	// The value should be the name of the accepted Envoy Gateway.
	OwningGatewayNameLabel = "gateway.envoyproxy.io/owning-gateway-name"
)
View Source
const (
	// Following the description in `timeout` section of https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto
	// Request timeout, which is defined as Duration, specifies the upstream timeout for the route
	// If not specified, the default is 15s
	HTTPRequestTimeout = "15s"
)

Variables

View Source
var (
	PathMatchTypeDerefOr       = ptr.Deref[gwapiv1.PathMatchType]
	GRPCMethodMatchTypeDerefOr = ptr.Deref[gwapiv1.GRPCMethodMatchType]
	HeaderMatchTypeDerefOr     = ptr.Deref[gwapiv1.HeaderMatchType]
	QueryParamMatchTypeDerefOr = ptr.Deref[gwapiv1.QueryParamMatchType]
)

Functions

func DowngradeBackendRef

func DowngradeBackendRef(old gwapiv1.BackendRef) gwapiv1a2.BackendRef

func DowngradeRouteParentStatuses

func DowngradeRouteParentStatuses(routeParentStatuses []gwapiv1.RouteParentStatus) []gwapiv1a2.RouteParentStatus

func FromNamespacesPtr

func FromNamespacesPtr(fromNamespaces gwapiv1.FromNamespaces) *gwapiv1.FromNamespaces

func GatewayClassOwnerLabel

func GatewayClassOwnerLabel(name string) map[string]string

GatewayClassOwnerLabel returns the GatewayCLass Owner label using the provided name as the value.

func GatewayOwnerLabels

func GatewayOwnerLabels(namespace, name string) map[string]string

GatewayOwnerLabels returns the Gateway Owner labels using the provided namespace and name as the values.

func GetBackendRef

func GetBackendRef(b BackendRefContext) *gwapiv1.BackendRef

func GetFilters

func GetFilters(b BackendRefContext) any

func GetHostnames

func GetHostnames(route RouteContext) []string

TODO: [v1alpha2-gwapiv1] This should not be required once all Route objects being implemented are of type gwapiv1. GetHostnames returns the hosts targeted by the Route object.

func GetParentReferences

func GetParentReferences(route RouteContext) []gwapiv1.ParentReference

TODO: [v1alpha2-gwapiv1] This should not be required once all Route objects being implemented are of type gwapiv1. GetParentReferences returns the ParentReference of the Route object.

func GetRouteStatus

func GetRouteStatus(route RouteContext) *gwapiv1.RouteStatus

GetRouteStatus returns the RouteStatus object associated with the Route.

func GetRouteType

func GetRouteType(route RouteContext) gwapiv1.Kind

GetRouteType returns the Kind of the Route object, HTTPRoute, TLSRoute, TCPRoute, UDPRoute etc.

func GroupDerefOr

func GroupDerefOr(group *gwapiv1.Group, defaultGroup string) string

func GroupPtr

func GroupPtr(name string) *gwapiv1.Group

func GroupPtrV1Alpha2

func GroupPtrV1Alpha2(group string) *gwapiv1a2.Group

func HasReadyListener

func HasReadyListener(listeners []*ListenerContext) bool

HasReadyListener returns true if at least one Listener in the provided list has a condition of "Ready: true", and false otherwise.

func IsRefToGateway

func IsRefToGateway(parentRef gwapiv1.ParentReference, gateway types.NamespacedName) bool

IsRefToGateway returns whether the provided parent ref is a reference to a Gateway with the given namespace/name, irrespective of whether a section/listener name has been specified (i.e. a parent ref to a listener on the specified gateway will return "true").

func KindDerefOr

func KindDerefOr(kind *gwapiv1.Kind, defaultKind string) string

func KindPtr

func KindPtr(name string) *gwapiv1.Kind

func KindPtrV1Alpha2

func KindPtrV1Alpha2(kind string) *gwapiv1a2.Kind

func NamespaceDerefOr

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

func NamespaceDerefOrAlpha

func NamespaceDerefOrAlpha(namespace *gwapiv1a2.Namespace, defaultNamespace string) string

func NamespacePtr

func NamespacePtr(name string) *gwapiv1.Namespace

func NamespacePtrV1Alpha2

func NamespacePtrV1Alpha2(namespace string) *gwapiv1a2.Namespace

func ObjectNamePtr

func ObjectNamePtr(val string) *v1alpha2.ObjectName

func PortNumPtr

func PortNumPtr(val int32) *gwapiv1.PortNumber

func PortNumPtrV1Alpha2

func PortNumPtrV1Alpha2(port int) *gwapiv1a2.PortNumber

func SectionNamePtr

func SectionNamePtr(name string) *gwapiv1.SectionName

func SectionNamePtrV1Alpha2

func SectionNamePtrV1Alpha2(sectionName string) *gwapiv1a2.SectionName

func UpgradeBackendRef

func UpgradeBackendRef(old gwapiv1a2.BackendRef) gwapiv1.BackendRef

UpgradeBackendRef converts gwapiv1a2.BackendRef to gwapiv1.BackendRef

func UpgradeParentReference

func UpgradeParentReference(old gwapiv1a2.ParentReference) gwapiv1.ParentReference

UpgradeParentReference converts gwapiv1a2.ParentReference to gwapiv1.ParentReference

func UpgradeParentReferences

func UpgradeParentReferences(old []gwapiv1a2.ParentReference) []gwapiv1.ParentReference

func UpgradeRouteParentStatuses

func UpgradeRouteParentStatuses(routeParentStatuses []gwapiv1a2.RouteParentStatus) []gwapiv1.RouteParentStatus

func ValidateGRPCRouteFilter

func ValidateGRPCRouteFilter(filter *gwapiv1.GRPCRouteFilter, extGKs ...schema.GroupKind) error

ValidateGRPCRouteFilter validates the provided filter within GRPCRoute.

func ValidateHTTPRouteFilter

func ValidateHTTPRouteFilter(filter *gwapiv1.HTTPRouteFilter, extGKs ...schema.GroupKind) error

ValidateHTTPRouteFilter validates the provided filter within HTTPRoute.

Types

type BackendRefContext

type BackendRefContext any

BackendRefContext represents a generic BackendRef object (HTTPBackendRef, GRPCBackendRef or BackendRef itself)

type ControllerResources

type ControllerResources []*Resources

ControllerResources holds all the GatewayAPI resources per GatewayClass

func (*ControllerResources) DeepCopy

DeepCopy creates a new ControllerResources. It is handwritten since the tooling was unable to copy into a new slice

func (*ControllerResources) Equal

Equal implements the Comparable interface used by watchable.DeepEqual to skip unnecessary updates.

type FiltersTranslator

type FiltersTranslator interface {
	HTTPFiltersTranslator
}

type GRPCRouteContext

type GRPCRouteContext struct {
	// GatewayControllerName is the name of the Gateway API controller.
	GatewayControllerName string

	*v1alpha2.GRPCRoute

	ParentRefs map[gwapiv1.ParentReference]*RouteParentContext
}

GRPCRouteContext wraps a GRPCRoute and provides helper methods for accessing the route's parents.

type GatewayContext

type GatewayContext struct {
	*gwapiv1.Gateway
	// contains filtered or unexported fields
}

GatewayContext wraps a Gateway and provides helper methods for setting conditions, accessing Listeners, etc.

func (*GatewayContext) ResetListeners

func (g *GatewayContext) ResetListeners()

ResetListeners resets the listener statuses and re-generates the GatewayContext ListenerContexts from the Gateway spec.

type HTTPFilterIR

type HTTPFilterIR struct {
	DirectResponse   *ir.DirectResponse
	RedirectResponse *ir.Redirect

	URLRewrite *ir.URLRewrite

	AddRequestHeaders    []ir.AddHeader
	RemoveRequestHeaders []string

	AddResponseHeaders    []ir.AddHeader
	RemoveResponseHeaders []string

	Mirrors []*ir.RouteDestination

	ExtensionRefs []*ir.UnstructuredRef
}

HTTPFilterIR contains the ir processing results.

type HTTPFiltersContext

type HTTPFiltersContext struct {
	*HTTPFilterIR

	ParentRef *RouteParentContext
	Route     RouteContext
	RuleIdx   int
}

HTTPFiltersContext is the context of http filters processing.

type HTTPFiltersTranslator

type HTTPFiltersTranslator interface {
	// contains filtered or unexported methods
}

type HTTPRouteContext

type HTTPRouteContext struct {
	// GatewayControllerName is the name of the Gateway API controller.
	GatewayControllerName string

	*gwapiv1.HTTPRoute

	ParentRefs map[gwapiv1.ParentReference]*RouteParentContext
}

HTTPRouteContext wraps an HTTPRoute and provides helper methods for accessing the route's parents.

type ListenerContext

type ListenerContext struct {
	*gwapiv1.Listener
	// contains filtered or unexported fields
}

ListenerContext wraps a Listener and provides helper methods for setting conditions and other status information on the associated Gateway, etc.

func GetReferencedListeners

func GetReferencedListeners(parentRef gwapiv1.ParentReference, gateways []*GatewayContext) (bool, []*ListenerContext)

GetReferencedListeners returns whether a given parent ref references a Gateway in the given list, and if so, a list of the Listeners within that Gateway that are included by the parent ref (either one specific Listener, or all Listeners in the Gateway, depending on whether section name is specified or not).

func (*ListenerContext) AllowsKind

func (l *ListenerContext) AllowsKind(kind gwapiv1.RouteGroupKind) bool

func (*ListenerContext) AttachedRoutes

func (l *ListenerContext) AttachedRoutes() int32

func (*ListenerContext) GetConditions

func (l *ListenerContext) GetConditions() []metav1.Condition

func (*ListenerContext) IncrementAttachedRoutes

func (l *ListenerContext) IncrementAttachedRoutes()

func (*ListenerContext) IsReady

func (l *ListenerContext) IsReady() bool

func (*ListenerContext) SetCondition

func (l *ListenerContext) SetCondition(conditionType gwapiv1.ListenerConditionType, status metav1.ConditionStatus, reason gwapiv1.ListenerConditionReason, message string)

func (*ListenerContext) SetSupportedKinds

func (l *ListenerContext) SetSupportedKinds(kinds ...gwapiv1.RouteGroupKind)

func (*ListenerContext) SetTLSSecrets

func (l *ListenerContext) SetTLSSecrets(tlsSecrets []*v1.Secret)

type ListenersTranslator

type ListenersTranslator interface {
	ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap, resources *Resources)
}

type Resources

type Resources struct {
	// This field is only used for marshalling/unmarshalling purposes and is not used by
	// the translator
	GatewayClass        *gwapiv1.GatewayClass        `json:"gatewayClass,omitempty" yaml:"gatewayClass,omitempty"`
	Gateways            []*gwapiv1.Gateway           `json:"gateways,omitempty" yaml:"gateways,omitempty"`
	HTTPRoutes          []*gwapiv1.HTTPRoute         `json:"httpRoutes,omitempty" yaml:"httpRoutes,omitempty"`
	GRPCRoutes          []*gwapiv1a2.GRPCRoute       `json:"grpcRoutes,omitempty" yaml:"grpcRoutes,omitempty"`
	TLSRoutes           []*gwapiv1a2.TLSRoute        `json:"tlsRoutes,omitempty" yaml:"tlsRoutes,omitempty"`
	TCPRoutes           []*gwapiv1a2.TCPRoute        `json:"tcpRoutes,omitempty" yaml:"tcpRoutes,omitempty"`
	UDPRoutes           []*gwapiv1a2.UDPRoute        `json:"udpRoutes,omitempty" yaml:"udpRoutes,omitempty"`
	ReferenceGrants     []*gwapiv1b1.ReferenceGrant  `json:"referenceGrants,omitempty" yaml:"referenceGrants,omitempty"`
	Namespaces          []*v1.Namespace              `json:"namespaces,omitempty" yaml:"namespaces,omitempty"`
	Services            []*v1.Service                `json:"services,omitempty" yaml:"services,omitempty"`
	ServiceImports      []*mcsapi.ServiceImport      `json:"serviceImports,omitempty" yaml:"serviceImports,omitempty"`
	EndpointSlices      []*discoveryv1.EndpointSlice `json:"endpointSlices,omitempty" yaml:"endpointSlices,omitempty"`
	Secrets             []*v1.Secret                 `json:"secrets,omitempty" yaml:"secrets,omitempty"`
	ConfigMaps          []*v1.ConfigMap              `json:"configMaps,omitempty" yaml:"configMaps,omitempty"`
	ExtensionRefFilters []unstructured.Unstructured  `json:"extensionRefFilters,omitempty" yaml:"extensionRefFilters,omitempty"`
	Backends            []*corev1alpha.Backend       `json:"backends,omitempty" yaml:"backends,omitempty"`
	Proxies             []*ctrlv1alpha1.Proxy        `json:"proxies,omitempty" yaml:"proxies,omitempty"`
}

Resources holds the Gateway API and related resources that the translators needs as inputs. +k8s:deepcopy-gen=true

func NewResources

func NewResources() *Resources

func (*Resources) DeepCopy

func (in *Resources) DeepCopy() *Resources

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resources.

func (*Resources) DeepCopyInto

func (in *Resources) DeepCopyInto(out *Resources)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Resources) GetBackend

func (r *Resources) GetBackend(name string) *corev1alpha.Backend

func (*Resources) GetConfigMap

func (r *Resources) GetConfigMap(namespace, name string) *v1.ConfigMap

func (*Resources) GetEndpointSlicesForBackend

func (r *Resources) GetEndpointSlicesForBackend(svcNamespace, svcName string, backendKind string) []*discoveryv1.EndpointSlice

func (*Resources) GetNamespace

func (r *Resources) GetNamespace(name string) *v1.Namespace

func (*Resources) GetProxy

func (r *Resources) GetProxy(name string) (*ctrlv1alpha1.Proxy, bool)

func (*Resources) GetSecret

func (r *Resources) GetSecret(namespace, name string) *v1.Secret

func (*Resources) GetService

func (r *Resources) GetService(namespace, name string) *v1.Service

func (*Resources) GetServiceImport

func (r *Resources) GetServiceImport(namespace, name string) *mcsapi.ServiceImport

type RouteContext

type RouteContext interface {
	client.Object
}

RouteContext represents a generic Route object (HTTPRoute, TLSRoute, etc.) that can reference Gateway objects.

type RouteParentContext

type RouteParentContext struct {
	*gwapiv1.ParentReference

	// TODO: [v1alpha2-gwapiv1] This can probably be replaced with
	// a single field pointing to *gwapiv1.RouteStatus.
	HTTPRoute *gwapiv1.HTTPRoute
	GRPCRoute *gwapiv1.GRPCRoute
	TLSRoute  *v1alpha2.TLSRoute
	TCPRoute  *v1alpha2.TCPRoute
	UDPRoute  *v1alpha2.UDPRoute
	// contains filtered or unexported fields
}

RouteParentContext wraps a ParentReference and provides helper methods for setting conditions and other status information on the associated HTTPRoute, TLSRoute etc.

func GetRouteParentContext

func GetRouteParentContext(route RouteContext, forParentRef gwapiv1.ParentReference) *RouteParentContext

GetRouteParentContext returns RouteParentContext by using the Route objects' ParentReference.

func (*RouteParentContext) HasCondition

func (r *RouteParentContext) HasCondition(route RouteContext, condType gwapiv1.RouteConditionType, status metav1.ConditionStatus) bool

func (*RouteParentContext) ResetConditions

func (r *RouteParentContext) ResetConditions(route RouteContext)

func (*RouteParentContext) SetCondition

func (r *RouteParentContext) SetCondition(route RouteContext, conditionType gwapiv1.RouteConditionType, status metav1.ConditionStatus, reason gwapiv1.RouteConditionReason, message string)

func (*RouteParentContext) SetListeners

func (r *RouteParentContext) SetListeners(listeners ...*ListenerContext)

type RoutesTranslator

type RoutesTranslator interface {
	ProcessHTTPRoutes(httpRoutes []*gwapiv1.HTTPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*HTTPRouteContext
	ProcessGRPCRoutes(grpcRoutes []*gwapiv1a2.GRPCRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*GRPCRouteContext
	ProcessTLSRoutes(tlsRoutes []*gwapiv1a2.TLSRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*TLSRouteContext
	ProcessTCPRoutes(tcpRoutes []*gwapiv1a2.TCPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*TCPRouteContext
	ProcessUDPRoutes(udpRoutes []*gwapiv1a2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext
}

type TCPRouteContext

type TCPRouteContext struct {
	// GatewayControllerName is the name of the Gateway API controller.
	GatewayControllerName string

	*v1alpha2.TCPRoute

	ParentRefs map[gwapiv1.ParentReference]*RouteParentContext
}

TCPRouteContext wraps a TCPRoute and provides helper methods for accessing the route's parents.

type TLSRouteContext

type TLSRouteContext struct {
	// GatewayControllerName is the name of the Gateway API controller.
	GatewayControllerName string

	*v1alpha2.TLSRoute

	ParentRefs map[gwapiv1.ParentReference]*RouteParentContext
}

TLSRouteContext wraps a TLSRoute and provides helper methods for accessing the route's parents.

type TranslateResult

type TranslateResult struct {
	Resources
	XdsIR XdsIRMap `json:"xdsIR" yaml:"xdsIR"`
}

type Translator

type Translator struct {
	// GatewayControllerName is the name of the Gateway API controller
	GatewayControllerName string

	// GatewayClassName is the name of the GatewayClass
	// to process Gateways for.
	GatewayClassName gwapiv1.ObjectName

	// GlobalRateLimitEnabled is true when global
	// ratelimiting has been configured by the admin.
	GlobalRateLimitEnabled bool

	// EndpointRoutingDisabled can be set to true to use
	// the Service Cluster IP for routing to the backend
	// instead.
	EndpointRoutingDisabled bool

	// EnvoyPatchPolicyEnabled when the EnvoyPatchPolicy
	// feature is enabled.
	EnvoyPatchPolicyEnabled bool

	// ExtensionGroupKinds stores the group/kind for all resources
	// introduced by an Extension so that the translator can
	// store referenced resources in the IR for later use.
	ExtensionGroupKinds []schema.GroupKind

	// Namespace is the namespace that Envoy Gateway runs in.
	Namespace string
}

Translator translates Gateway API resources to IRs and computes status for Gateway API resources.

func (*Translator) GetRelevantGateways

func (t *Translator) GetRelevantGateways(gateways []*gwapiv1.Gateway) []*GatewayContext

GetRelevantGateways returns GatewayContexts, containing a copy of the original Gateway with the Listener statuses reset.

func (*Translator) InitIRs

func (t *Translator) InitIRs(gateways []*GatewayContext, resources *Resources) map[string]*ir.Xds

InitIRs checks if mergeGateways is enabled in EnvoyProxy config and initializes XdsIR and InfraIR maps with adequate keys.

func (*Translator) ProcessGRPCFilters

func (t *Translator) ProcessGRPCFilters(parentRef *RouteParentContext,
	route RouteContext,
	filters []gwapiv1.GRPCRouteFilter,
	resources *Resources) *HTTPFiltersContext

ProcessGRPCFilters translates gateway api grpc filters to IRs.

func (*Translator) ProcessGRPCRoutes

func (t *Translator) ProcessGRPCRoutes(grpcRoutes []*gwapiv1a2.GRPCRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*GRPCRouteContext

func (*Translator) ProcessHTTPFilters

func (t *Translator) ProcessHTTPFilters(parentRef *RouteParentContext,
	route RouteContext,
	filters []gwapiv1.HTTPRouteFilter,
	ruleIdx int,
	resources *Resources) *HTTPFiltersContext

ProcessHTTPFilters translates gateway api http filters to IRs.

func (*Translator) ProcessHTTPRoutes

func (t *Translator) ProcessHTTPRoutes(httpRoutes []*gwapiv1.HTTPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*HTTPRouteContext

func (*Translator) ProcessListeners

func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap, resources *Resources)

func (*Translator) ProcessTCPRoutes

func (t *Translator) ProcessTCPRoutes(tcpRoutes []*gwapiv1a2.TCPRoute, gateways []*GatewayContext, resources *Resources,
	xdsIR XdsIRMap) []*TCPRouteContext

func (*Translator) ProcessTLSRoutes

func (t *Translator) ProcessTLSRoutes(tlsRoutes []*gwapiv1a2.TLSRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*TLSRouteContext

func (*Translator) ProcessUDPRoutes

func (t *Translator) ProcessUDPRoutes(udpRoutes []*gwapiv1a2.UDPRoute, gateways []*GatewayContext, resources *Resources,
	xdsIR XdsIRMap) []*UDPRouteContext

func (*Translator) Translate

func (t *Translator) Translate(resources *Resources) *TranslateResult

type TranslatorManager

type TranslatorManager interface {
	Translate(resources *Resources) *TranslateResult
	GetRelevantGateways(gateways []*gwapiv1.Gateway) []*GatewayContext

	RoutesTranslator
}

type UDPRouteContext

type UDPRouteContext struct {
	// GatewayControllerName is the name of the Gateway API controller.
	GatewayControllerName string

	*v1alpha2.UDPRoute

	ParentRefs map[gwapiv1.ParentReference]*RouteParentContext
}

UDPRouteContext wraps a UDPRoute and provides helper methods for accessing the route's parents.

type XdsIRMap

type XdsIRMap map[string]*ir.Xds

type XdsIRRoutes

type XdsIRRoutes []*ir.HTTPRoute

func (XdsIRRoutes) Len

func (x XdsIRRoutes) Len() int

func (XdsIRRoutes) Less

func (x XdsIRRoutes) Less(i, j int) bool

func (XdsIRRoutes) Swap

func (x XdsIRRoutes) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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