Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor grpc-server package #598

Merged
merged 1 commit into from
Apr 5, 2022

Conversation

micahhausler
Copy link
Contributor

@micahhausler micahhausler commented Mar 17, 2022

Description

  • Untangle certificate acquisition
  • Make gRPC server accept different registrable APIs
  • Move postgres setup logic out of tink-server's main.go to an internal package
  • Move gRPC server implementation to the new /server package
  • Remove unused global workflowData

Why is this needed

This will facilitate swapping out the current gRPC API implementation with an alternative in a successive PR.

Fixes: #

How Has This Been Tested?

I will have a secondary PR adding end-to-end tests

How are existing users impacted? What migration steps/scripts do we need?

Anyone importing or instantiating the grpcserver.SetupGRPC with grpserver.ConfigGRPCServer will need to use the new signature and pass in a grpcserver.Registrar such as server.DBServer.

Previously this looked like:

grpcConfig := &grpcServer.ConfigGRPCServer{
        Facility:      config.Facility,
        TLSCert:       "insecure",
        GRPCAuthority: listenAddr,
        DB:            tinkDB,
}
if config.TLS {
        grpcConfig.TLSCert = config.TLSCert
}
cert, modT := grpcServer.SetupGRPC(ctx, logger, grpcConfig, errCh)

And now, this looks like:

cert, certPEM, certModTime, err := grpcserver.GetCerts(certsDir)
grpcOpts := []grpc.ServerOption{grpc.Creds(credentials.NewServerTLSFromCert(cert))}
tinkAPI, err := server.NewDBServer(
        logger,
        tinkDB,
        server.WithCerts(*certModTime, certPEM),
)
_, err := grpcserver.SetupGRPC(
        ctx,
        tinkAPI,
        listenAddr,
        grpcOpts,
        errCh)

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@micahhausler micahhausler requested review from nshalman and mmlb March 17, 2022 22:36
@codecov
Copy link

codecov bot commented Mar 17, 2022

Codecov Report

Merging #598 (07886bc) into main (dbe434f) will increase coverage by 0.28%.
The diff coverage is 57.94%.

❗ Current head 07886bc differs from pull request most recent head dbf5c4b. Consider uploading reports for the commit dbf5c4b to get more accurate results

@@            Coverage Diff             @@
##             main     #598      +/-   ##
==========================================
+ Coverage   45.68%   45.96%   +0.28%     
==========================================
  Files          55       56       +1     
  Lines        3301     3283      -18     
==========================================
+ Hits         1508     1509       +1     
+ Misses       1707     1684      -23     
- Partials       86       90       +4     
Impacted Files Coverage Δ
server/dbserver.go 0.00% <0.00%> (ø)
server/dbserver_hardware.go 2.40% <0.00%> (ø)
server/dbserver_template.go 37.27% <40.00%> (ø)
server/dbserver_workflow.go 41.74% <50.00%> (ø)
grpc-server/grpc_server.go 75.60% <73.52%> (+39.12%) ⬆️
server/dbserver_worker_workflow.go 91.24% <96.96%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dbe434f...dbf5c4b. Read the comment docs.

// The public key is expected to be named "bundle.pem" and the private key
// "server.pem".
func GetCerts(certsDir string) (*tls.Certificate, []byte, *time.Time, error) {
certFile, err := os.Open(filepath.Join(certsDir, "bundle.pem"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

G304: Potential file inclusion via variable
(at-me in a reply with help or ignore)

@micahhausler micahhausler force-pushed the refactor/grpcserver branch 3 times, most recently from 669634c to dc23bb2 Compare March 18, 2022 16:15
Copy link
Member

@displague displague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

I left some comments that largely focused on implementing TinkServer as server/Server, server/NewServer (with options helper moving that way) since the grpc-server/ parentage seems unnecessary.

grpc-server/tinkerbell_server.go Outdated Show resolved Hide resolved
grpc-server/tinkerbell_server.go Outdated Show resolved Hide resolved
grpc-server/tinkerbell_server.go Outdated Show resolved Hide resolved
grpc-server/grpc_server_test.go Show resolved Hide resolved
grpc-server/grpc_server.go Show resolved Hide resolved
@micahhausler micahhausler force-pushed the refactor/grpcserver branch 3 times, most recently from c7afe78 to ae45cce Compare March 23, 2022 16:31
Comment on lines +174 to 191
addr, err := grpcserver.SetupGRPC(
ctx,
tinkAPI,
config.GRPCAuthority,
grpcOpts,
errCh)
if err != nil {
return err
}
cert, modT := grpcServer.SetupGRPC(ctx, logger, grpcConfig, errCh)
logger.With("address", addr).Info("started listener")

httpConfig := &httpServer.Config{
httpConfig := &httpserver.Config{
HTTPAuthority: config.HTTPAuthority,
CertPEM: cert,
ModTime: modT,
CertPEM: certPEM,
ModTime: *certModTime,
}
httpServer.SetupHTTP(ctx, logger, httpConfig, errCh)
httpserver.SetupHTTP(ctx, logger, httpConfig, errCh)

Copy link
Member

@chrisdoherty4 chrisdoherty4 Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could really benefit from using https://github.com/oklog/run. Unnecessary for this PR, but if you get time separately it would help clean up the subsequent error channel code that does static draining of the channel.

@micahhausler micahhausler force-pushed the refactor/grpcserver branch 3 times, most recently from 7f702d0 to 4a9e988 Compare March 24, 2022 21:49
displague
displague previously approved these changes Mar 28, 2022
thebsdbox
thebsdbox previously approved these changes Mar 30, 2022
* Untangle certificate acquisition
* Make gRPC server accept different registrable APIs
* Move postgres setup logic out of tink-server's main.go to
  an internal package
* Move gRPC server implementation to the new /server package
* Remove unused global workflowData

Signed-off-by: Micah Hausler <[email protected]>
@micahhausler micahhausler dismissed stale reviews from thebsdbox and displague via dbf5c4b April 4, 2022 22:44
@micahhausler micahhausler force-pushed the refactor/grpcserver branch from 4a9e988 to dbf5c4b Compare April 4, 2022 22:44
@displague displague merged commit d3512cb into tinkerbell:main Apr 5, 2022
@displague displague added the breaking-change Denotes a PR that introduces potentially breaking changes that require user action. label Apr 5, 2022
@displague displague added this to the 0.7.0 milestone Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Denotes a PR that introduces potentially breaking changes that require user action.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants