Skip to content

Commit

Permalink
EndpointSlice resources tracked by Graph (#1432)
Browse files Browse the repository at this point in the history
Problem: EndpointSlice resources are currently being tracked by the relationship capturer,
but to reduce the number of components we would like to track the resources in the Graph.

Solution: Enable Graph to track EndpointSlice resources and Services. In addition, this PR
refactors backend_refs to store the NamespacedName of a Service and a ServicePort instead
of the actual Service. This is done to track non-existing referenced services. Also, refactors
and removes the alwaysTruePredicate. Removes RelationshipCapturer.
  • Loading branch information
bjee19 authored Jan 24, 2024
1 parent 06d8a6b commit 73f7918
Show file tree
Hide file tree
Showing 23 changed files with 1,113 additions and 1,324 deletions.
8 changes: 3 additions & 5 deletions internal/mode/static/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/file"
ngxruntime "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/runtime"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/relationship"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/resolver"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/telemetry"
Expand Down Expand Up @@ -138,10 +137,9 @@ func StartManager(cfg config.Config) error {
}

processor := state.NewChangeProcessorImpl(state.ChangeProcessorConfig{
GatewayCtlrName: cfg.GatewayCtlrName,
GatewayClassName: cfg.GatewayClassName,
RelationshipCapturer: relationship.NewCapturerImpl(),
Logger: cfg.Logger.WithName("changeProcessor"),
GatewayCtlrName: cfg.GatewayCtlrName,
GatewayClassName: cfg.GatewayClassName,
Logger: cfg.Logger.WithName("changeProcessor"),
Validators: validation.Validators{
HTTPFieldsValidator: ngxvalidation.HTTPValidator{},
},
Expand Down
19 changes: 7 additions & 12 deletions internal/mode/static/state/change_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/nginxinc/nginx-gateway-fabric/internal/framework/gatewayclass"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/relationship"
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation"
)

Expand Down Expand Up @@ -55,8 +54,6 @@ type ChangeProcessor interface {

// ChangeProcessorConfig holds configuration parameters for ChangeProcessorImpl.
type ChangeProcessorConfig struct {
// RelationshipCapturer captures relationships between Kubernetes API resources and Gateway API resources.
RelationshipCapturer relationship.Capturer
// Validators validate resources according to data-plane specific rules.
Validators validation.Validators
// EventRecorder records events for Kubernetes resources.
Expand Down Expand Up @@ -114,34 +111,32 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
clusterState: clusterStore,
}

isReferenced := func(obj client.Object) bool {
nsname := types.NamespacedName{Name: obj.GetName(), Namespace: obj.GetNamespace()}
isReferenced := func(obj client.Object, nsname types.NamespacedName) bool {
return processor.latestGraph != nil && processor.latestGraph.IsReferenced(obj, nsname)
}

trackingUpdater := newChangeTrackingUpdater(
cfg.RelationshipCapturer,
extractGVK,
[]changeTrackingUpdaterObjectTypeCfg{
{
gvk: extractGVK(&v1.GatewayClass{}),
store: newObjectStoreMapAdapter(clusterStore.GatewayClasses),
predicate: alwaysProcess{},
predicate: nil,
},
{
gvk: extractGVK(&v1.Gateway{}),
store: newObjectStoreMapAdapter(clusterStore.Gateways),
predicate: alwaysProcess{},
predicate: nil,
},
{
gvk: extractGVK(&v1.HTTPRoute{}),
store: newObjectStoreMapAdapter(clusterStore.HTTPRoutes),
predicate: alwaysProcess{},
predicate: nil,
},
{
gvk: extractGVK(&v1beta1.ReferenceGrant{}),
store: newObjectStoreMapAdapter(clusterStore.ReferenceGrants),
predicate: alwaysProcess{},
predicate: nil,
},
{
gvk: extractGVK(&apiv1.Namespace{}),
Expand All @@ -151,12 +146,12 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
{
gvk: extractGVK(&apiv1.Service{}),
store: newObjectStoreMapAdapter(clusterStore.Services),
predicate: nil,
predicate: funcPredicate{stateChanged: isReferenced},
},
{
gvk: extractGVK(&discoveryV1.EndpointSlice{}),
store: nil,
predicate: nil,
predicate: funcPredicate{stateChanged: isReferenced},
},
{
gvk: extractGVK(&apiv1.Secret{}),
Expand Down
Loading

0 comments on commit 73f7918

Please sign in to comment.