From e0f4f6c1523dc2369caa353c154508987a8b755d Mon Sep 17 00:00:00 2001 From: Nathan Coleman Date: Wed, 25 Jan 2023 13:21:46 -0500 Subject: [PATCH] Run config entry controller routines on leader (#16054) --- agent/consul/leader_connect.go | 29 ++++++++++++++++++++++++++++- agent/consul/server.go | 1 + logging/names.go | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/agent/consul/leader_connect.go b/agent/consul/leader_connect.go index 79162603ac..42bdd4313b 100644 --- a/agent/consul/leader_connect.go +++ b/agent/consul/leader_connect.go @@ -5,11 +5,15 @@ import ( "fmt" "time" + "golang.org/x/sync/errgroup" + "golang.org/x/time/rate" + "github.com/hashicorp/go-version" + + "github.com/hashicorp/consul/agent/consul/gateways" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/logging" - "github.com/hashicorp/go-version" ) const ( @@ -51,6 +55,7 @@ func (s *Server) startConnectLeader(ctx context.Context) error { s.leaderRoutineManager.Start(ctx, caRootMetricRoutineName, rootCAExpiryMonitor(s).Monitor) s.leaderRoutineManager.Start(ctx, caSigningMetricRoutineName, signingCAExpiryMonitor(s).Monitor) s.leaderRoutineManager.Start(ctx, virtualIPCheckRoutineName, s.runVirtualIPVersionCheck) + s.leaderRoutineManager.Start(ctx, configEntryControllersRoutineName, s.runConfigEntryControllers) return s.startIntentionConfigEntryMigration(ctx) } @@ -63,6 +68,28 @@ func (s *Server) stopConnectLeader() { s.leaderRoutineManager.Stop(caRootMetricRoutineName) s.leaderRoutineManager.Stop(caSigningMetricRoutineName) s.leaderRoutineManager.Stop(virtualIPCheckRoutineName) + s.leaderRoutineManager.Stop(configEntryControllersRoutineName) +} + +func (s *Server) runConfigEntryControllers(ctx context.Context) error { + group, ctx := errgroup.WithContext(ctx) + + group.Go(func() error { + logger := s.logger.Named(logging.APIGatewayController) + return gateways.NewAPIGatewayController(s.fsm, s.publisher, logger).Run(ctx) + }) + + group.Go(func() error { + logger := s.logger.Named(logging.HTTPRouteController) + return gateways.NewHTTPRouteController(s.fsm, s.publisher, logger).Run(ctx) + }) + + group.Go(func() error { + logger := s.logger.Named(logging.TCPRouteController) + return gateways.NewTCPRouteController(s.fsm, s.publisher, logger).Run(ctx) + }) + + return group.Wait() } func (s *Server) runCARootPruning(ctx context.Context) error { diff --git a/agent/consul/server.go b/agent/consul/server.go index 89210f5f0c..a12038be5a 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -122,6 +122,7 @@ const ( caRootPruningRoutineName = "CA root pruning" caRootMetricRoutineName = "CA root expiration metric" caSigningMetricRoutineName = "CA signing expiration metric" + configEntryControllersRoutineName = "config entry controllers" configReplicationRoutineName = "config entry replication" federationStateReplicationRoutineName = "federation state replication" federationStateAntiEntropyRoutineName = "federation state anti-entropy" diff --git a/logging/names.go b/logging/names.go index 5d1f60c9bc..003bb3e86a 100644 --- a/logging/names.go +++ b/logging/names.go @@ -22,8 +22,10 @@ const ( Envoy string = "envoy" FederationState string = "federation_state" FSM string = "fsm" + APIGatewayController string = "api_gateway_controller" GatewayLocator string = "gateway_locator" HTTP string = "http" + HTTPRouteController string = "http_route_controller" IngressGateway string = "ingress_gateway" Intentions string = "intentions" Internal string = "internal" @@ -52,6 +54,7 @@ const ( Partition string = "partition" Peering string = "peering" PeeringMetrics string = "peering_metrics" + TCPRouteController string = "tcp_route_controller" TerminatingGateway string = "terminating_gateway" TLSUtil string = "tlsutil" Transaction string = "txn"