Skip to content

Commit b2c88f6

Browse files
authored
[Feature] [ML] Shutdown Handler (#1529)
1 parent 244c362 commit b2c88f6

26 files changed

+641
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- (Improvement) (ML) Switch to fsnotify for file watching for MacOS support
3131
- (Feature) (ML) Unify Images, Resources and Lifecycle
3232
- (Improvement) (ML) CronJob status update
33+
- (Improvement) (ML) Job Sidecar Shutdown
3334

3435
## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
3536
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks

cmd/ml_storage.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
package cmd
2222

2323
import (
24-
"context"
2524
"os"
2625

2726
"github.com/rs/zerolog/log"
2827
"github.com/spf13/cobra"
2928

3029
"github.com/arangodb/kube-arangodb/pkg/ml/storage"
31-
"github.com/arangodb/kube-arangodb/pkg/util"
30+
"github.com/arangodb/kube-arangodb/pkg/util/shutdown"
31+
"github.com/arangodb/kube-arangodb/pkg/util/svc"
3232
)
3333

3434
var (
@@ -48,13 +48,18 @@ var (
4848
cmdMLStorageS3Options struct {
4949
storage.ServiceConfig
5050
}
51+
52+
cmdMLShutdownOptions struct {
53+
shutdown.ServiceConfig
54+
}
5155
)
5256

5357
func init() {
5458
cmdML.AddCommand(cmdMLStorage)
5559
cmdMLStorage.AddCommand(cmdMLStorageS3)
5660

5761
f := cmdMLStorageS3.PersistentFlags()
62+
f.StringVar(&cmdMLShutdownOptions.ListenAddress, "shutdown.address", "", "Address the GRPC shutdown service will listen on (IP:port)")
5863
f.StringVar(&cmdMLStorageS3Options.ListenAddress, "server.address", "", "Address the GRPC service will listen on (IP:port)")
5964

6065
f.StringVar(&cmdMLStorageS3Options.S3.Endpoint, "s3.endpoint", "", "Endpoint of S3 API implementation")
@@ -76,12 +81,10 @@ func cmdMLStorageS3Run(cmd *cobra.Command, _ []string) {
7681
}
7782

7883
func cmdMLStorageS3RunE(_ *cobra.Command) error {
79-
ctx := util.CreateSignalContext(context.Background())
80-
81-
svc, err := storage.NewService(ctx, storage.StorageTypeS3Proxy, cmdMLStorageS3Options.ServiceConfig)
84+
service, err := storage.NewService(shutdown.Context(), storage.StorageTypeS3Proxy, cmdMLStorageS3Options.ServiceConfig)
8285
if err != nil {
8386
return err
8487
}
8588

86-
return svc.Run(ctx)
89+
return svc.RunServices(shutdown.Context(), service, shutdown.ServiceCentral(cmdMLShutdownOptions.ServiceConfig))
8790
}

docs/api/ArangoMLStorage.V1Alpha1.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ Resources holds resource requests & limits for container
143143
Links:
144144
* [Documentation of core.ResourceRequirements](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#resourcerequirements-v1-core)
145145

146+
***
147+
148+
### .spec.mode.sidecar.shutdownListenPort
149+
150+
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go#L36)</sup>
151+
152+
ShutdownListenPort defines on which port the sidecar container will be listening for shutdown connections
153+
154+
Default Value: `9202`
155+
146156
## Status
147157

148158
### .status.conditions

pkg/api/shutdown/v1/operator.pb.go

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/shutdown/v1/operator.proto

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/shutdown/v1/operator_grpc.pb.go

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/ml/v1alpha1/extension_spec_deployment.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ func (s *ArangoMLExtensionSpecDeployment) Validate() error {
107107
}
108108

109109
errs := []error{
110-
shared.PrefixResourceErrors("service", shared.ValidateOptional(s.GetService(), func(service ArangoMLExtensionSpecDeploymentService) error {
111-
return service.Validate()
112-
})),
110+
shared.PrefixResourceErrors("service", shared.ValidateOptional(s.GetService(), func(s ArangoMLExtensionSpecDeploymentService) error { return s.Validate() })),
113111
}
114112

115113
if s.GetReplicas() < 0 || s.GetReplicas() > 10 {

pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ 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
35+
// +doc/default: 9202
36+
ShutdownListenPort *uint16 `json:"shutdownListenPort,omitempty"`
37+
3438
// Image define default image used for the extension
3539
*sharedApi.Image `json:",inline"`
3640

@@ -65,6 +69,10 @@ func (s *ArangoMLStorageSpecModeSidecar) Validate() error {
6569
err = append(err, shared.PrefixResourceErrors("listenPort", errors.Newf("must be positive")))
6670
}
6771

72+
if s.GetShutdownListenPort() < 1 {
73+
err = append(err, shared.PrefixResourceErrors("shutdownListenPort", errors.Newf("must be positive")))
74+
}
75+
6876
err = append(err, s.GetResources().Validate())
6977

7078
return shared.WithErrors(err...)
@@ -76,3 +84,10 @@ func (s *ArangoMLStorageSpecModeSidecar) GetListenPort() uint16 {
7684
}
7785
return *s.ListenPort
7886
}
87+
88+
func (s *ArangoMLStorageSpecModeSidecar) GetShutdownListenPort() uint16 {
89+
if s == nil || s.ShutdownListenPort == nil {
90+
return 9202
91+
}
92+
return *s.ShutdownListenPort
93+
}

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

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/shared/v1/image.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ type Image struct {
3838
PullSecrets []string `json:"pullSecrets,omitempty"`
3939
}
4040

41+
func (i *Image) GetImage() string {
42+
if i == nil || i.Image == nil {
43+
return ""
44+
}
45+
46+
return *i.Image
47+
}
48+
4149
func (i *Image) Validate() error {
4250
if i == nil {
4351
return nil

0 commit comments

Comments
 (0)