Skip to content

Commit 6f713a8

Browse files
authored
[Feature] [Scheduler] Shutdown Integration (#1777)
1 parent 9f1bd2b commit 6f713a8

File tree

10 files changed

+122
-18
lines changed

10 files changed

+122
-18
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- (Improvement) Drop slash requirement from ArangoRoute
3131
- (Feature) (Networking) Pass through Server Header
3232
- (Feature) (Platform) Shutdown migration to CE
33+
- (Feature) (Scheduler) Shutdown Integration
3334

3435
## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
3536
- (Feature) ArangoRoute CRD

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG IMAGE=ubuntu:24.04
2-
ARG ENVOY_IMAGE=envoyproxy/envoy:v1.31.0
2+
ARG ENVOY_IMAGE=envoyproxy/envoy:v1.32.1
33

44
# Build Steps
55

docs/integration-sidecar.md

+12
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ metadata:
8787
integration.profiles.arangodb.com/storage: v2
8888
```
8989
90+
#### [Shutdown V1](/docs/integration/shutdown.v1.md)
91+
92+
Shutdown Integration Sidecar
93+
94+
To enable:
95+
96+
```yaml
97+
metadata:
98+
labels:
99+
integration.profiles.arangodb.com/shutdown: v1
100+
```
101+
90102
### Envs
91103
92104
#### INTEGRATION_API_ADDRESS

docs/integration/shutdown.v1.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: page
3+
title: Authentication V1
4+
parent: ArangoDBPlatform
5+
---
6+
7+
# Shutdown V1
8+
9+
Definitions:
10+
11+
- [Service](../../integrations/shutdown/v1/definition/definition.proto)
12+
13+
Operator will send shutdown request once all containers marked with annotation are stopped.
14+
15+
Example:
16+
17+
```yaml
18+
metadata:
19+
annotations:
20+
core.shutdown.arangodb.com/app: "true"
21+
core.shutdown.arangodb.com/app2: "true"
22+
container.shutdown.arangodb.com/app3: port1
23+
spec:
24+
containers:
25+
- name: app
26+
- name: app2
27+
- name: app3
28+
ports:
29+
name: port1
30+
```
31+
32+
Pod will receive shutdown request on port `port1` if containers `app` and `app2` will be in non running state.

integrations/envoy/auth/v3/response.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (d DeniedResponse) GetCheckResponse() (*pbEnvoyAuthV3.CheckResponse, error)
6666
resp.Body = string(z)
6767
resp.Headers = append(resp.Headers, &corev3.HeaderValueOption{
6868
Header: &corev3.HeaderValue{
69-
Key: "content/type",
69+
Key: "content-type",
7070
Value: "application/json",
7171
},
7272
AppendAction: corev3.HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD,

pkg/deployment/resources/arango_profiles.go

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
153153
Spec: spec,
154154
DeploymentName: apiObject.GetName(),
155155
})),
156+
gen(constants.ProfilesIntegrationShutdown, constants.ProfilesIntegrationV1, always(sidecar.IntegrationShutdownV1{})),
156157
gen(constants.ProfilesIntegrationEnvoy, constants.ProfilesIntegrationV3, always(sidecar.IntegrationEnvoyV3{Spec: spec})),
157158
gen(constants.ProfilesIntegrationStorage, constants.ProfilesIntegrationV2, func() (sidecar.Integration, bool) {
158159
if v, err := cachedStatus.ArangoPlatformStorage().V1Alpha1(); err == nil {

pkg/integrations/sidecar/integration.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ const (
2929
ListenPortHealthName = "health"
3030
)
3131

32-
type Integration interface {
33-
Name() []string
34-
Envs() ([]core.EnvVar, error)
35-
GlobalEnvs() ([]core.EnvVar, error)
36-
Volumes() ([]core.Volume, []core.VolumeMount, error)
37-
Validate() error
38-
}
39-
4032
func NewShutdownAnnotations(coreContainers []string) *schedulerApi.ProfileTemplate {
4133
pt := schedulerApi.ProfileTemplate{
4234
Pod: &schedulerPodApi.Pod{
@@ -57,6 +49,7 @@ func NewIntegrationEnablement(integrations ...Integration) (*schedulerApi.Profil
5749
var envs, gEnvs []core.EnvVar
5850
var volumes []core.Volume
5951
var volumeMounts []core.VolumeMount
52+
var annotations = map[string]string{}
6053

6154
for _, integration := range integrations {
6255
name := strings.Join(integration.Name(), "/")
@@ -72,6 +65,14 @@ func NewIntegrationEnablement(integrations ...Integration) (*schedulerApi.Profil
7265
volumeMounts = append(volumeMounts, lvolumeMounts...)
7366
}
7467

68+
if anns, err := getIntegrationAnnotations(integration); err != nil {
69+
return nil, errors.Wrapf(err, "Failure in annotations %s", name)
70+
} else {
71+
for k, v := range anns {
72+
annotations[k] = v
73+
}
74+
}
75+
7576
if lenvs, err := integration.Envs(); err != nil {
7677
return nil, errors.Wrapf(err, "Failure in envs %s", name)
7778
} else if len(lenvs) > 0 {
@@ -92,6 +93,9 @@ func NewIntegrationEnablement(integrations ...Integration) (*schedulerApi.Profil
9293
return &schedulerApi.ProfileTemplate{
9394
Priority: util.NewType(127),
9495
Pod: &schedulerPodApi.Pod{
96+
Metadata: &schedulerPodResourcesApi.Metadata{
97+
Annotations: annotations,
98+
},
9599
Volumes: &schedulerPodResourcesApi.Volumes{
96100
Volumes: volumes,
97101
},
@@ -205,9 +209,6 @@ func NewIntegration(image *schedulerContainerResourcesApi.Image, integration *sc
205209
},
206210
}
207211

208-
pt.Pod.Metadata.Annotations[fmt.Sprintf("%s/%s", constants.AnnotationShutdownContainer, ContainerName)] = ListenPortHealthName
209-
pt.Pod.Metadata.Annotations[constants.AnnotationShutdownManagedContainer] = "true"
210-
211212
pt.Container.All.Environments = &schedulerContainerResourcesApi.Environments{
212213
Env: envs,
213214
}

pkg/integrations/sidecar/integration.shutdown.v1.go

+11
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,24 @@
2121
package sidecar
2222

2323
import (
24+
"fmt"
25+
2426
core "k8s.io/api/core/v1"
27+
28+
"github.com/arangodb/kube-arangodb/pkg/util/constants"
2529
)
2630

2731
type IntegrationShutdownV1 struct {
2832
Core *Core
2933
}
3034

35+
func (i IntegrationShutdownV1) Annotations() (map[string]string, error) {
36+
return map[string]string{
37+
fmt.Sprintf("%s/%s", constants.AnnotationShutdownContainer, ContainerName): ListenPortHealthName,
38+
constants.AnnotationShutdownManagedContainer: "true",
39+
}, nil
40+
}
41+
3142
func (i IntegrationShutdownV1) Name() []string {
3243
return []string{"SHUTDOWN", "V1"}
3344
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 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 sidecar
22+
23+
import core "k8s.io/api/core/v1"
24+
25+
type Integration interface {
26+
Name() []string
27+
Envs() ([]core.EnvVar, error)
28+
GlobalEnvs() ([]core.EnvVar, error)
29+
Volumes() ([]core.Volume, []core.VolumeMount, error)
30+
Validate() error
31+
}
32+
33+
type IntegrationAnnotations interface {
34+
Integration
35+
36+
Annotations() (map[string]string, error)
37+
}
38+
39+
func getIntegrationAnnotations(int Integration) (map[string]string, error) {
40+
if v, ok := int.(IntegrationAnnotations); ok {
41+
return v.Annotations()
42+
}
43+
44+
return nil, nil
45+
}

pkg/util/constants/profiles.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ const ProfilesDeployment = ProfileGroup + "/deployment"
2828
const ProfilesIntegrationPrefix = "integration." + ProfileGroup
2929

3030
const (
31-
ProfilesIntegrationAuthn = "authn"
32-
ProfilesIntegrationAuthz = "authz"
33-
ProfilesIntegrationSched = "sched"
34-
ProfilesIntegrationEnvoy = "envoy"
35-
ProfilesIntegrationStorage = "storage"
31+
ProfilesIntegrationAuthn = "authn"
32+
ProfilesIntegrationAuthz = "authz"
33+
ProfilesIntegrationSched = "sched"
34+
ProfilesIntegrationEnvoy = "envoy"
35+
ProfilesIntegrationStorage = "storage"
36+
ProfilesIntegrationShutdown = "shutdown"
3637
)
3738

3839
const (

0 commit comments

Comments
 (0)