Skip to content

Commit

Permalink
replace remaining controllers with informers
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <stephen.kriss@gmail.com>
  • Loading branch information
skriss committed Jan 30, 2024
1 parent f182e73 commit 9d066b2
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 812 deletions.
5 changes: 0 additions & 5 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ outpkg: "mocks"
dir: '{{trimPrefix .PackagePath "github.com/projectcontour/contour/" }}/mocks'
disable-version-string: True
packages:
sigs.k8s.io/controller-runtime/pkg/manager:
config:
dir: "internal/controller/mocks"
interfaces:
Manager:
github.com/projectcontour/contour/internal/debug:
interfaces:
DagBuilder:
Expand Down
56 changes: 27 additions & 29 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
controller_runtime_metrics "sigs.k8s.io/controller-runtime/pkg/metrics"
controller_runtime_metrics_server "sigs.k8s.io/controller-runtime/pkg/metrics/server"
gatewayapi_v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayapi_v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

contour_api_v1 "github.com/projectcontour/contour/apis/projectcontour/v1"
contour_api_v1alpha1 "github.com/projectcontour/contour/apis/projectcontour/v1alpha1"
"github.com/projectcontour/contour/internal/annotation"
"github.com/projectcontour/contour/internal/contour"
"github.com/projectcontour/contour/internal/contourconfig"
"github.com/projectcontour/contour/internal/controller"
"github.com/projectcontour/contour/internal/dag"
"github.com/projectcontour/contour/internal/debug"
envoy_v3 "github.com/projectcontour/contour/internal/envoy/v3"
Expand Down Expand Up @@ -619,7 +619,7 @@ func (s *Server) doServe() error {
}

// Inform on Gateway API resources.
needsNotification := s.setupGatewayAPI(contourConfiguration, s.mgr, eventHandler)
needsNotification := s.setupGatewayAPI(contourConfiguration, eventHandler)

Check warning on line 622 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L622

Added line #L622 was not covered by tests

// Inform on secrets, filtering by root namespaces.
var handler cache.ResourceEventHandler = eventHandler
Expand Down Expand Up @@ -992,9 +992,7 @@ func (s *Server) setupHealth(healthConfig contour_api_v1alpha1.HealthConfig,
return nil
}

func (s *Server) setupGatewayAPI(contourConfiguration contour_api_v1alpha1.ContourConfigurationSpec,
mgr manager.Manager, eventHandler *contour.EventRecorder,
) []leadership.NeedLeaderElectionNotification {
func (s *Server) setupGatewayAPI(contourConfiguration contour_api_v1alpha1.ContourConfigurationSpec, eventHandler *contour.EventRecorder) []leadership.NeedLeaderElectionNotification {

Check warning on line 995 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L995

Added line #L995 was not covered by tests
needLeadershipNotification := []leadership.NeedLeaderElectionNotification{}

// Check if GatewayAPI is configured.
Expand All @@ -1009,6 +1007,21 @@ func (s *Server) setupGatewayAPI(contourConfiguration contour_api_v1alpha1.Conto
s.log.WithError(err).WithField("resource", "gateways").Fatal("failed to create informer")
}

Check warning on line 1008 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1006-L1008

Added lines #L1006 - L1008 were not covered by tests

// Inform on HTTPRoutes.
if err := s.informOnResource(&gatewayapi_v1beta1.HTTPRoute{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "httproutes").Fatal("failed to create informer")
}

Check warning on line 1013 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1011-L1013

Added lines #L1011 - L1013 were not covered by tests

// Inform on ReferenceGrants.
if err := s.informOnResource(&gatewayapi_v1beta1.ReferenceGrant{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "referencegrants").Fatal("failed to create informer")
}

Check warning on line 1018 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1016-L1018

Added lines #L1016 - L1018 were not covered by tests

// Inform on Namespaces.
if err := s.informOnResource(&corev1.Namespace{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "namespaces").Fatal("failed to create informer")

Check warning on line 1022 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1021-L1022

Added lines #L1021 - L1022 were not covered by tests
}

// Some features may be disabled.
features := map[string]struct{}{
"tlsroutes": {},
Expand All @@ -1019,41 +1032,26 @@ func (s *Server) setupGatewayAPI(contourConfiguration contour_api_v1alpha1.Conto
delete(features, f)
}

// Create and register the HTTPRoute controller with the manager.
if err := controller.RegisterHTTPRouteController(s.log.WithField("context", "httproute-controller"), mgr, eventHandler); err != nil {
s.log.WithError(err).Fatal("failed to create httproute-controller")
}

// Create and register the TLSRoute controller with the manager, if enabled.
// Inform on TLSRoutes, if enabled.
if _, enabled := features["tlsroutes"]; enabled {
if err := controller.RegisterTLSRouteController(s.log.WithField("context", "tlsroute-controller"), mgr, eventHandler); err != nil {
s.log.WithError(err).Fatal("failed to create tlsroute-controller")
if err := s.informOnResource(&gatewayapi_v1alpha2.TLSRoute{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "tlsroutes").Fatal("failed to create informer")

Check warning on line 1038 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1037-L1038

Added lines #L1037 - L1038 were not covered by tests
}
}

// Create and register the GRPCRoute controller with the manager, if enabled.
// Inform on GRPCRoutes, if enabled.
if _, enabled := features["grpcroutes"]; enabled {
if err := controller.RegisterGRPCRouteController(s.log.WithField("context", "grpcroute-controller"), mgr, eventHandler); err != nil {
s.log.WithError(err).Fatal("failed to create grpcroute-controller")
if err := s.informOnResource(&gatewayapi_v1alpha2.GRPCRoute{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "grpcroutes").Fatal("failed to create informer")

Check warning on line 1045 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1044-L1045

Added lines #L1044 - L1045 were not covered by tests
}
}

// Create and register the TCPRoute controller with the manager.
// Inform on TCPRoutes, if enabled.
if _, enabled := features["tcproutes"]; enabled {
if err := controller.RegisterTCPRouteController(s.log.WithField("context", "tcproute-controller"), mgr, eventHandler); err != nil {
s.log.WithError(err).Fatal("failed to create tcproute-controller")
if err := s.informOnResource(&gatewayapi_v1alpha2.TCPRoute{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "tcproutes").Fatal("failed to create informer")

Check warning on line 1052 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L1051-L1052

Added lines #L1051 - L1052 were not covered by tests
}
}

// Inform on ReferenceGrants.
if err := s.informOnResource(&gatewayapi_v1beta1.ReferenceGrant{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "referencegrants").Fatal("failed to create informer")
}

// Inform on Namespaces.
if err := s.informOnResource(&corev1.Namespace{}, eventHandler); err != nil {
s.log.WithError(err).WithField("resource", "namespaces").Fatal("failed to create informer")
}
}
return needLeadershipNotification
}
Expand Down
30 changes: 0 additions & 30 deletions internal/controller/controller.go

This file was deleted.

65 changes: 0 additions & 65 deletions internal/controller/controller_test.go

This file was deleted.

76 changes: 0 additions & 76 deletions internal/controller/grpcroute.go

This file was deleted.

76 changes: 0 additions & 76 deletions internal/controller/httproute.go

This file was deleted.

Loading

0 comments on commit 9d066b2

Please sign in to comment.