utils

package
v1.4.11 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package utils contains utility functions for gateway

Index

Constants

This section is empty.

Variables

View Source
var IsValidHostname = webhook.IsValidHostname

Functions

func BackendRefToServicePortName added in v1.4.0

func BackendRefToServicePortName(client cache.Cache, route client.Object, backendRef gwv1.BackendObjectReference, rps status.RouteConditionAccessor) *fgwv2.ServicePortName

BackendRefToServicePortName converts a BackendRef to a ServicePortName for a given Route if the referent is a Kubernetes Service and the port is valid.

func DeepCopy added in v1.4.0

func DeepCopy(dst any, src any) error

DeepCopy copy all fields from source to destination

func ExtensionRefToFilter added in v1.4.0

func ExtensionRefToFilter(client cache.Cache, route client.Object, extensionRef *gwv1.LocalObjectReference) *extv1alpha1.Filter

ExtensionRefToFilter converts a LocalObjectReference to a Filter.

func FilterEndpointSliceList added in v1.4.0

func FilterEndpointSliceList(endpointSliceList *discoveryv1.EndpointSliceList, port corev1.ServicePort) []*discoveryv1.EndpointSlice

FilterEndpointSliceList filters the given EndpointSliceList to only include EndpointSlices that have a matching port.

func FindBackendLBPolicy added in v1.4.0

func FindBackendLBPolicy(c cache.Cache, targetRef gwv1alpha2.LocalPolicyTargetReference, routeNamespace string) (*gwpav1alpha2.BackendLBPolicy, bool)

FindBackendLBPolicy finds the BackendTLSPolicy for the given LocalPolicyTargetReference.

func FindBackendTLSPolicy added in v1.4.0

func FindBackendTLSPolicy(c cache.Cache, targetRef gwv1alpha2.LocalPolicyTargetReferenceWithSectionName, routeNamespace string) (*gwv1alpha3.BackendTLSPolicy, bool)

FindBackendTLSPolicy finds the BackendTLSPolicy for the given LocalPolicyTargetReferenceWithSectionName.

func FindEndpointPort added in v1.4.0

func FindEndpointPort(ports []corev1.EndpointPort, svcPort corev1.ServicePort) int32

FindEndpointPort finds the port in the EndpointPort slice that matches the ServicePort.

func FindEndpointSlicePort added in v1.4.0

func FindEndpointSlicePort(ports []discoveryv1.EndpointPort, svcPort corev1.ServicePort) int32

FindEndpointSlicePort finds the port in the EndpointSlice that matches the ServicePort.

func FindGatewayClassByName added in v1.4.0

func FindGatewayClassByName(c cache.Cache, name string) (*gwv1.GatewayClass, error)

FindGatewayClassByName returns the GatewayClass with the given name

func FindHealthCheckPolicy added in v1.4.0

func FindMatchedReferenceGrant added in v1.4.0

func FindMatchedReferenceGrant(from gwtypes.CrossNamespaceFrom, to gwtypes.CrossNamespaceTo, referenceGrants []*gwv1beta1.ReferenceGrant) *gwv1beta1.ReferenceGrant

FindMatchedReferenceGrant returns if the reference is valid across namespaces based on the reference grants

func FindRetryPolicy added in v1.4.0

func GetActiveGateways added in v1.3.0

func GetActiveGateways(cache cache.Cache) []*gwv1.Gateway

GetActiveGateways returns the active gateways

func GetActiveGatewaysInNamespace added in v1.4.0

func GetActiveGatewaysInNamespace(cache cache.Cache, namespace string) []*gwv1.Gateway

GetActiveGatewaysInNamespace returns the active gateways in the namespace

func GetAllowedListeners

func GetAllowedListeners(client cache.Cache, gw *gwv1.Gateway, rps status.RouteParentStatusObject) []gwtypes.Listener

GetAllowedListeners returns the allowed listeners

func GetCARefGrants added in v1.4.0

func GetCARefGrants(c cache.Cache) []*gwv1beta1.ReferenceGrant

GetCARefGrants returns all ReferenceGrants in the cache that target a Kubernetes Secret or ConfigMap

func GetDefaultPort added in v1.4.0

func GetDefaultPort(svcPort corev1.ServicePort) int32

GetDefaultPort returns the default port for the given ServicePort.

func GetSecretRefGrants added in v1.4.0

func GetSecretRefGrants(c cache.Cache) []*gwv1beta1.ReferenceGrant

GetSecretRefGrants returns all ReferenceGrants in the cache that target a Kubernetes Secret

func GetServicePort added in v1.4.0

func GetServicePort(svc *corev1.Service, port *int32) (corev1.ServicePort, error)

GetServicePort returns the ServicePort for the given port.

func GetServiceRefGrants added in v1.4.0

func GetServiceRefGrants(c cache.Cache) []*gwv1beta1.ReferenceGrant

GetServiceRefGrants returns all ReferenceGrants in the cache that target a Kubernetes Service

func GetValidHostnames

func GetValidHostnames(listenerHostname *gwv1.Hostname, routeHostnames []gwv1.Hostname) []string

GetValidHostnames returns the valid hostnames

func GetValidListenersForGateway added in v1.3.0

func GetValidListenersForGateway(gw *gwv1.Gateway) []gwtypes.Listener

GetValidListenersForGateway returns the valid listeners from the gateway

func GroupPointer

func GroupPointer(group string) *gwv1.Group

GroupPointer returns a pointer to the given group

func HasAccessToBackendTargetRef added in v1.4.0

func HasAccessToBackendTargetRef(client cache.Cache, policy client.Object, targetRef gwv1alpha2.NamespacedPolicyTargetReference, pca status.PolicyAncestorStatusObject) bool

HasAccessToBackendTargetRef checks if the policy has access to the target reference which is a backend service

func HasAccessToTargetRef added in v1.3.0

func HasAccessToTargetRef(policy client.Object, ref gwv1alpha2.NamespacedPolicyTargetReference, referenceGrants []*gwv1beta1.ReferenceGrant) bool

HasAccessToTargetRef returns true if the policy has access to the target reference

func HostnameMatchesWildcardHostname

func HostnameMatchesWildcardHostname(hostname, wildcardHostname string) bool

HostnameMatchesWildcardHostname returns true if the hostname matches the wildcard hostname

func IsAcceptedGateway

func IsAcceptedGateway(gateway *gwv1.Gateway) bool

IsAcceptedGateway returns true if the gateway is accepted

func IsAcceptedGatewayClass

func IsAcceptedGatewayClass(gatewayClass *gwv1.GatewayClass) bool

IsAcceptedGatewayClass returns true if the gateway class is accepted

func IsAcceptedPolicyAttachment added in v1.2.0

func IsAcceptedPolicyAttachment(conditions []metav1.Condition) bool

IsAcceptedPolicyAttachment returns true if the policy attachment is accepted

func IsActiveGateway

func IsActiveGateway(gateway *gwv1.Gateway) bool

IsActiveGateway returns true if the gateway is active, it stands for the gateway is accepted, programmed and has a valid listener

func IsActiveGatewayByConditions added in v1.4.0

func IsActiveGatewayByConditions(conditions []metav1.Condition) bool

func IsEffectiveRouteForParent added in v1.4.0

func IsEffectiveRouteForParent(rsh status.RouteStatusObject, parentRef gwv1.ParentReference) bool

IsEffectiveRouteForParent returns true if the route is accepted and all references are resolved

func IsEndpointReady added in v1.4.0

func IsEndpointReady(ep discoveryv1.Endpoint) bool

IsEndpointReady returns true if the given Endpoint is ready.

func IsListenerAccepted

func IsListenerAccepted(listenerStatus gwv1.ListenerStatus) bool

IsListenerAccepted returns true if the listener is accepted

func IsListenerConflicted added in v1.4.0

func IsListenerConflicted(listenerStatus gwv1.ListenerStatus) bool

IsListenerConflicted returns true if the listener is conflicted

func IsListenerProgrammed

func IsListenerProgrammed(listenerStatus gwv1.ListenerStatus) bool

IsListenerProgrammed returns true if the listener is programmed

func IsListenerResolvedRefs added in v1.4.0

func IsListenerResolvedRefs(listenerStatus gwv1.ListenerStatus) bool

IsListenerResolvedRefs returns true if the listener is resolved refs

func IsListenerValid added in v1.4.0

func IsListenerValid(s gwv1.ListenerStatus) bool

IsListenerValid returns true if the listener is valid

func IsLocalObjRefToGateway added in v1.4.0

func IsLocalObjRefToGateway(targetRef gwv1.LocalObjectReference, gateway types.NamespacedName) bool

func IsPolicyAcceptedForAncestor added in v1.4.0

func IsPolicyAcceptedForAncestor(ancestorRef gwv1.ParentReference, ancestors []gwv1alpha2.PolicyAncestorStatus) bool

func IsProgrammedGateway added in v1.4.0

func IsProgrammedGateway(gateway *gwv1.Gateway) bool

IsProgrammedGateway returns true if the gateway is programmed

func IsRefToGateway

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

IsRefToGateway returns true if the parent reference is to the gateway

func IsTargetRefToGVK added in v1.2.0

IsTargetRefToGVK returns true if the target reference is to the given group version kind

func IsTargetRefToTarget added in v1.4.0

func IsTargetRefToTarget(policy client.Object, targetRef gwv1alpha2.NamespacedPolicyTargetReference, target client.Object) bool

IsTargetRefToTarget returns true if the target reference is to the target resource

func IsValidBackendRefToGroupKindOfService added in v1.4.0

func IsValidBackendRefToGroupKindOfService(ref gwv1.BackendObjectReference) bool

IsValidBackendRefToGroupKindOfService returns true if the reference is to a Service in the core group

func IsValidRefToGroupKindOfCA added in v1.4.0

func IsValidRefToGroupKindOfCA(ref gwv1.ObjectReference) bool

IsValidRefToGroupKindOfCA returns true if the reference is to a ConfigMap or Secret in the core group

func IsValidRefToGroupKindOfSecret added in v1.4.0

func IsValidRefToGroupKindOfSecret(ref gwv1.SecretObjectReference) bool

IsValidRefToGroupKindOfSecret returns true if the reference is to a Secret in the core group

func IsValidTargetRefToGroupKindOfService added in v1.4.0

func IsValidTargetRefToGroupKindOfService(ref gwv1alpha2.NamespacedPolicyTargetReference) bool

IsValidTargetRefToGroupKindOfService checks if the target reference is valid to the group kind of service

func NamespaceDerefOr added in v1.4.0

func NamespaceDerefOr(ns *gwv1.Namespace, defaultNs string) string

NamespaceDerefOr returns the namespace if it is not nil, otherwise returns the default namespace

func NamespaceMatches added in v1.3.0

func NamespaceMatches(client cache.Cache, namespaces *gwv1.RouteNamespaces, gatewayNamespace, routeNamespace string) bool

NamespaceMatches returns true if the namespace matches

func ObjectRefToCACertificate added in v1.4.0

func ObjectRefToCACertificate(client cache.Cache, referer client.Object, ref gwv1.ObjectReference, ancestorStatus status.PolicyAncestorStatusObject) []byte

ObjectRefToCACertificate converts an ObjectReference to a CA Certificate. It supports Kubernetes Secret and ConfigMap as the referent.

func SortResources added in v1.4.0

func SortResources[T client.Object](resources []T) []T

SortResources sorts the resources by creation timestamp and name

func ToSlicePtr added in v1.4.0

func ToSlicePtr[T any](slice []T) []*T

func ValidCrossNamespaceRef added in v1.3.0

func ValidCrossNamespaceRef(from gwtypes.CrossNamespaceFrom, to gwtypes.CrossNamespaceTo, referenceGrants []*gwv1beta1.ReferenceGrant) bool

ValidCrossNamespaceRef returns if the reference is valid across namespaces based on the reference grants

Types

This section is empty.

Jump to

Keyboard shortcuts

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