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

coordinator: use errgroup in main #75

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions coordinator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/intercom"
"github.com/edgelesssys/nunki/internal/logger"
"golang.org/x/sync/errgroup"
)

func main() {
Expand All @@ -26,7 +27,7 @@ func run() (retErr error) {
}
defer func() {
if retErr != nil {
logger.Error(retErr.Error())
logger.Error("Coordinator terminated after failure", "err", retErr)
}
}()

Expand All @@ -46,17 +47,23 @@ func run() (retErr error) {
coordS := newCoordAPIServer(meshAuth, caInstance, logger)
intercomS := newIntercomServer(meshAuth, caInstance, logger)

go func() {
eg := errgroup.Group{}

eg.Go(func() error {
logger.Info("Coordinator API listening")
if err := coordS.Serve(net.JoinHostPort("0.0.0.0", coordapi.Port)); err != nil {
// TODO: collect error using errgroup.
logger.Error("Coordinator API failed to serve", "err", err)
return fmt.Errorf("serving Coordinator API: %w", err)
}
}()
return nil
})

logger.Info("Coordinator intercom listening")
if err := intercomS.Serve(net.JoinHostPort("0.0.0.0", intercom.Port)); err != nil {
return fmt.Errorf("serving intercom: %w", err)
}
return nil
eg.Go(func() error {
logger.Info("Coordinator intercom listening")
if err := intercomS.Serve(net.JoinHostPort("0.0.0.0", intercom.Port)); err != nil {
return fmt.Errorf("serving intercom API: %w", err)
}
return nil
})

return eg.Wait()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/stretchr/testify v1.8.4
go.uber.org/goleak v1.3.0
golang.org/x/crypto v0.18.0
golang.org/x/sync v0.4.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ verify:
rm -rf ./{{workspace_dir}}/verify
ns=$(cat ./{{workspace_dir}}/just.namespace)
nix run .#kubectl-wait-ready -- $ns coordinator
kubectl -n $ns port-forward pod/port-forwarder-coordinator 1313 &
kubectl -n $ns port-forward pod/port-forwarder-coordinator 1314:1313 &
PID=$!
trap "kill $PID" EXIT
sleep 1
t=$(date +%s)
nix run .#cli -- verify \
-c localhost:1313 \
-c localhost:1314 \
-o ./{{workspace_dir}}/verify
duration=$(( $(date +%s) - $t ))
echo "Verified in $duration seconds."
Expand Down
2 changes: 1 addition & 1 deletion packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rec {

src = goFiles;
proxyVendor = true;
vendorHash = "sha256-RySYZYCKOeBp0miqYMQKtc1TQ3NdYgfPj+/vBjhkFpI=";
vendorHash = "sha256-/2GzN6vzMm8NWJYcauR+eJuZAVEV5wi/Wdkbe3KhKOM=";

CGO_ENABLED = 0;
ldflags = [
Expand Down