Skip to content
Open
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
8 changes: 7 additions & 1 deletion cmd/binoculars/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ func main() {
)
defer shutdownGateway()

shutdown, wg := binoculars.StartUp(&config)
shutdown, wg, err := binoculars.StartUp(&config)
if err != nil {
log.Errorf("Binoculars startup failed: %v", err)
shutdownGateway()
shutdownMetricServer()
os.Exit(1)
}
go func() {
<-stopSignal
shutdown()
Expand Down
18 changes: 7 additions & 11 deletions internal/binoculars/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package binoculars

import (
"os"
"fmt"
"sync"

"github.com/armadaproject/armada/internal/binoculars/configuration"
Expand All @@ -10,28 +10,22 @@ import (
"github.com/armadaproject/armada/internal/common/auth"
"github.com/armadaproject/armada/internal/common/cluster"
grpcCommon "github.com/armadaproject/armada/internal/common/grpc"
log "github.com/armadaproject/armada/internal/common/logging"
"github.com/armadaproject/armada/pkg/api/binoculars"
)

func StartUp(config *configuration.BinocularsConfig) (func(), *sync.WaitGroup) {
wg := &sync.WaitGroup{}
wg.Add(1)

func StartUp(config *configuration.BinocularsConfig) (func(), *sync.WaitGroup, error) {
kubernetesClientProvider, err := cluster.NewKubernetesClientProvider(
config.ImpersonateUsers,
config.Kubernetes.QPS,
config.Kubernetes.Burst,
)
if err != nil {
log.Errorf("Failed to connect to kubernetes because %s", err)
os.Exit(-1)
return nil, nil, fmt.Errorf("failed to connect to kubernetes: %w", err)
}

authServices, err := auth.ConfigureAuth(config.Auth)
if err != nil {
log.Errorf("Failed to create auth services %s", err)
os.Exit(-1)
return nil, nil, fmt.Errorf("failed to create auth services: %w", err)
}

grpcServer := grpcCommon.CreateGrpcServer(config.Grpc.KeepaliveParams, config.Grpc.KeepaliveEnforcementPolicy, authServices, config.Grpc.Tls)
Expand All @@ -47,7 +41,9 @@ func StartUp(config *configuration.BinocularsConfig) (func(), *sync.WaitGroup) {
binocularsServer := server.NewBinocularsServer(logService, cordonService)
binoculars.RegisterBinocularsServer(grpcServer, binocularsServer)

wg := &sync.WaitGroup{}
wg.Add(1)
grpcCommon.Listen(config.GrpcPort, grpcServer, wg)

return grpcServer.GracefulStop, wg
return grpcServer.GracefulStop, wg, nil
}