Skip to content

[Feature] [Scheduler] Shutdown Integration #1777

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 3 commits into from
Dec 6, 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
Expand Up @@ -30,6 +30,7 @@
- (Improvement) Drop slash requirement from ArangoRoute
- (Feature) (Networking) Pass through Server Header
- (Feature) (Platform) Shutdown migration to CE
- (Feature) (Scheduler) Shutdown Integration

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG IMAGE=ubuntu:24.04
ARG ENVOY_IMAGE=envoyproxy/envoy:v1.31.0
ARG ENVOY_IMAGE=envoyproxy/envoy:v1.32.1

# Build Steps

Expand Down
12 changes: 12 additions & 0 deletions docs/integration-sidecar.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ metadata:
integration.profiles.arangodb.com/storage: v2
```

#### [Shutdown V1](/docs/integration/shutdown.v1.md)

Shutdown Integration Sidecar

To enable:

```yaml
metadata:
labels:
integration.profiles.arangodb.com/shutdown: v1
```

### Envs

#### INTEGRATION_API_ADDRESS
Expand Down
32 changes: 32 additions & 0 deletions docs/integration/shutdown.v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: page
title: Authentication V1
parent: ArangoDBPlatform
---

# Shutdown V1

Definitions:

- [Service](../../integrations/shutdown/v1/definition/definition.proto)

Operator will send shutdown request once all containers marked with annotation are stopped.

Example:

```yaml
metadata:
annotations:
core.shutdown.arangodb.com/app: "true"
core.shutdown.arangodb.com/app2: "true"
container.shutdown.arangodb.com/app3: port1
spec:
containers:
- name: app
- name: app2
- name: app3
ports:
name: port1
```

Pod will receive shutdown request on port `port1` if containers `app` and `app2` will be in non running state.
2 changes: 1 addition & 1 deletion integrations/envoy/auth/v3/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (d DeniedResponse) GetCheckResponse() (*pbEnvoyAuthV3.CheckResponse, error)
resp.Body = string(z)
resp.Headers = append(resp.Headers, &corev3.HeaderValueOption{
Header: &corev3.HeaderValue{
Key: "content/type",
Key: "content-type",
Value: "application/json",
},
AppendAction: corev3.HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD,
Expand Down
1 change: 1 addition & 0 deletions pkg/deployment/resources/arango_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (r *Resources) EnsureArangoProfiles(ctx context.Context, cachedStatus inspe
Spec: spec,
DeploymentName: apiObject.GetName(),
})),
gen(constants.ProfilesIntegrationShutdown, constants.ProfilesIntegrationV1, always(sidecar.IntegrationShutdownV1{})),
gen(constants.ProfilesIntegrationEnvoy, constants.ProfilesIntegrationV3, always(sidecar.IntegrationEnvoyV3{Spec: spec})),
gen(constants.ProfilesIntegrationStorage, constants.ProfilesIntegrationV2, func() (sidecar.Integration, bool) {
if v, err := cachedStatus.ArangoPlatformStorage().V1Alpha1(); err == nil {
Expand Down
23 changes: 12 additions & 11 deletions pkg/integrations/sidecar/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ const (
ListenPortHealthName = "health"
)

type Integration interface {
Name() []string
Envs() ([]core.EnvVar, error)
GlobalEnvs() ([]core.EnvVar, error)
Volumes() ([]core.Volume, []core.VolumeMount, error)
Validate() error
}

func NewShutdownAnnotations(coreContainers []string) *schedulerApi.ProfileTemplate {
pt := schedulerApi.ProfileTemplate{
Pod: &schedulerPodApi.Pod{
Expand All @@ -57,6 +49,7 @@ func NewIntegrationEnablement(integrations ...Integration) (*schedulerApi.Profil
var envs, gEnvs []core.EnvVar
var volumes []core.Volume
var volumeMounts []core.VolumeMount
var annotations = map[string]string{}

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

if anns, err := getIntegrationAnnotations(integration); err != nil {
return nil, errors.Wrapf(err, "Failure in annotations %s", name)
} else {
for k, v := range anns {
annotations[k] = v
}
}

if lenvs, err := integration.Envs(); err != nil {
return nil, errors.Wrapf(err, "Failure in envs %s", name)
} else if len(lenvs) > 0 {
Expand All @@ -92,6 +93,9 @@ func NewIntegrationEnablement(integrations ...Integration) (*schedulerApi.Profil
return &schedulerApi.ProfileTemplate{
Priority: util.NewType(127),
Pod: &schedulerPodApi.Pod{
Metadata: &schedulerPodResourcesApi.Metadata{
Annotations: annotations,
},
Volumes: &schedulerPodResourcesApi.Volumes{
Volumes: volumes,
},
Expand Down Expand Up @@ -205,9 +209,6 @@ func NewIntegration(image *schedulerContainerResourcesApi.Image, integration *sc
},
}

pt.Pod.Metadata.Annotations[fmt.Sprintf("%s/%s", constants.AnnotationShutdownContainer, ContainerName)] = ListenPortHealthName
pt.Pod.Metadata.Annotations[constants.AnnotationShutdownManagedContainer] = "true"

pt.Container.All.Environments = &schedulerContainerResourcesApi.Environments{
Env: envs,
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/integrations/sidecar/integration.shutdown.v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@
package sidecar

import (
"fmt"

core "k8s.io/api/core/v1"

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

type IntegrationShutdownV1 struct {
Core *Core
}

func (i IntegrationShutdownV1) Annotations() (map[string]string, error) {
return map[string]string{
fmt.Sprintf("%s/%s", constants.AnnotationShutdownContainer, ContainerName): ListenPortHealthName,
constants.AnnotationShutdownManagedContainer: "true",
}, nil
}

func (i IntegrationShutdownV1) Name() []string {
return []string{"SHUTDOWN", "V1"}
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/integrations/sidecar/integration_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// DISCLAIMER
//
// Copyright 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package sidecar

import core "k8s.io/api/core/v1"

type Integration interface {
Name() []string
Envs() ([]core.EnvVar, error)
GlobalEnvs() ([]core.EnvVar, error)
Volumes() ([]core.Volume, []core.VolumeMount, error)
Validate() error
}

type IntegrationAnnotations interface {
Integration

Annotations() (map[string]string, error)
}

func getIntegrationAnnotations(int Integration) (map[string]string, error) {
if v, ok := int.(IntegrationAnnotations); ok {
return v.Annotations()
}

return nil, nil
}
11 changes: 6 additions & 5 deletions pkg/util/constants/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ const ProfilesDeployment = ProfileGroup + "/deployment"
const ProfilesIntegrationPrefix = "integration." + ProfileGroup

const (
ProfilesIntegrationAuthn = "authn"
ProfilesIntegrationAuthz = "authz"
ProfilesIntegrationSched = "sched"
ProfilesIntegrationEnvoy = "envoy"
ProfilesIntegrationStorage = "storage"
ProfilesIntegrationAuthn = "authn"
ProfilesIntegrationAuthz = "authz"
ProfilesIntegrationSched = "sched"
ProfilesIntegrationEnvoy = "envoy"
ProfilesIntegrationStorage = "storage"
ProfilesIntegrationShutdown = "shutdown"
)

const (
Expand Down