Skip to content

Commit

Permalink
Instantiate secure resource service client after the grpc server (#18712
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ishustava authored Sep 8, 2023
1 parent 9adb617 commit bbc2763
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,18 +817,20 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
s.reportingManager = reporting.NewReportingManager(s.logger, getEnterpriseReportingDeps(flat), s, s.fsm.State())
go s.reportingManager.Run(&lib.StopChannelContext{StopCh: s.shutdownCh})

// Setup resource service clients.
if err := s.setupSecureResourceServiceClient(); err != nil {
return nil, err
}

// Setup insecure resource service client.
if err := s.setupInsecureResourceServiceClient(flat.Registry, logger); err != nil {
return nil, err
}

// Initialize external gRPC server
s.setupExternalGRPC(config, flat, logger)

// Setup secure resource service client. We need to do it after we setup the
// gRPC server because it needs the server to be instantiated.
if err := s.setupSecureResourceServiceClient(); err != nil {
return nil, err
}

// Initialize internal gRPC server.
//
// Note: some "external" gRPC services are also exposed on the internal gRPC server
Expand Down Expand Up @@ -1400,6 +1402,10 @@ func (s *Server) setupExternalGRPC(config *Config, deps Deps, logger hclog.Logge
}

func (s *Server) setupInsecureResourceServiceClient(typeRegistry resource.Registry, logger hclog.Logger) error {
if s.raftStorageBackend == nil {
return fmt.Errorf("raft storage backend cannot be nil")
}

server := resourcegrpc.NewServer(resourcegrpc.Config{
Registry: typeRegistry,
Backend: s.raftStorageBackend,
Expand All @@ -1418,6 +1424,9 @@ func (s *Server) setupInsecureResourceServiceClient(typeRegistry resource.Regist
}

func (s *Server) setupSecureResourceServiceClient() error {
if s.resourceServiceServer == nil {
return fmt.Errorf("resource service server cannot be nil")
}
conn, err := s.runInProcessGRPCServer(s.resourceServiceServer.Register)
if err != nil {
return err
Expand Down

0 comments on commit bbc2763

Please sign in to comment.