Skip to content

[Feature] Extract GRPC Server #1590

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

Merged
merged 5 commits into from
Feb 8, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) Extract GRPC Server

## [1.2.37](https://github.com/arangodb/kube-arangodb/tree/1.2.37) (2024-01-22)
- (Documentation) Improve documentation rendering for GitHub Pages
Expand Down
6 changes: 3 additions & 3 deletions cmd/admin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -192,7 +192,7 @@ func getDeploymentAndCredentials(ctx context.Context,

client, ok := kclient.GetDefaultFactory().Client()
if !ok {
err = errors.Newf("Client not initialised")
err = errors.Errorf("Client not initialised")
return
}

Expand Down Expand Up @@ -337,7 +337,7 @@ func getCACertificate(ctx context.Context, secrets secretv1.ReadInterface, name
func getDeployment(ctx context.Context, namespace, deplName string) (api.ArangoDeployment, error) {
client, ok := kclient.GetDefaultFactory().Client()
if !ok {
return api.ArangoDeployment{}, errors.Newf("Client not initialised")
return api.ArangoDeployment{}, errors.Errorf("Client not initialised")
}

extCli := client.Arango()
Expand Down
7 changes: 3 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
Expand All @@ -59,7 +58,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/server"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
utilsError "github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
Expand Down Expand Up @@ -437,7 +436,7 @@ func executeMain(cmd *cobra.Command, args []string) {
if err != nil {
logger.Err(err).Fatal("Failed to create API server")
}
go utilsError.LogError(logger, "while running API server", apiServer.Run)
go errors.LogError(logger, "while running API server", apiServer.Run)
}

listenAddr := net.JoinHostPort(serverOptions.host, strconv.Itoa(serverOptions.port))
Expand Down Expand Up @@ -486,7 +485,7 @@ func executeMain(cmd *cobra.Command, args []string) {
}); err != nil {
logger.Err(err).Fatal("Failed to create HTTP server")
} else {
go utilsError.LogError(logger, "error while starting server", svr.Run)
go errors.LogError(logger, "error while starting server", svr.Run)
}

// startChaos(context.Background(), cfg.KubeCli, cfg.Namespace, chaosLevel)
Expand Down
4 changes: 2 additions & 2 deletions cmd/crd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -28,11 +28,11 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/arangodb/kube-arangodb/pkg/crd"
"github.com/arangodb/kube-arangodb/pkg/crd/crds"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/init_container_version_check.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -24,9 +24,10 @@ import (
"encoding/json"
"os"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

const cmdVersionCheckInitContainersInvalidVersionExitCode = 11
Expand Down
4 changes: 2 additions & 2 deletions cmd/lifecycle_probes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,6 @@ import (
"path"
"strconv"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

Expand All @@ -45,6 +44,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cmd/lifecycle_startup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -21,14 +21,14 @@
package cmd

import (
"errors"
"fmt"
"net/http"
"time"

"github.com/spf13/cobra"

shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

var cmdLifecycleStartup = &cobra.Command{
Expand Down
23 changes: 11 additions & 12 deletions cmd/ml_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import (

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"google.golang.org/grpc"

pbShutdown "github.com/arangodb/kube-arangodb/pkg/api/shutdown/v1"
"github.com/arangodb/kube-arangodb/pkg/ml/storage"
"github.com/arangodb/kube-arangodb/pkg/util/probe"
"github.com/arangodb/kube-arangodb/pkg/util/shutdown"
"github.com/arangodb/kube-arangodb/pkg/util/svc"
)
Expand All @@ -53,7 +50,7 @@ var (
}

cmdMLStorageControllerOptions struct {
svc.GRPCConfig
Configuration svc.Configuration
}
)

Expand All @@ -62,8 +59,8 @@ func init() {
cmdMLStorage.AddCommand(cmdMLStorageS3)

f := cmdMLStorageS3.PersistentFlags()
f.StringVar(&cmdMLStorageControllerOptions.ListenAddress, "controller.address", "", "Address the GRPC controller service will listen on (IP:port)")
f.StringVar(&cmdMLStorageS3Options.ListenAddress, "server.address", "", "Address the GRPC service will listen on (IP:port)")
f.StringVar(&cmdMLStorageControllerOptions.Configuration.Address, "controller.address", "", "Address the GRPC controller service will listen on (IP:port)")
f.StringVar(&cmdMLStorageS3Options.Configuration.Address, "server.address", "", "Address the GRPC service will listen on (IP:port)")

f.StringVar(&cmdMLStorageS3Options.S3.Endpoint, "s3.endpoint", "", "Endpoint of S3 API implementation")
f.StringVar(&cmdMLStorageS3Options.S3.CACrtFile, "s3.ca-crt", "", "Path to file containing CA certificate to validate endpoint connection")
Expand All @@ -84,16 +81,18 @@ func cmdMLStorageS3Run(cmd *cobra.Command, _ []string) {
}

func cmdMLStorageS3RunE(_ *cobra.Command) error {
health := svc.NewHealthService(cmdMLStorageControllerOptions.Configuration, svc.Readiness, shutdown.NewGlobalShutdownServer())

health.Start(shutdown.Context())

storageService, err := storage.NewService(shutdown.Context(), storage.StorageTypeS3Proxy, cmdMLStorageS3Options.ServiceConfig)
if err != nil {
return err
}

healthService := probe.NewHealthService()
svc := svc.NewService(cmdMLStorageS3Options.Configuration, storageService)

svcRun := svc.StartWithHealth(shutdown.Context(), health)

controllerService := svc.NewGRPC(cmdMLStorageControllerOptions.GRPCConfig, func(server *grpc.Server) {
pbShutdown.RegisterShutdownServer(server, shutdown.NewShutdownableShutdownServer())
healthService.Register(server)
})
return svc.RunServices(shutdown.Context(), healthService, storageService, controllerService)
return svcRun.Wait()
}
5 changes: 3 additions & 2 deletions cmd/uuid.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,9 +25,10 @@ import (
"os"
"strings"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

type cmdUUIDInputStruct struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/md/sections.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,7 +78,7 @@ func ReplaceSection(in, replace, section string) (string, error) {

endID := strings.Index(in, end)
if endID == -1 {
return "", errors.Newf("END_INJECT sections is missing for section %s. Note that newline is required at the end and before tag", section)
return "", errors.Errorf("END_INJECT sections is missing for section %s. Note that newline is required at the end and before tag", section)
}

if strings.HasSuffix(replace, "\n\n") {
Expand Down
4 changes: 2 additions & 2 deletions internal/md/table.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ func (t *table) AddRow(in map[Column]string) error {

for k, v := range in {
if _, ok := t.columns.Get(k.ID()); !ok {
return errors.Newf("Column not found")
return errors.Errorf("Column not found")
}

r[k.ID()] = v
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/tls.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pkg/apis/apps/v1/job_validate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,11 +32,11 @@ func (a *ArangoJob) Validate() error {

func (a *ArangoJobSpec) Validate() error {
if a.ArangoDeploymentName == "" {
return errors.Newf("deployment name can not be empty")
return errors.Errorf("deployment name can not be empty")
}

if a.JobTemplate == nil {
return errors.Newf("jobTemplate name can not be empty")
return errors.Errorf("jobTemplate name can not be empty")
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/backup/v1/backup_policy_validate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,9 +38,9 @@ func (a *ArangoBackupPolicy) Validate() error {

func (a *ArangoBackupPolicySpec) Validate() error {
if expr, err := cron.ParseStandard(a.Schedule); err != nil {
return errors.Newf("error while parsing expr: %s", err.Error())
return errors.Errorf("error while parsing expr: %s", err.Error())
} else if expr.Next(time.Now()).IsZero() {
return errors.Newf("invalid schedule format")
return errors.Errorf("invalid schedule format")
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/backup/v1/backup_validate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@ func (a *ArangoBackup) Validate() error {

func (a *ArangoBackupSpec) Validate() error {
if a.Deployment.Name == "" {
return errors.Newf("deployment name can not be empty")
return errors.Errorf("deployment name can not be empty")
}

if a.Download != nil {
Expand All @@ -58,15 +58,15 @@ func (a *ArangoBackupSpec) Validate() error {

func (a *ArangoBackupSpecOperation) Validate() error {
if a.RepositoryURL == "" {
return errors.Newf("RepositoryURL can not be empty")
return errors.Errorf("RepositoryURL can not be empty")
}

return nil
}

func (a *ArangoBackupSpecDownload) Validate() error {
if a.ID == "" {
return errors.Newf("ID can not be empty")
return errors.Errorf("ID can not be empty")
}

return a.ArangoBackupSpecOperation.Validate()
Expand Down
Loading