Skip to content

Commit 597e9d7

Browse files
Restore ReadinessProbe for ML Storage sidecar, rename shutdown -> controller service
Also small clean-up of duplicate Ter function
1 parent e1d4e62 commit 597e9d7

File tree

8 files changed

+96
-48
lines changed

8 files changed

+96
-48
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Documentation) Use relative links for generated docs
1010
- (Improvement) Change default logging level to info. Add --log.sampling (default true). Adjust log levels.
1111
- (Maintenance) Bump Go to 1.21.6
12+
- (Feature) (ML) Restore ReadinessProbe for ML Storage sidecar
1213

1314
## [1.2.36](https://github.com/arangodb/kube-arangodb/tree/1.2.36) (2024-01-08)
1415
- (Documentation) Improvements and fixes for rendered documentation (GH pages)

cmd/ml_storage.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import (
2525

2626
"github.com/rs/zerolog/log"
2727
"github.com/spf13/cobra"
28+
"google.golang.org/grpc"
2829

30+
pbShutdown "github.com/arangodb/kube-arangodb/pkg/api/shutdown/v1"
2931
"github.com/arangodb/kube-arangodb/pkg/ml/storage"
32+
"github.com/arangodb/kube-arangodb/pkg/util/probe"
3033
"github.com/arangodb/kube-arangodb/pkg/util/shutdown"
3134
"github.com/arangodb/kube-arangodb/pkg/util/svc"
3235
)
@@ -49,8 +52,8 @@ var (
4952
storage.ServiceConfig
5053
}
5154

52-
cmdMLShutdownOptions struct {
53-
shutdown.ServiceConfig
55+
cmdMLStorageControllerOptions struct {
56+
svc.GRPCConfig
5457
}
5558
)
5659

@@ -59,7 +62,7 @@ func init() {
5962
cmdMLStorage.AddCommand(cmdMLStorageS3)
6063

6164
f := cmdMLStorageS3.PersistentFlags()
62-
f.StringVar(&cmdMLShutdownOptions.ListenAddress, "shutdown.address", "", "Address the GRPC shutdown service will listen on (IP:port)")
65+
f.StringVar(&cmdMLStorageControllerOptions.ListenAddress, "controller.address", "", "Address the GRPC controller service will listen on (IP:port)")
6366
f.StringVar(&cmdMLStorageS3Options.ListenAddress, "server.address", "", "Address the GRPC service will listen on (IP:port)")
6467

6568
f.StringVar(&cmdMLStorageS3Options.S3.Endpoint, "s3.endpoint", "", "Endpoint of S3 API implementation")
@@ -81,10 +84,16 @@ func cmdMLStorageS3Run(cmd *cobra.Command, _ []string) {
8184
}
8285

8386
func cmdMLStorageS3RunE(_ *cobra.Command) error {
84-
service, err := storage.NewService(shutdown.Context(), storage.StorageTypeS3Proxy, cmdMLStorageS3Options.ServiceConfig)
87+
storageService, err := storage.NewService(shutdown.Context(), storage.StorageTypeS3Proxy, cmdMLStorageS3Options.ServiceConfig)
8588
if err != nil {
8689
return err
8790
}
8891

89-
return svc.RunServices(shutdown.Context(), service, shutdown.ServiceCentral(cmdMLShutdownOptions.ServiceConfig))
92+
healthService := probe.NewHealthService()
93+
94+
controllerService := svc.NewGRPC(cmdMLStorageControllerOptions.GRPCConfig, func(server *grpc.Server) {
95+
pbShutdown.RegisterShutdownServer(server, shutdown.NewShutdownableShutdownServer())
96+
healthService.Register(server)
97+
})
98+
return svc.RunServices(shutdown.Context(), healthService, storageService, controllerService)
9099
}

pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type ArangoMLStorageSpecModeSidecar struct {
3131
// +doc/default: 9201
3232
ListenPort *uint16 `json:"listenPort,omitempty"`
3333

34-
// ShutdownListenPort defines on which port the sidecar container will be listening for shutdown connections
34+
// ControllerListenPort defines on which port the sidecar container will be listening for controller requests
3535
// +doc/default: 9202
36-
ShutdownListenPort *uint16 `json:"shutdownListenPort,omitempty"`
36+
ControllerListenPort *uint16 `json:"controllerListenPort,omitempty"`
3737

3838
// ContainerTemplate Keeps the information about Container configuration
3939
*sharedApi.ContainerTemplate `json:",inline"`
@@ -58,8 +58,8 @@ func (s *ArangoMLStorageSpecModeSidecar) Validate() error {
5858
err = append(err, shared.PrefixResourceErrors("listenPort", errors.Newf("must be positive")))
5959
}
6060

61-
if s.GetShutdownListenPort() < 1 {
62-
err = append(err, shared.PrefixResourceErrors("shutdownListenPort", errors.Newf("must be positive")))
61+
if s.GetControllerListenPort() < 1 {
62+
err = append(err, shared.PrefixResourceErrors("controllerListenPort", errors.Newf("must be positive")))
6363
}
6464

6565
err = append(err, s.GetContainerTemplate().Validate())
@@ -74,9 +74,9 @@ func (s *ArangoMLStorageSpecModeSidecar) GetListenPort() uint16 {
7474
return *s.ListenPort
7575
}
7676

77-
func (s *ArangoMLStorageSpecModeSidecar) GetShutdownListenPort() uint16 {
78-
if s == nil || s.ShutdownListenPort == nil {
77+
func (s *ArangoMLStorageSpecModeSidecar) GetControllerListenPort() uint16 {
78+
if s == nil || s.ControllerListenPort == nil {
7979
return 9202
8080
}
81-
return *s.ShutdownListenPort
81+
return *s.ControllerListenPort
8282
}

pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/util/probe/grpc.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package probe
22+
23+
import (
24+
"google.golang.org/grpc"
25+
"google.golang.org/grpc/health"
26+
pbHealth "google.golang.org/grpc/health/grpc_health_v1"
27+
)
28+
29+
type HealthService interface {
30+
Register(server *grpc.Server)
31+
SetServing()
32+
Shutdown()
33+
}
34+
35+
func NewHealthService() HealthService {
36+
return &grpcHealthService{
37+
hs: health.NewServer(),
38+
}
39+
}
40+
41+
type grpcHealthService struct {
42+
hs *health.Server
43+
}
44+
45+
func (s *grpcHealthService) Register(server *grpc.Server) {
46+
pbHealth.RegisterHealthServer(server, s.hs)
47+
}
48+
49+
// SetServing marks the health response as Serving for all services
50+
func (s *grpcHealthService) SetServing() {
51+
s.hs.SetServingStatus("", pbHealth.HealthCheckResponse_SERVING)
52+
}
53+
54+
// Shutdown marks as not serving and forbids further changes in health status
55+
func (s *grpcHealthService) Shutdown() {
56+
s.hs.Shutdown()
57+
}

pkg/util/shutdown/grpc.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,12 @@ import (
2424
"context"
2525
"time"
2626

27-
"google.golang.org/grpc"
28-
2927
"github.com/arangodb/kube-arangodb/pkg/api/server"
3028
pbShutdown "github.com/arangodb/kube-arangodb/pkg/api/shutdown/v1"
3129
)
3230

33-
func RegisterCentral(pb grpc.ServiceRegistrar) {
34-
pbShutdown.RegisterShutdownServer(pb, NewShutdownableShutdownCentralServer())
35-
}
36-
37-
func Register(pb grpc.ServiceRegistrar, closer context.CancelFunc) {
38-
pbShutdown.RegisterShutdownServer(pb, NewShutdownableShutdownServer(closer))
39-
}
40-
41-
func NewShutdownableShutdownCentralServer() ShutdownableShutdownServer {
42-
return NewShutdownableShutdownServer(stop)
43-
}
44-
45-
func NewShutdownableShutdownServer(closer context.CancelFunc) ShutdownableShutdownServer {
46-
return &impl{closer: closer}
31+
func NewShutdownableShutdownServer() ShutdownableShutdownServer {
32+
return &impl{closer: stop}
4733
}
4834

4935
type ShutdownableShutdownServer interface {

pkg/util/shutdown/server.go renamed to pkg/util/svc/grpc.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,27 @@
1818
// Copyright holder is ArangoDB GmbH, Cologne, Germany
1919
//
2020

21-
package shutdown
21+
package svc
2222

2323
import (
2424
"context"
2525
"net"
2626

2727
"google.golang.org/grpc"
28-
29-
"github.com/arangodb/kube-arangodb/pkg/util/svc"
3028
)
3129

32-
type ServiceConfig struct {
30+
type GRPCConfig struct {
3331
ListenAddress string
3432
}
3533

36-
func ServiceCentral(config ServiceConfig) svc.Service {
37-
server := grpc.NewServer( /* currently no auth parameters required */ )
38-
39-
RegisterCentral(server)
40-
41-
return &service{
42-
cfg: config,
43-
grpcServer: server,
44-
}
45-
}
34+
type RegisterServerFunc func(server *grpc.Server)
4635

47-
func Service(config ServiceConfig, closer context.CancelFunc) svc.Service {
36+
func NewGRPC(config GRPCConfig, registerFuncs ...RegisterServerFunc) Service {
4837
server := grpc.NewServer( /* currently no auth parameters required */ )
4938

50-
Register(server, closer)
39+
for _, fn := range registerFuncs {
40+
fn(server)
41+
}
5142

5243
return &service{
5344
cfg: config,
@@ -57,7 +48,7 @@ func Service(config ServiceConfig, closer context.CancelFunc) svc.Service {
5748

5849
type service struct {
5950
grpcServer *grpc.Server
60-
cfg ServiceConfig
51+
cfg GRPCConfig
6152
}
6253

6354
func (s *service) Run(ctx context.Context) error {

pkg/util/svc/service.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ import (
2525
"sync"
2626

2727
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
28+
"github.com/arangodb/kube-arangodb/pkg/util/probe"
2829
)
2930

3031
type Service interface {
3132
Run(ctx context.Context) error
3233
}
3334

34-
func RunServices(ctx context.Context, services ...Service) error {
35+
func RunServices(ctx context.Context, healthService probe.HealthService, services ...Service) error {
3536
if len(services) == 0 {
3637
<-ctx.Done()
3738
return nil
@@ -48,9 +49,12 @@ func RunServices(ctx context.Context, services ...Service) error {
4849
defer wg.Done()
4950

5051
errors[id] = services[id].Run(ctx)
52+
53+
healthService.Shutdown()
5154
}(id)
5255
}
5356

57+
healthService.SetServing()
5458
wg.Wait()
5559

5660
return shared.WithErrors(errors...)

0 commit comments

Comments
 (0)