Documentation ¶
Overview ¶
Package resourcediscovery discovers and maps relationships between Gateway API resources. It constructs a graph-like model representing resource dependencies and their interactions.
Key features:
Resource discovery: ¶
- Fetches GatewayClasses, Gateways, HTTPRoutes, Backends, and Policies based on filters.
- Discovers related resources by following references between them.
Resource model construction: ¶
- Builds a graph-like model representing resources and their connections.
- Tracks relationships between GatewayClasses, Gateways, HTTPRoutes, Backends, Namespaces, and Policies.
Policy evaluation: ¶
- Identifies effective policies applicable to each resource, considering inheritance and hierarchy.
Index ¶
- func BackendID(group, kind, namespace, name string) backendID
- func BackendIDForService(namespace, name string) backendID
- func ConvertPoliciesMapToPolicyRefs(policies map[policyID]*PolicyNode) []policymanager.ObjRef
- func GatewayClassID(gatewayClassName string) gatewayClassID
- func GatewayID(namespace, name string) gatewayID
- func HTTPRouteID(namespace, name string) httpRouteID
- func NamespaceID(namespaceName string) namespaceID
- func PolicyID(group, kind, namespace, name string) policyID
- func ReferenceGrantID(namespace, name string) referenceGrantID
- type BackendNode
- type Discoverer
- func (d Discoverer) DiscoverResourcesForBackend(filter Filter) (*ResourceModel, error)
- func (d Discoverer) DiscoverResourcesForGateway(filter Filter) (*ResourceModel, error)
- func (d Discoverer) DiscoverResourcesForGatewayClass(filter Filter) (*ResourceModel, error)
- func (d Discoverer) DiscoverResourcesForHTTPRoute(filter Filter) (*ResourceModel, error)
- func (d Discoverer) DiscoverResourcesForNamespace(filter Filter) (*ResourceModel, error)
- type Filter
- type GatewayClassNode
- type GatewayNode
- type HTTPRouteNode
- type NamespaceNode
- type PolicyNode
- type ReferenceFromTo
- type ReferenceGrantNode
- type ReferenceNotPermittedError
- type ReferenceToNonExistentResourceError
- type ResourceModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BackendID ¶
func BackendID(group, kind, namespace, name string) backendID
BackendID returns an ID for a Backend.
func BackendIDForService ¶
func BackendIDForService(namespace, name string) backendID
BackendIDForService returns an ID for a Backend which contains an underlying Service type.
func ConvertPoliciesMapToPolicyRefs ¶
func ConvertPoliciesMapToPolicyRefs(policies map[policyID]*PolicyNode) []policymanager.ObjRef
ConvertPoliciesMapToPolicyRefs returns the Object references of all given policies. Note that these are not the value of targetRef within the Policies but rather the reference to the Policy object itself.
func GatewayClassID ¶
func GatewayClassID(gatewayClassName string) gatewayClassID
GatewayClassID returns an ID for a GatewayClass.
func GatewayID ¶
func GatewayID(namespace, name string) gatewayID
GatewayID returns an ID for a Gateway.
func HTTPRouteID ¶
func HTTPRouteID(namespace, name string) httpRouteID
HTTPRouteID returns an ID for a HTTPRoute.
func NamespaceID ¶
func NamespaceID(namespaceName string) namespaceID
NamespaceID returns an ID for a Namespace.
func PolicyID ¶
func PolicyID(group, kind, namespace, name string) policyID
PolicyID returns an ID for a Policy.
func ReferenceGrantID ¶
func ReferenceGrantID(namespace, name string) referenceGrantID
ReferenceGrantID returns an ID for a ReferenceGrant.
Types ¶
type BackendNode ¶
type BackendNode struct { // Backend references the actual Backend resource. Backend *unstructured.Unstructured // Namespace is the namespace of the Backend. Namespace *NamespaceNode // HTTPRoutes lists HTTPRoutes that reference this Backend as a target. HTTPRoutes map[httpRouteID]*HTTPRouteNode // Policies stores Policies directly applied to the Backend. Policies map[policyID]*PolicyNode // ReferenceGrants contains ReferenceGrants that expose this Backend. ReferenceGrants map[referenceGrantID]*ReferenceGrantNode // EffectivePolicies reflects the effective policies applicable to this // Backend, mapped per Gateway for context-specific enforcement. EffectivePolicies map[gatewayID]map[policymanager.PolicyCrdID]policymanager.Policy // Errors contains any errorrs associated with this resource. Errors []error }
BackendNode models the relationships and dependencies of a Backend resource, representing the ultimate destination for traffic directed by HTTPRoutes. It serves as a generic abstraction, encompassing various underlying resource types that can act as traffic targets, such as Services, ServiceImports, etc.
func NewBackendNode ¶
func NewBackendNode(backend *unstructured.Unstructured) *BackendNode
func (BackendNode) ClientObject ¶
func (b BackendNode) ClientObject() client.Object
func (*BackendNode) ID ¶
func (b *BackendNode) ID() backendID
type Discoverer ¶
type Discoverer struct { K8sClients *common.K8sClients PolicyManager *policymanager.PolicyManager // The API versions to be used when fetching Gateway API related resources. An // attempt will be made to discover this information from the discovery APIs. // Failure to do so will mean we use the "default" versions defined in this // file. PreferredGatewayClassGroupVersion metav1.GroupVersion PreferredGatewayGroupVersion metav1.GroupVersion PreferredHTTPRouteGroupVersion metav1.GroupVersion PreferredReferenceGrantGroupVersion metav1.GroupVersion }
Discoverer orchestrates the discovery of resources and their associated policies, building a model of interconnected resources.
TODO: Optimization Task: Implement a heuristic within each discovery function to intelligently choose between:
- Single API calls for efficient bulk fetching when appropriate.
- Multiple API calls for targeted retrieval when necessary.
func NewDiscoverer ¶
func NewDiscoverer(k8sClients *common.K8sClients, policyManager *policymanager.PolicyManager) Discoverer
func (Discoverer) DiscoverResourcesForBackend ¶
func (d Discoverer) DiscoverResourcesForBackend(filter Filter) (*ResourceModel, error)
DiscoverResourcesForBackend discovers resources related to a Backend.
func (Discoverer) DiscoverResourcesForGateway ¶
func (d Discoverer) DiscoverResourcesForGateway(filter Filter) (*ResourceModel, error)
DiscoverResourcesForGateway discovers resources related to a Gateway.
func (Discoverer) DiscoverResourcesForGatewayClass ¶
func (d Discoverer) DiscoverResourcesForGatewayClass(filter Filter) (*ResourceModel, error)
DiscoverResourcesForGatewayClass discovers resources related to a GatewayClass.
func (Discoverer) DiscoverResourcesForHTTPRoute ¶
func (d Discoverer) DiscoverResourcesForHTTPRoute(filter Filter) (*ResourceModel, error)
DiscoverResourcesForHTTPRoute discovers resources related to an HTTPRoute.
func (Discoverer) DiscoverResourcesForNamespace ¶
func (d Discoverer) DiscoverResourcesForNamespace(filter Filter) (*ResourceModel, error)
DiscoverResourcesForNamespace discovers resources related to a Namespace.
type GatewayClassNode ¶
type GatewayClassNode struct { // GatewayClass references the actual GatewayClass resource. GatewayClass *gatewayv1.GatewayClass // Gateways tracks Gateways that are configured to use this GatewayClass. Gateways map[gatewayID]*GatewayNode // Policies stores Policies that directly apply to this GatewayClass. Policies map[policyID]*PolicyNode }
GatewayClassNode models the relationships and dependencies of a GatewayClass resource.
func NewGatewayClassNode ¶
func NewGatewayClassNode(gatewayClass *gatewayv1.GatewayClass) *GatewayClassNode
func (GatewayClassNode) ClientObject ¶
func (g GatewayClassNode) ClientObject() client.Object
func (*GatewayClassNode) ID ¶
func (g *GatewayClassNode) ID() gatewayClassID
type GatewayNode ¶
type GatewayNode struct { // Gateway references the actual Gateway resource. Gateway *gatewayv1.Gateway // Namespace is the namespace of the Gateway. Namespace *NamespaceNode // GatewayClass tracks the GatewayClass for this Gateway. GatewayClass *GatewayClassNode // HTTPRoutes stores HTTPRoutes attached to this Gateway. HTTPRoutes map[httpRouteID]*HTTPRouteNode // Policies stores Policies directly applied to the Gateway. Policies map[policyID]*PolicyNode // EffectivePolicies reflects the effective policies applicable to this Gateway, // considering inheritance and hierarchy. EffectivePolicies map[policymanager.PolicyCrdID]policymanager.Policy // Events contains the events associated with this Gateway. Events []corev1.Event // Errors contains any errorrs associated with this resource. Errors []error }
GatewayNode models the relationships and dependencies of a Gateway resource.
func NewGatewayNode ¶
func NewGatewayNode(gateway *gatewayv1.Gateway) *GatewayNode
func (GatewayNode) ClientObject ¶
func (g GatewayNode) ClientObject() client.Object
func (*GatewayNode) ID ¶
func (g *GatewayNode) ID() gatewayID
type HTTPRouteNode ¶
type HTTPRouteNode struct { // HTTPRoute references the actual HTTPRoute resource. HTTPRoute *gatewayv1.HTTPRoute // Namespace is the namespace of the HTTPRoute. Namespace *NamespaceNode // Gateways stores Gateways whhich this HTTPRoute is attached to. Gateways map[gatewayID]*GatewayNode // Backends lists Backends serving as target endpoints for traffic through // this route. Backends map[backendID]*BackendNode // Policies stores Policies directly applied to the HTTPRoute. Policies map[policyID]*PolicyNode // EffectivePolicies reflects the effective policies applicable to this // HTTPRoute, mapped per Gateway for context-specific enforcement. EffectivePolicies map[gatewayID]map[policymanager.PolicyCrdID]policymanager.Policy // Errors contains any errorrs associated with this resource. Errors []error }
HTTPRouteNode models the relationships and dependencies of an HTTPRoute resource.
func NewHTTPRouteNode ¶
func NewHTTPRouteNode(httpRoute *gatewayv1.HTTPRoute) *HTTPRouteNode
func (HTTPRouteNode) ClientObject ¶
func (h HTTPRouteNode) ClientObject() client.Object
func (*HTTPRouteNode) ID ¶
func (h *HTTPRouteNode) ID() httpRouteID
type NamespaceNode ¶
type NamespaceNode struct { // NamespaceName identifies the Namespace. Namespace *corev1.Namespace // Gateways lists Gateways deployed within the Namespace. Gateways map[gatewayID]*GatewayNode // HTTPRoutes lists HTTPRoutes configured within the Namespace. HTTPRoutes map[httpRouteID]*HTTPRouteNode // Backends lists Backends residing within the Namespace. Backends map[backendID]*BackendNode // Policies stores Policies directly applied to the Namespace. Policies map[policyID]*PolicyNode }
NamespaceNode models the relationships and dependencies of a Namespace.
func NewNamespaceNode ¶
func NewNamespaceNode(namespace corev1.Namespace) *NamespaceNode
func (*NamespaceNode) ClientObject ¶
func (n *NamespaceNode) ClientObject() client.Object
func (*NamespaceNode) ID ¶
func (n *NamespaceNode) ID() namespaceID
type PolicyNode ¶
type PolicyNode struct { // Policy references the actual Policy resource. Policy *policymanager.Policy // Namespace references the Namespace to which the policy is directly // attached. It's nil if the policy is not associated with a specific // namespace. Namespace *NamespaceNode // GatewayClass references the GatewayClassNode to which the policy is // directly attached. It's nil if the policy is not associated with a specific // GatewayClass. GatewayClass *GatewayClassNode // Gateway references the GatewayNode to which the policy is directly // attached. It's nil if the policy is not associated with a specific Gateway. Gateway *GatewayNode // HTTPRoute references the HTTPRouteNode to which the policy is directly // attached. It's nil if the policy is not associated with a specific // HTTPRoute. HTTPRoute *HTTPRouteNode // Backend references the BackendNode to which the policy is directly // attached. It's nil if the policy is not associated with a specific Backend. Backend *BackendNode }
PolicyNode models the relationships and dependencies of a Policy resource
func NewPolicyNode ¶
func NewPolicyNode(policy *policymanager.Policy) *PolicyNode
func (PolicyNode) ClientObject ¶
func (p PolicyNode) ClientObject() client.Object
func (*PolicyNode) ID ¶
func (p *PolicyNode) ID() policyID
type ReferenceFromTo ¶
type ReferenceGrantNode ¶
type ReferenceGrantNode struct { // ReferenceGrantName identifies the ReferenceGrant. ReferenceGrant *gatewayv1beta1.ReferenceGrant // Backends lists Backends residing within the ReferenceGrant. Backends map[backendID]*BackendNode }
ReferenceGrantNode models the relationships and dependencies of a ReferenceGrant.
func NewReferenceGrantNode ¶
func NewReferenceGrantNode(referenceGrant *gatewayv1beta1.ReferenceGrant) *ReferenceGrantNode
func (*ReferenceGrantNode) ID ¶
func (r *ReferenceGrantNode) ID() referenceGrantID
type ReferenceNotPermittedError ¶
type ReferenceNotPermittedError struct {
ReferenceFromTo
}
func (ReferenceNotPermittedError) Error ¶
func (r ReferenceNotPermittedError) Error() string
type ReferenceToNonExistentResourceError ¶
type ReferenceToNonExistentResourceError struct {
ReferenceFromTo
}
func (ReferenceToNonExistentResourceError) Error ¶
func (r ReferenceToNonExistentResourceError) Error() string
type ResourceModel ¶
type ResourceModel struct { GatewayClasses map[gatewayClassID]*GatewayClassNode Namespaces map[namespaceID]*NamespaceNode Gateways map[gatewayID]*GatewayNode HTTPRoutes map[httpRouteID]*HTTPRouteNode Backends map[backendID]*BackendNode ReferenceGrants map[referenceGrantID]*ReferenceGrantNode Policies map[policyID]*PolicyNode }
ResourceModel represents the graph-like model of Gateway API resources and their relationships, capturing dependencies and interactions. It acts as a central data structure for organizing and managing these resources, enabling operations like:
- Discovering and understanding the relationships between different resources
- Calculating effective policies based on hierarchical inheritance
- Identifying potential conflicts or issues in resource configuration
- Visualizing the topology of Gateway API resources