1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Extract Scheduler API (#1599)

This commit is contained in:
Adam Janikowski 2024-02-23 09:21:00 +01:00 committed by GitHub
parent 5eb65d3785
commit d2045e0e5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
63 changed files with 2539 additions and 1564 deletions

View file

@ -41,6 +41,16 @@ linters-settings:
alias: policy
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/shared/v1
alias: sharedApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1
alias: schedulerApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container
alias: schedulerContainerApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources
alias: schedulerContainerResourcesApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod
alias: schedulerPodApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod/resources
alias: schedulerPodResourcesApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/shared
alias: shared
- pkg: github.com/arangodb/kube-arangodb/pkg/handlers/enterprise/ml/shared

View file

@ -1,6 +1,7 @@
# Change Log
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) Extract Scheduler API
## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
- (Feature) Extract GRPC Server

View file

@ -431,14 +431,14 @@ update-generated:
"client lister informer deepcopy" \
"github.com/arangodb/kube-arangodb/pkg/generated" \
"github.com/arangodb/kube-arangodb/pkg/apis" \
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1 ml:v1alpha1" \
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1 ml:v1alpha1 scheduler:v1alpha1" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)
GOPATH=$(GOBUILDDIR) $(VENDORDIR)/k8s.io/code-generator/generate-groups.sh \
"deepcopy" \
"github.com/arangodb/kube-arangodb/pkg/generated" \
"github.com/arangodb/kube-arangodb/pkg/apis" \
"shared:v1" \
"shared:v1 scheduler:v1alpha1/container scheduler:v1alpha1/container/resources scheduler:v1alpha1/pod scheduler:v1alpha1/pod/resources" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)

File diff suppressed because it is too large Load diff

View file

@ -116,7 +116,7 @@ Default Value: `9202`
### .spec.mode.sidecar.env
Type: `core.EnvVar` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/envs.go#L33)</sup>
Type: `core.EnvVar` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/environments.go#L33)</sup>
Env keeps the information about environment variables provided to the container
@ -127,7 +127,7 @@ Links:
### .spec.mode.sidecar.envFrom
Type: `core.EnvFromSource` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/envs.go#L38)</sup>
Type: `core.EnvFromSource` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/environments.go#L38)</sup>
EnvFrom keeps the information about environment variable sources provided to the container
@ -138,12 +138,30 @@ Links:
### .spec.mode.sidecar.image
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/image.go#L31)</sup>
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L34)</sup>
Image define image details
***
### .spec.mode.sidecar.imagePullPolicy
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L38)</sup>
ImagePullPolicy define Image pull policy
Default Value: `IfNotPresent`
***
### .spec.mode.sidecar.imagePullSecrets
Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L41)</sup>
ImagePullSecrets define Secrets used to pull Image from registry
***
### .spec.mode.sidecar.listenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go#L32)</sup>
@ -154,27 +172,9 @@ Default Value: `9201`
***
### .spec.mode.sidecar.pullPolicy
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/image.go#L35)</sup>
PullPolicy define Image pull policy
Default Value: `IfNotPresent`
***
### .spec.mode.sidecar.pullSecrets
Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/image.go#L38)</sup>
PullSecrets define Secrets used to pull Image from registry
***
### .spec.mode.sidecar.resources
Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/resources.go#L34)</sup>
Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/resources.go#L34)</sup>
Resources holds resource requests & limits for container
@ -185,7 +185,7 @@ Links:
### .spec.mode.sidecar.securityContext
Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/security_container.go#L29)</sup>
Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/security.go#L31)</sup>
PodSecurityContext holds pod-level security attributes and common container settings.

View file

@ -137,72 +137,118 @@ func Test_GenerateAPIDocs(t *testing.T) {
fset := token.NewFileSet()
sharedFields := parseSourceFiles(t, root, fset, fmt.Sprintf("%s/pkg/apis/shared/v1", root))
type inputPackageTypes map[string]map[string]any
type inputPackage struct {
Types inputPackageTypes
Shared []string
}
type inputPackages map[string]map[string]inputPackage
// package path -> result doc file name -> name of the top-level field to be described -> field instance for reflection
input := map[string]map[string]map[string]interface{}{
fmt.Sprintf("%s/pkg/apis/deployment/v1", root): {
"ArangoDeployment.V1": {
"Spec": deploymentApi.ArangoDeployment{}.Spec,
},
"ArangoMember.V1": {
"Spec": deploymentApi.ArangoMember{}.Spec,
input := inputPackages{
"deployment": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoDeployment.V1": {
"Spec": deploymentApi.ArangoDeployment{}.Spec,
},
"ArangoMember.V1": {
"Spec": deploymentApi.ArangoMember{}.Spec,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/apps/v1", root): {
"ArangoJob.V1": {
"Spec": appsApi.ArangoJob{}.Spec,
"apps": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoJob.V1": {
"Spec": appsApi.ArangoJob{}.Spec,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/backup/v1", root): {
"ArangoBackup.V1": {
"Spec": backupApi.ArangoBackup{}.Spec,
"Status": backupApi.ArangoBackup{}.Status,
},
"ArangoBackupPolicy.V1": {
"Spec": backupApi.ArangoBackupPolicy{}.Spec,
"Status": backupApi.ArangoBackupPolicy{}.Status,
"backup": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoBackup.V1": {
"Spec": backupApi.ArangoBackup{}.Spec,
"Status": backupApi.ArangoBackup{}.Status,
},
"ArangoBackupPolicy.V1": {
"Spec": backupApi.ArangoBackupPolicy{}.Spec,
"Status": backupApi.ArangoBackupPolicy{}.Status,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/ml/v1alpha1", root): {
"ArangoMLExtension.V1Alpha1": {
"Spec": mlApi.ArangoMLExtension{}.Spec,
"Status": mlApi.ArangoMLExtension{}.Status,
},
"ArangoMLStorage.V1Alpha1": {
"Spec": mlApi.ArangoMLStorage{}.Spec,
"Status": mlApi.ArangoMLStorage{}.Status,
},
"ArangoMLCronJob.V1Alpha1": {
"Spec": mlApi.ArangoMLCronJob{}.Spec,
"Status": mlApi.ArangoMLCronJob{}.Status,
},
"ArangoMLBatchJob.V1Alpha1": {
"Spec": mlApi.ArangoMLBatchJob{}.Spec,
"Status": mlApi.ArangoMLBatchJob{}.Status,
"ml": map[string]inputPackage{
"v1alpha1": {
Types: inputPackageTypes{
"ArangoMLExtension.V1Alpha1": {
"Spec": mlApi.ArangoMLExtension{}.Spec,
"Status": mlApi.ArangoMLExtension{}.Status,
},
"ArangoMLStorage.V1Alpha1": {
"Spec": mlApi.ArangoMLStorage{}.Spec,
"Status": mlApi.ArangoMLStorage{}.Status,
},
"ArangoMLCronJob.V1Alpha1": {
"Spec": mlApi.ArangoMLCronJob{}.Spec,
"Status": mlApi.ArangoMLCronJob{}.Status,
},
"ArangoMLBatchJob.V1Alpha1": {
"Spec": mlApi.ArangoMLBatchJob{}.Spec,
"Status": mlApi.ArangoMLBatchJob{}.Status,
},
},
Shared: []string{
"shared/v1",
"scheduler/v1alpha1",
"scheduler/v1alpha1/container",
"scheduler/v1alpha1/container/resources",
"scheduler/v1alpha1/pod",
"scheduler/v1alpha1/pod/resources",
},
},
},
fmt.Sprintf("%s/pkg/apis/replication/v1", root): {
"ArangoDeploymentReplication.V1": {
"Spec": replicationApi.ArangoDeploymentReplication{}.Spec,
"replication": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoDeploymentReplication.V1": {
"Spec": replicationApi.ArangoDeploymentReplication{}.Spec,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/storage/v1alpha", root): {
"ArangoLocalStorage.V1Alpha": {
"Spec": storageApi.ArangoLocalStorage{}.Spec,
"storage": map[string]inputPackage{
"v1alpha": {
Types: inputPackageTypes{
"ArangoLocalStorage.V1Alpha": {
"Spec": storageApi.ArangoLocalStorage{}.Spec,
},
},
},
},
}
for apiDir, docs := range input {
fields := parseSourceFiles(t, root, fset, apiDir)
for name, versions := range input {
for version, docs := range versions {
fields := parseSourceFiles(t, root, fset, path.Join(root, "pkg/apis", name, version))
for n, f := range sharedFields {
require.NotContains(t, fields, n)
fields[n] = f
for _, p := range docs.Shared {
sharedFields := parseSourceFiles(t, root, fset, path.Join(root, "pkg/apis", p))
for n, f := range sharedFields {
require.NotContains(t, fields, n)
fields[n] = f
}
}
generateDocs(t, docs.Types, fields, fset)
}
generateDocs(t, docs, fields, fset)
}
}

View file

@ -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.
@ -21,6 +21,7 @@
package v1alpha1
import (
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
)
@ -34,7 +35,7 @@ type ArangoMLExtensionSpec struct {
Storage *sharedApi.Object `json:"storage,omitempty"`
// Image defines default image used for the extension
*sharedApi.Image `json:",inline"`
*schedulerContainerResourcesApi.Image `json:",inline"`
// ArangoMLExtensionTemplate define Init job specification
Init *ArangoMLExtensionTemplate `json:"init,omitempty"`
@ -54,7 +55,7 @@ func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetad
return a.MetadataService
}
func (a *ArangoMLExtensionSpec) GetImage() *sharedApi.Image {
func (a *ArangoMLExtensionSpec) GetImage() *schedulerContainerResourcesApi.Image {
if a == nil || a.Image == nil {
return nil
}
@ -102,7 +103,7 @@ func (a *ArangoMLExtensionSpec) Validate() error {
shared.PrefixResourceErrors("storage", shared.ValidateRequired(a.GetStorage(), func(obj sharedApi.Object) error { return obj.Validate() })),
a.GetImage().Validate(),
shared.PrefixResourceErrors("init", a.GetInit().Validate()),
shared.ValidateAnyNotNil(".image or .init.image needs to be specified", a.GetImage(), a.GetInit().GetContainerTemplate().GetImage()),
shared.ValidateAnyNotNil(".image or .init.image needs to be specified", a.GetImage(), a.GetInit().GetContainer().GetImage()),
shared.PrefixResourceErrors("deployment", a.GetDeployment().Validate()),
shared.PrefixResourceErrors("jobsTemplates", a.GetJobsTemplates().Validate()),
))

View file

@ -21,8 +21,8 @@
package v1alpha1
import (
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
@ -58,8 +58,8 @@ type ArangoMLExtensionSpecDeployment struct {
// Service defines how components will be exposed
Service *ArangoMLExtensionSpecDeploymentService `json:"service,omitempty"`
// PodTemplate defines base template for pods
*sharedApi.PodTemplate
// Pod defines base template for pods
*schedulerPodApi.Pod
// Prediction defines how Prediction workload will be deployed
Prediction *ArangoMLExtensionSpecDeploymentComponent `json:"prediction,omitempty"`
@ -76,12 +76,12 @@ func (s *ArangoMLExtensionSpecDeployment) GetReplicas() int32 {
return *s.Replicas
}
func (s *ArangoMLExtensionSpecDeployment) GetPodTemplate() *sharedApi.PodTemplate {
if s == nil || s.PodTemplate == nil {
func (s *ArangoMLExtensionSpecDeployment) GetPodTemplate() *schedulerPodApi.Pod {
if s == nil || s.Pod == nil {
return nil
}
return s.PodTemplate
return s.Pod
}
func (s *ArangoMLExtensionSpecDeployment) GetPrediction() *ArangoMLExtensionSpecDeploymentComponent {

View file

@ -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.
@ -21,8 +21,8 @@
package v1alpha1
import (
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
)
type ArangoMLExtensionSpecDeploymentComponent struct {
@ -33,8 +33,8 @@ type ArangoMLExtensionSpecDeploymentComponent struct {
// Port defines on which port the container will be listening for connections
Port *int32 `json:"port,omitempty"`
// ContainerTemplate Keeps the information about Container configuration
*sharedApi.ContainerTemplate `json:",inline"`
// Container Keeps the information about Container configuration
*schedulerContainerApi.Container `json:",inline"`
}
func (s *ArangoMLExtensionSpecDeploymentComponent) GetGPU() bool {
@ -51,12 +51,12 @@ func (s *ArangoMLExtensionSpecDeploymentComponent) GetPort(def int32) int32 {
return *s.Port
}
func (s *ArangoMLExtensionSpecDeploymentComponent) GetContainerTemplate() *sharedApi.ContainerTemplate {
if s == nil || s.ContainerTemplate == nil {
func (s *ArangoMLExtensionSpecDeploymentComponent) GetContainer() *schedulerContainerApi.Container {
if s == nil || s.Container == nil {
return nil
}
return s.ContainerTemplate
return s.Container
}
func (s *ArangoMLExtensionSpecDeploymentComponent) Validate() error {
@ -67,7 +67,7 @@ func (s *ArangoMLExtensionSpecDeploymentComponent) Validate() error {
var err []error
err = append(err,
s.GetContainerTemplate().Validate(),
s.GetContainer().Validate(),
)
return shared.WithErrors(err...)

View file

@ -21,8 +21,9 @@
package v1alpha1
import (
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container"
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
)
type JobType string
@ -115,27 +116,27 @@ func (a *ArangoMLJobTemplates) Validate() error {
}
type ArangoMLExtensionTemplate struct {
// PodTemplate keeps the information about Pod configuration
*sharedApi.PodTemplate `json:",inline"`
// Pod keeps the information about Pod configuration
*schedulerPodApi.Pod `json:",inline"`
// ContainerTemplate Keeps the information about Container configuration
*sharedApi.ContainerTemplate `json:",inline"`
// Container Keeps the information about Container configuration
*schedulerContainerApi.Container `json:",inline"`
}
func (a *ArangoMLExtensionTemplate) GetPodTemplate() *sharedApi.PodTemplate {
if a == nil {
func (a *ArangoMLExtensionTemplate) GetPodTemplate() *schedulerPodApi.Pod {
if a == nil || a.Pod == nil {
return nil
}
return a.PodTemplate
return a.Pod
}
func (a *ArangoMLExtensionTemplate) GetContainerTemplate() *sharedApi.ContainerTemplate {
if a == nil {
func (a *ArangoMLExtensionTemplate) GetContainer() *schedulerContainerApi.Container {
if a == nil || a.Container == nil {
return nil
}
return a.ContainerTemplate
return a.Container
}
func (a *ArangoMLExtensionTemplate) Validate() error {
@ -145,6 +146,6 @@ func (a *ArangoMLExtensionTemplate) Validate() error {
return shared.WithErrors(
a.GetPodTemplate().Validate(),
a.GetContainerTemplate().Validate(),
a.GetContainer().Validate(),
)
}

View file

@ -21,8 +21,8 @@
package v1alpha1
import (
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
@ -35,16 +35,16 @@ type ArangoMLStorageSpecModeSidecar struct {
// +doc/default: 9202
ControllerListenPort *uint16 `json:"controllerListenPort,omitempty"`
// ContainerTemplate Keeps the information about Container configuration
*sharedApi.ContainerTemplate `json:",inline"`
// Container Keeps the information about Container configuration
*schedulerContainerApi.Container `json:",inline"`
}
func (s *ArangoMLStorageSpecModeSidecar) GetContainerTemplate() *sharedApi.ContainerTemplate {
if s == nil || s.ContainerTemplate == nil {
func (s *ArangoMLStorageSpecModeSidecar) GetContainer() *schedulerContainerApi.Container {
if s == nil || s.Container == nil {
return nil
}
return s.ContainerTemplate
return s.Container
}
func (s *ArangoMLStorageSpecModeSidecar) Validate() error {
@ -62,7 +62,7 @@ func (s *ArangoMLStorageSpecModeSidecar) Validate() error {
err = append(err, shared.PrefixResourceErrors("controllerListenPort", errors.Errorf("must be positive")))
}
err = append(err, s.GetContainerTemplate().Validate())
err = append(err, s.GetContainer().Validate())
return shared.WithErrors(err...)
}

View file

@ -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.
@ -27,6 +27,8 @@ import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container"
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
)
@ -66,8 +68,8 @@ func Test_ArangoMLStorageSpec(t *testing.T) {
core.ResourceMemory: resource.MustParse("128Mi"),
},
}
s.Mode.Sidecar.ContainerTemplate = &sharedApi.ContainerTemplate{}
s.Mode.Sidecar.Resources = &sharedApi.Resources{Resources: &assignedRequirements}
s.Mode.Sidecar.Container = &schedulerContainerApi.Container{}
s.Mode.Sidecar.Resources = &schedulerContainerResourcesApi.Resources{Resources: &assignedRequirements}
expectedRequirements := core.ResourceRequirements{
Requests: assignedRequirements.Requests,
@ -77,7 +79,7 @@ func Test_ArangoMLStorageSpec(t *testing.T) {
},
}
actualRequirements := s.Mode.Sidecar.GetResources().With(&sharedApi.Resources{Resources: &core.ResourceRequirements{
actualRequirements := s.Mode.Sidecar.GetResources().With(&schedulerContainerResourcesApi.Resources{Resources: &core.ResourceRequirements{
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("128Mi"),
@ -87,6 +89,6 @@ func Test_ArangoMLStorageSpec(t *testing.T) {
core.ResourceMemory: resource.MustParse("256Mi"),
},
}})
require.Equal(t, expectedRequirements, *actualRequirements.GetResources())
require.Equal(t, expectedRequirements, actualRequirements.GetResources())
})
}

View file

@ -27,6 +27,9 @@ package v1alpha1
import (
deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
container "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container"
resources "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
pod "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
sharedv1 "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
@ -339,7 +342,7 @@ func (in *ArangoMLExtensionSpec) DeepCopyInto(out *ArangoMLExtensionSpec) {
}
if in.Image != nil {
in, out := &in.Image, &out.Image
*out = new(sharedv1.Image)
*out = new(resources.Image)
(*in).DeepCopyInto(*out)
}
if in.Init != nil {
@ -383,9 +386,9 @@ func (in *ArangoMLExtensionSpecDeployment) DeepCopyInto(out *ArangoMLExtensionSp
*out = new(ArangoMLExtensionSpecDeploymentService)
(*in).DeepCopyInto(*out)
}
if in.PodTemplate != nil {
in, out := &in.PodTemplate, &out.PodTemplate
*out = new(sharedv1.PodTemplate)
if in.Pod != nil {
in, out := &in.Pod, &out.Pod
*out = new(pod.Pod)
(*in).DeepCopyInto(*out)
}
if in.Prediction != nil {
@ -429,9 +432,9 @@ func (in *ArangoMLExtensionSpecDeploymentComponent) DeepCopyInto(out *ArangoMLEx
*out = new(int32)
**out = **in
}
if in.ContainerTemplate != nil {
in, out := &in.ContainerTemplate, &out.ContainerTemplate
*out = new(sharedv1.ContainerTemplate)
if in.Container != nil {
in, out := &in.Container, &out.Container
*out = new(container.Container)
(*in).DeepCopyInto(*out)
}
return
@ -650,14 +653,14 @@ func (in *ArangoMLExtensionStatusReconciliation) DeepCopy() *ArangoMLExtensionSt
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ArangoMLExtensionTemplate) DeepCopyInto(out *ArangoMLExtensionTemplate) {
*out = *in
if in.PodTemplate != nil {
in, out := &in.PodTemplate, &out.PodTemplate
*out = new(sharedv1.PodTemplate)
if in.Pod != nil {
in, out := &in.Pod, &out.Pod
*out = new(pod.Pod)
(*in).DeepCopyInto(*out)
}
if in.ContainerTemplate != nil {
in, out := &in.ContainerTemplate, &out.ContainerTemplate
*out = new(sharedv1.ContainerTemplate)
if in.Container != nil {
in, out := &in.Container, &out.Container
*out = new(container.Container)
(*in).DeepCopyInto(*out)
}
return
@ -923,9 +926,9 @@ func (in *ArangoMLStorageSpecModeSidecar) DeepCopyInto(out *ArangoMLStorageSpecM
*out = new(uint16)
**out = **in
}
if in.ContainerTemplate != nil {
in, out := &in.ContainerTemplate, &out.ContainerTemplate
*out = new(sharedv1.ContainerTemplate)
if in.Container != nil {
in, out := &in.Container, &out.Container
*out = new(container.Container)
(*in).DeepCopyInto(*out)
}
return

View file

@ -0,0 +1,25 @@
//
// 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 scheduler
const (
ArangoSchedulerGroupName = "scheduler.arangodb.com"
)

View file

@ -0,0 +1,183 @@
//
// 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 container
import (
core "k8s.io/api/core/v1"
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
)
type Containers map[string]Container
func (c Containers) Apply(template *core.PodTemplateSpec) error {
if len(c) == 0 {
return nil
}
for k, v := range c {
if id := container.GetContainerIDByName(template.Spec.Containers, k); id >= 0 {
if err := v.Apply(template, &template.Spec.Containers[id]); err != nil {
return err
}
} else {
id = len(template.Spec.Containers)
template.Spec.Containers = append(template.Spec.Containers, core.Container{
Name: k,
})
if err := v.Apply(template, &template.Spec.Containers[id]); err != nil {
return err
}
}
}
return nil
}
func (c Containers) With(other Containers) Containers {
if len(c) == 0 && len(other) == 0 {
return nil
}
if len(c) == 0 {
return other.DeepCopy()
}
if len(other) == 0 {
return c.DeepCopy()
}
ret := Containers{}
for k, v := range c {
if v1, ok := other[k]; !ok {
ret[k] = v
} else {
ret[k] = util.TypeOrDefault(v.With(&v1))
}
}
for k, v := range other {
if _, ok := c[k]; !ok {
ret[k] = v
}
}
return ret
}
type Container struct {
// Security keeps the security settings for Container
*schedulerContainerResourcesApi.Security `json:",inline"`
// Environments keeps the environment variables for Container
*schedulerContainerResourcesApi.Environments `json:",inline"`
// Image define default image used for the job
*schedulerContainerResourcesApi.Image `json:",inline"`
// Resources define resources assigned to the pod
*schedulerContainerResourcesApi.Resources `json:",inline"`
}
func (c *Container) Apply(template *core.PodTemplateSpec, container *core.Container) error {
if c == nil {
return nil
}
return shared.WithErrors(
c.Security.Apply(container),
c.Environments.Apply(container),
c.Image.Apply(template, container),
c.Resources.Apply(container),
)
}
func (c *Container) GetImage() *schedulerContainerResourcesApi.Image {
if c == nil || c.Image == nil {
return nil
}
return c.Image
}
func (c *Container) GetResources() *schedulerContainerResourcesApi.Resources {
if c == nil || c.Resources == nil {
return nil
}
return c.Resources
}
func (c *Container) GetSecurity() *schedulerContainerResourcesApi.Security {
if c == nil || c.Security == nil {
return nil
}
return c.Security
}
func (c *Container) GetEnvironments() *schedulerContainerResourcesApi.Environments {
if c == nil || c.Environments == nil {
return nil
}
return c.Environments
}
func (c *Container) With(other *Container) *Container {
if c == nil && other == nil {
return nil
}
if c == nil {
return other.DeepCopy()
}
if other == nil {
return c.DeepCopy()
}
return &Container{
Security: c.Security.With(other.Security),
Environments: c.Environments.With(other.Environments),
Image: c.Image.With(other.Image),
Resources: c.Resources.With(other.Resources),
}
}
func (c *Container) Validate() error {
if c == nil {
return nil
}
return shared.WithErrors(
shared.PrefixResourceErrors("containerSecurity", c.Security.Validate()),
shared.PrefixResourceErrors("containerEnvironments", c.Environments.Validate()),
shared.PrefixResourceErrors("containerResources", c.Image.Validate()),
shared.PrefixResourceErrors("containerImage", c.Resources.Validate()),
)
}

View file

@ -0,0 +1,23 @@
//
// 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
//
// +k8s:deepcopy-gen=package
// +groupName=scheduler.arangodb.com
package container

View file

@ -0,0 +1,99 @@
//
// 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 container
import (
core "k8s.io/api/core/v1"
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
)
type Generic struct {
// Security keeps the security settings for Container
*schedulerContainerResourcesApi.Security `json:",inline"`
// Environments keeps the environment variables for Container
*schedulerContainerResourcesApi.Environments `json:",inline"`
}
func (c *Generic) Apply(template *core.PodTemplateSpec) error {
if c == nil {
return nil
}
for id := range template.Spec.Containers {
if err := shared.WithErrors(
c.Security.Apply(&template.Spec.Containers[id]),
c.Environments.Apply(&template.Spec.Containers[id]),
); err != nil {
return err
}
}
return nil
}
func (c *Generic) GetSecurity() *schedulerContainerResourcesApi.Security {
if c == nil || c.Security == nil {
return nil
}
return c.Security
}
func (c *Generic) GetEnvironments() *schedulerContainerResourcesApi.Environments {
if c == nil || c.Environments == nil {
return nil
}
return c.Environments
}
func (c *Generic) With(other *Generic) *Generic {
if c == nil && other == nil {
return nil
}
if c == nil {
return other.DeepCopy()
}
if other == nil {
return c.DeepCopy()
}
return &Generic{
Security: c.Security.With(other.Security),
Environments: c.Environments.With(other.Environments),
}
}
func (c *Generic) Validate() error {
if c == nil {
return nil
}
return shared.WithErrors(
shared.PrefixResourceErrors("containerSecurity", c.Security.Validate()),
shared.PrefixResourceErrors("containerEnvironments", c.Environments.Validate()),
)
}

View file

@ -0,0 +1,23 @@
//
// 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
//
// +k8s:deepcopy-gen=package
// +groupName=scheduler.arangodb.com
package resources

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
// 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.
@ -18,7 +18,7 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
package resources
import (
core "k8s.io/api/core/v1"
@ -38,6 +38,17 @@ type Environments struct {
EnvFrom []core.EnvFromSource `json:"envFrom,omitempty"`
}
func (e *Environments) Apply(container *core.Container) error {
if e == nil {
return nil
}
container.Env = envs.MergeEnvs(container.Env, e.Env...)
container.EnvFrom = envs.MergeEnvFrom(container.EnvFrom, e.EnvFrom...)
return nil
}
func (e *Environments) With(other *Environments) *Environments {
if e == nil && other == nil {
return nil

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// 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.
@ -18,24 +18,48 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
package resources
import (
core "k8s.io/api/core/v1"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
)
type ImagePullSecrets []string
type Image struct {
// Image define image details
Image *string `json:"image,omitempty"`
// PullPolicy define Image pull policy
// ImagePullPolicy define Image pull policy
// +doc/default: IfNotPresent
PullPolicy *core.PullPolicy `json:"pullPolicy,omitempty"`
ImagePullPolicy *core.PullPolicy `json:"imagePullPolicy,omitempty"`
// PullSecrets define Secrets used to pull Image from registry
PullSecrets []string `json:"pullSecrets,omitempty"`
// ImagePullSecrets define Secrets used to pull Image from registry
ImagePullSecrets ImagePullSecrets `json:"imagePullSecrets,omitempty"`
}
func (i *Image) Apply(pod *core.PodTemplateSpec, container *core.Container) error {
if i == nil {
return nil
}
container.Image = util.WithDefault(i.Image)
container.ImagePullPolicy = util.WithDefault(i.ImagePullPolicy)
for _, secret := range i.ImagePullSecrets {
if hasImagePullSecret(pod.Spec.ImagePullSecrets, secret) {
continue
}
pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, core.LocalObjectReference{
Name: secret,
})
}
return nil
}
func (i *Image) With(other *Image) *Image {
@ -65,7 +89,17 @@ func (i *Image) Validate() error {
return shared.WithErrors(
shared.PrefixResourceErrors("image", shared.ValidateRequired(i.Image, shared.ValidateImage)),
shared.PrefixResourceErrors("pullPolicy", shared.ValidateOptional(i.PullPolicy, shared.ValidatePullPolicy)),
shared.PrefixResourceErrors("pullSecrets", shared.ValidateList(i.PullSecrets, shared.ValidateResourceName)),
shared.PrefixResourceErrors("imagePullPolicy", shared.ValidateOptional(i.ImagePullPolicy, shared.ValidatePullPolicy)),
shared.PrefixResourceErrors("pullSecrets", shared.ValidateList(i.ImagePullSecrets, shared.ValidateResourceName)),
)
}
func hasImagePullSecret(secrets []core.LocalObjectReference, secret string) bool {
for _, sec := range secrets {
if sec.Name == secret {
return true
}
}
return false
}

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
// 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.
@ -18,7 +18,7 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
package resources
import (
core "k8s.io/api/core/v1"
@ -34,6 +34,16 @@ type Resources struct {
Resources *core.ResourceRequirements `json:"resources,omitempty"`
}
func (r *Resources) Apply(template *core.Container) error {
if r == nil {
return nil
}
template.Resources = util.WithDefault(r.Resources.DeepCopy())
return nil
}
func (r *Resources) With(newResources *Resources) *Resources {
if r == nil && newResources == nil {
return nil
@ -47,15 +57,15 @@ func (r *Resources) With(newResources *Resources) *Resources {
return r.DeepCopy()
}
return &Resources{Resources: util.NewType(resources.ApplyContainerResource(util.TypeOrDefault(r.GetResources()), util.TypeOrDefault(newResources.GetResources())))}
return &Resources{Resources: util.NewType(resources.ApplyContainerResource(r.GetResources(), newResources.GetResources()))}
}
func (r *Resources) GetResources() *core.ResourceRequirements {
func (r *Resources) GetResources() core.ResourceRequirements {
if r == nil || r.Resources == nil {
return nil
return core.ResourceRequirements{}
}
return r.Resources
return *r.Resources
}
func (r *Resources) Validate() error {

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// 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.
@ -18,18 +18,30 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
package resources
import core "k8s.io/api/core/v1"
import (
core "k8s.io/api/core/v1"
)
type SecurityContainer struct {
type Security struct {
// PodSecurityContext holds pod-level security attributes and common container settings.
// +doc/type: core.SecurityContext
// +doc/link: Kubernetes docs|https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
SecurityContext *core.SecurityContext `json:"securityContext,omitempty"`
}
func (s *SecurityContainer) With(other *SecurityContainer) *SecurityContainer {
func (s *Security) Apply(template *core.Container) error {
if s == nil {
return nil
}
template.SecurityContext = s.SecurityContext.DeepCopy()
return nil
}
func (s *Security) With(other *Security) *Security {
if s == nil && other == nil {
return nil
}
@ -38,19 +50,17 @@ func (s *SecurityContainer) With(other *SecurityContainer) *SecurityContainer {
return s.DeepCopy()
}
// TODO: Add fine graned merge
return other.DeepCopy()
}
func (s *SecurityContainer) GetSecurityContext() *core.SecurityContext {
func (s *Security) GetSecurityContext() core.SecurityContext {
if s == nil {
return nil
return core.SecurityContext{}
}
return s.SecurityContext
return *s.SecurityContext
}
func (s *SecurityContainer) Validate() error {
func (s *Security) Validate() error {
return nil
}

View file

@ -0,0 +1,153 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
//
// 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
//
// Code generated by deepcopy-gen. DO NOT EDIT.
package resources
import (
v1 "k8s.io/api/core/v1"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Environments) DeepCopyInto(out *Environments) {
*out = *in
if in.Env != nil {
in, out := &in.Env, &out.Env
*out = make([]v1.EnvVar, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.EnvFrom != nil {
in, out := &in.EnvFrom, &out.EnvFrom
*out = make([]v1.EnvFromSource, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Environments.
func (in *Environments) DeepCopy() *Environments {
if in == nil {
return nil
}
out := new(Environments)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Image) DeepCopyInto(out *Image) {
*out = *in
if in.Image != nil {
in, out := &in.Image, &out.Image
*out = new(string)
**out = **in
}
if in.ImagePullPolicy != nil {
in, out := &in.ImagePullPolicy, &out.ImagePullPolicy
*out = new(v1.PullPolicy)
**out = **in
}
if in.ImagePullSecrets != nil {
in, out := &in.ImagePullSecrets, &out.ImagePullSecrets
*out = make(ImagePullSecrets, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Image.
func (in *Image) DeepCopy() *Image {
if in == nil {
return nil
}
out := new(Image)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in ImagePullSecrets) DeepCopyInto(out *ImagePullSecrets) {
{
in := &in
*out = make(ImagePullSecrets, len(*in))
copy(*out, *in)
return
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImagePullSecrets.
func (in ImagePullSecrets) DeepCopy() ImagePullSecrets {
if in == nil {
return nil
}
out := new(ImagePullSecrets)
in.DeepCopyInto(out)
return *out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Resources) DeepCopyInto(out *Resources) {
*out = *in
if in.Resources != nil {
in, out := &in.Resources, &out.Resources
*out = new(v1.ResourceRequirements)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resources.
func (in *Resources) DeepCopy() *Resources {
if in == nil {
return nil
}
out := new(Resources)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Security) DeepCopyInto(out *Security) {
*out = *in
if in.SecurityContext != nil {
in, out := &in.SecurityContext, &out.SecurityContext
*out = new(v1.SecurityContext)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Security.
func (in *Security) DeepCopy() *Security {
if in == nil {
return nil
}
out := new(Security)
in.DeepCopyInto(out)
return out
}

View file

@ -0,0 +1,114 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
//
// 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
//
// Code generated by deepcopy-gen. DO NOT EDIT.
package container
import (
resources "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Container) DeepCopyInto(out *Container) {
*out = *in
if in.Security != nil {
in, out := &in.Security, &out.Security
*out = new(resources.Security)
(*in).DeepCopyInto(*out)
}
if in.Environments != nil {
in, out := &in.Environments, &out.Environments
*out = new(resources.Environments)
(*in).DeepCopyInto(*out)
}
if in.Image != nil {
in, out := &in.Image, &out.Image
*out = new(resources.Image)
(*in).DeepCopyInto(*out)
}
if in.Resources != nil {
in, out := &in.Resources, &out.Resources
*out = new(resources.Resources)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Container.
func (in *Container) DeepCopy() *Container {
if in == nil {
return nil
}
out := new(Container)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in Containers) DeepCopyInto(out *Containers) {
{
in := &in
*out = make(Containers, len(*in))
for key, val := range *in {
(*out)[key] = *val.DeepCopy()
}
return
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Containers.
func (in Containers) DeepCopy() Containers {
if in == nil {
return nil
}
out := new(Containers)
in.DeepCopyInto(out)
return *out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Generic) DeepCopyInto(out *Generic) {
*out = *in
if in.Security != nil {
in, out := &in.Security, &out.Security
*out = new(resources.Security)
(*in).DeepCopyInto(*out)
}
if in.Environments != nil {
in, out := &in.Environments, &out.Environments
*out = new(resources.Environments)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Generic.
func (in *Generic) DeepCopy() *Generic {
if in == nil {
return nil
}
out := new(Generic)
in.DeepCopyInto(out)
return out
}

View file

@ -0,0 +1,23 @@
//
// 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
//
// +k8s:deepcopy-gen=package
// +groupName=scheduler.arangodb.com
package v1alpha1

View file

@ -0,0 +1,86 @@
//
// 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 pod
import (
core "k8s.io/api/core/v1"
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod/resources"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
)
type Pod struct {
// Scheduling keeps the scheduling information
*schedulerPodResourcesApi.Scheduling `json:",inline"`
// Namespace keeps the Container layer Kernel namespace configuration
*schedulerPodResourcesApi.Namespace `json:",inline"`
// Security keeps the security settings for Pod
*schedulerPodResourcesApi.Security `json:",inline"`
}
func (a *Pod) Apply(template *core.PodTemplateSpec) error {
if a == nil {
return nil
}
return shared.WithErrors(
a.Scheduling.Apply(template),
a.Namespace.Apply(template),
a.Security.Apply(template),
)
}
func (a *Pod) GetSecurity() *schedulerPodResourcesApi.Security {
if a == nil {
return nil
}
return a.Security
}
func (a *Pod) GetScheduling() *schedulerPodResourcesApi.Scheduling {
if a == nil {
return nil
}
return a.Scheduling
}
func (a *Pod) GetContainerNamespace() *schedulerPodResourcesApi.Namespace {
if a == nil {
return nil
}
return a.Namespace
}
func (a *Pod) Validate() error {
if a == nil {
return nil
}
return shared.WithErrors(
a.Scheduling.Validate(),
a.Namespace.Validate(),
a.Security.Validate(),
)
}

View file

@ -0,0 +1,23 @@
//
// 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
//
// +k8s:deepcopy-gen=package
// +groupName=scheduler.arangodb.com
package pod

View file

@ -0,0 +1,23 @@
//
// 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
//
// +k8s:deepcopy-gen=package
// +groupName=scheduler.arangodb.com
package resources

View file

@ -0,0 +1,120 @@
//
// 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 resources
import (
core "k8s.io/api/core/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
)
type Namespace struct {
// HostNetwork requests Host network for this pod. Use the host's network namespace.
// If this option is set, the ports that will be used must be specified.
// +doc/default: false
HostNetwork *bool `json:"hostNetwork,omitempty" protobuf:"varint,11,opt,name=hostNetwork"`
// HostPID define to use the host's pid namespace.
// +doc/default: false
HostPID *bool `json:"hostPID,omitempty" protobuf:"varint,12,opt,name=hostPID"`
// HostIPC defines to use the host's ipc namespace.
// +doc/default: false
HostIPC *bool `json:"hostIPC,omitempty" protobuf:"varint,13,opt,name=hostIPC"`
// ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
// When this is set containers will be able to view and signal processes from other containers
// in the same pod, and the first process in each container will not be assigned PID 1.
// HostPID and ShareProcessNamespace cannot both be set.
// +doc/default: false
ShareProcessNamespace *bool `json:"shareProcessNamespace,omitempty" protobuf:"varint,27,opt,name=shareProcessNamespace"`
}
func (n *Namespace) Apply(template *core.PodTemplateSpec) error {
if n == nil {
return nil
}
template.Spec.HostNetwork = util.WithDefault(n.HostNetwork)
template.Spec.HostPID = util.WithDefault(n.HostPID)
template.Spec.HostIPC = util.WithDefault(n.HostIPC)
if v := n.ShareProcessNamespace; v != nil {
template.Spec.ShareProcessNamespace = util.NewType(*v)
} else {
template.Spec.ShareProcessNamespace = nil
}
return nil
}
func (n *Namespace) GetHostNetwork() *bool {
if n == nil || n.HostNetwork == nil {
return nil
}
return n.HostNetwork
}
func (n *Namespace) GetHostPID() *bool {
if n == nil || n.HostPID == nil {
return nil
}
return n.HostPID
}
func (n *Namespace) GetHostIPC() *bool {
if n == nil || n.HostIPC == nil {
return nil
}
return n.HostIPC
}
func (n *Namespace) GetShareProcessNamespace() *bool {
if n == nil {
return nil
}
return n.ShareProcessNamespace
}
func (n *Namespace) With(other *Namespace) *Namespace {
if n == nil && other == nil {
return nil
}
if n == nil {
return other.DeepCopy()
}
if other == nil {
return n.DeepCopy()
}
return &Namespace{
HostNetwork: util.First(other.HostNetwork, n.HostNetwork),
HostPID: util.First(other.HostPID, n.HostPID),
HostIPC: util.First(other.HostIPC, n.HostIPC),
ShareProcessNamespace: util.First(other.ShareProcessNamespace, n.ShareProcessNamespace),
}
}
func (n *Namespace) Validate() error {
return nil
}

View file

@ -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.
@ -18,13 +18,17 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
package resources
import (
core "k8s.io/api/core/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/affinity"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tolerations"
)
type SchedulingTolerations []core.Toleration
type Tolerations []core.Toleration
type Scheduling struct {
// NodeSelector is a selector that must be true for the workload to fit on a node.
@ -39,7 +43,7 @@ type Scheduling struct {
// Tolerations defines tolerations
// +doc/type: []core.Toleration
// +doc/link: Kubernetes docs|https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/
Tolerations SchedulingTolerations `json:"tolerations,omitempty"`
Tolerations Tolerations `json:"tolerations,omitempty"`
// SchedulerName specifies, the pod will be dispatched by specified scheduler.
// If not specified, the pod will be dispatched by default scheduler.
@ -47,6 +51,28 @@ type Scheduling struct {
SchedulerName *string `json:"schedulerName,omitempty"`
}
func (s *Scheduling) Apply(template *core.PodTemplateSpec) error {
if s == nil {
return nil
}
if len(s.NodeSelector) == 0 {
template.Spec.NodeSelector = nil
} else {
template.Spec.NodeSelector = map[string]string{}
for k, v := range s.NodeSelector {
template.Spec.NodeSelector[k] = v
}
}
template.Spec.Affinity = s.Affinity.DeepCopy()
template.Spec.Tolerations = s.Tolerations.DeepCopy()
template.Spec.SchedulerName = util.WithDefault(s.SchedulerName)
return nil
}
func (s *Scheduling) GetNodeSelector() map[string]string {
if s != nil {
return s.NodeSelector
@ -71,7 +97,7 @@ func (s *Scheduling) GetAffinity() *core.Affinity {
return nil
}
func (s *Scheduling) GetTolerations() SchedulingTolerations {
func (s *Scheduling) GetTolerations() Tolerations {
if s != nil {
return s.Tolerations
}
@ -79,6 +105,54 @@ func (s *Scheduling) GetTolerations() SchedulingTolerations {
return nil
}
func (s *Scheduling) With(other *Scheduling) *Scheduling {
if s == nil && other == nil {
return nil
}
if other == nil {
return s.DeepCopy()
}
if s == nil {
return other.DeepCopy()
}
current := s.DeepCopy()
new := other.DeepCopy()
// NodeSelector
if len(current.NodeSelector) == 0 {
current.NodeSelector = new.NodeSelector
} else if len(new.NodeSelector) > 0 {
for k, v := range new.NodeSelector {
other.NodeSelector[k] = v
}
}
// SchedulerName
if new.SchedulerName != nil {
other.SchedulerName = new.SchedulerName
}
// Tolerations
new.Tolerations = tolerations.AddTolerationsIfNotFound(new.Tolerations, other.Tolerations...)
// Affinity
current.Affinity = affinity.Merge(current.Affinity, new.Affinity)
// return
if current.Affinity == nil &&
current.SchedulerName == nil &&
len(current.Tolerations) == 0 &&
len(current.NodeSelector) == 0 {
return nil
}
return current
}
func (s *Scheduling) Validate() error {
return nil
}

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// 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.
@ -18,18 +18,30 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1
package resources
import core "k8s.io/api/core/v1"
import (
core "k8s.io/api/core/v1"
)
type SecurityPod struct {
type Security struct {
// PodSecurityContext holds pod-level security attributes and common container settings.
// +doc/type: core.PodSecurityContext
// +doc/link: Kubernetes docs|https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
PodSecurityContext *core.PodSecurityContext `json:"podSecurityContext,omitempty"`
}
func (s *SecurityPod) GetPodSecurityContext() *core.PodSecurityContext {
func (s *Security) Apply(template *core.PodTemplateSpec) error {
if s == nil {
return nil
}
template.Spec.SecurityContext = s.PodSecurityContext.DeepCopy()
return nil
}
func (s *Security) GetSecurityContext() *core.PodSecurityContext {
if s == nil {
return nil
}
@ -37,6 +49,22 @@ func (s *SecurityPod) GetPodSecurityContext() *core.PodSecurityContext {
return s.PodSecurityContext
}
func (s *SecurityPod) Validate() error {
func (s *Security) With(newResources *Security) *Security {
if s == nil && newResources == nil {
return nil
}
if s == nil {
return newResources.DeepCopy()
}
if newResources == nil {
return s.DeepCopy()
}
return nil
}
func (s *Security) Validate() error {
return nil
}

View file

@ -0,0 +1,149 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
//
// 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
//
// Code generated by deepcopy-gen. DO NOT EDIT.
package resources
import (
v1 "k8s.io/api/core/v1"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Namespace) DeepCopyInto(out *Namespace) {
*out = *in
if in.HostNetwork != nil {
in, out := &in.HostNetwork, &out.HostNetwork
*out = new(bool)
**out = **in
}
if in.HostPID != nil {
in, out := &in.HostPID, &out.HostPID
*out = new(bool)
**out = **in
}
if in.HostIPC != nil {
in, out := &in.HostIPC, &out.HostIPC
*out = new(bool)
**out = **in
}
if in.ShareProcessNamespace != nil {
in, out := &in.ShareProcessNamespace, &out.ShareProcessNamespace
*out = new(bool)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Namespace.
func (in *Namespace) DeepCopy() *Namespace {
if in == nil {
return nil
}
out := new(Namespace)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Scheduling) DeepCopyInto(out *Scheduling) {
*out = *in
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Affinity != nil {
in, out := &in.Affinity, &out.Affinity
*out = new(v1.Affinity)
(*in).DeepCopyInto(*out)
}
if in.Tolerations != nil {
in, out := &in.Tolerations, &out.Tolerations
*out = make(Tolerations, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.SchedulerName != nil {
in, out := &in.SchedulerName, &out.SchedulerName
*out = new(string)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Scheduling.
func (in *Scheduling) DeepCopy() *Scheduling {
if in == nil {
return nil
}
out := new(Scheduling)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Security) DeepCopyInto(out *Security) {
*out = *in
if in.PodSecurityContext != nil {
in, out := &in.PodSecurityContext, &out.PodSecurityContext
*out = new(v1.PodSecurityContext)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Security.
func (in *Security) DeepCopy() *Security {
if in == nil {
return nil
}
out := new(Security)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in Tolerations) DeepCopyInto(out *Tolerations) {
{
in := &in
*out = make(Tolerations, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
return
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Tolerations.
func (in Tolerations) DeepCopy() Tolerations {
if in == nil {
return nil
}
out := new(Tolerations)
in.DeepCopyInto(out)
return *out
}

View file

@ -0,0 +1,61 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
//
// 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
//
// Code generated by deepcopy-gen. DO NOT EDIT.
package pod
import (
resources "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod/resources"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Pod) DeepCopyInto(out *Pod) {
*out = *in
if in.Scheduling != nil {
in, out := &in.Scheduling, &out.Scheduling
*out = new(resources.Scheduling)
(*in).DeepCopyInto(*out)
}
if in.Namespace != nil {
in, out := &in.Namespace, &out.Namespace
*out = new(resources.Namespace)
(*in).DeepCopyInto(*out)
}
if in.Security != nil {
in, out := &in.Security, &out.Security
*out = new(resources.Security)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Pod.
func (in *Pod) DeepCopy() *Pod {
if in == nil {
return nil
}
out := new(Pod)
in.DeepCopyInto(out)
return out
}

View file

@ -0,0 +1,53 @@
//
// 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 v1alpha1
import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/arangodb/kube-arangodb/pkg/apis/scheduler"
)
const (
ArangoSchedulerVersion = "v1alpha1"
)
var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
SchemeGroupVersion = schema.GroupVersion{Group: scheduler.ArangoSchedulerGroupName,
Version: ArangoSchedulerVersion}
)
// Resource gets an ArangoCluster GroupResource for a specified resource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
func addKnownTypes(s *runtime.Scheme) error {
s.AddKnownTypes(SchemeGroupVersion)
meta.AddToGroupVersion(s, SchemeGroupVersion)
return nil
}

View file

@ -0,0 +1,26 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
//
// 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
//
// Code generated by deepcopy-gen. DO NOT EDIT.
package v1alpha1

View file

@ -1,76 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2023 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 v1
type ContainerNamespace struct {
// HostNetwork requests Host network for this pod. Use the host's network namespace.
// If this option is set, the ports that will be used must be specified.
// +doc/default: false
HostNetwork bool `json:"hostNetwork,omitempty" protobuf:"varint,11,opt,name=hostNetwork"`
// HostPID define to use the host's pid namespace.
// +doc/default: false
HostPID bool `json:"hostPID,omitempty" protobuf:"varint,12,opt,name=hostPID"`
// HostIPC defines to use the host's ipc namespace.
// +doc/default: false
HostIPC bool `json:"hostIPC,omitempty" protobuf:"varint,13,opt,name=hostIPC"`
// ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
// When this is set containers will be able to view and signal processes from other containers
// in the same pod, and the first process in each container will not be assigned PID 1.
// HostPID and ShareProcessNamespace cannot both be set.
// +doc/default: false
ShareProcessNamespace *bool `json:"shareProcessNamespace,omitempty" protobuf:"varint,27,opt,name=shareProcessNamespace"`
}
func (c *ContainerNamespace) GetHostNetwork() bool {
if c == nil {
return false
}
return c.HostNetwork
}
func (c *ContainerNamespace) GetHostPID() bool {
if c == nil {
return false
}
return c.HostPID
}
func (c *ContainerNamespace) GetHostIPC() bool {
if c == nil {
return false
}
return c.HostIPC
}
func (c *ContainerNamespace) GetShareProcessNamespace() *bool {
if c == nil {
return nil
}
return c.ShareProcessNamespace
}
func (c *ContainerNamespace) Validate() error {
return nil
}

View file

@ -1,104 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2023 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 v1
import (
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
)
type ContainerTemplate struct {
// Image define default image used for the job
*Image `json:",inline"`
// Resources define resources assigned to the pod
*Resources `json:",inline"`
// SecurityContainer keeps the security settings for Container
*SecurityContainer `json:",inline"`
// Environments keeps the environment variables for Container
*Environments `json:",inline"`
}
func (a *ContainerTemplate) With(other *ContainerTemplate) *ContainerTemplate {
if a == nil && other == nil {
return nil
}
if a == nil {
return other.DeepCopy()
}
if other == nil {
return a.DeepCopy()
}
return &ContainerTemplate{
Image: a.GetImage().With(other.GetImage()),
Resources: a.GetResources().With(other.GetResources()),
SecurityContainer: a.GetSecurityContainer().With(other.GetSecurityContainer()),
Environments: a.GetEnvironments().With(other.GetEnvironments()),
}
}
func (a *ContainerTemplate) GetImage() *Image {
if a == nil || a.Image == nil {
return nil
}
return a.Image
}
func (a *ContainerTemplate) GetSecurityContainer() *SecurityContainer {
if a == nil || a.SecurityContainer == nil {
return nil
}
return a.SecurityContainer
}
func (a *ContainerTemplate) GetEnvironments() *Environments {
if a == nil || a.Environments == nil {
return nil
}
return a.Environments
}
func (a *ContainerTemplate) GetResources() *Resources {
if a == nil || a.Resources == nil {
return nil
}
return a.Resources
}
func (a *ContainerTemplate) Validate() error {
if a == nil {
return nil
}
return shared.WithErrors(
a.GetImage().Validate(),
a.GetResources().Validate(),
a.GetSecurityContainer().Validate(),
a.GetEnvironments().Validate(),
)
}

View file

@ -1,69 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2023 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 v1
import shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
type PodTemplate struct {
// Scheduling keeps the scheduling information
*Scheduling `json:",inline"`
// ContainerNamespace keeps the Container layer Kernel namespace configuration
*ContainerNamespace `json:",inline"`
// SecurityPod keeps the security settings for Pod
*SecurityPod `json:",inline"`
}
func (a *PodTemplate) GetSecurityPod() *SecurityPod {
if a == nil {
return nil
}
return a.SecurityPod
}
func (a *PodTemplate) GetScheduling() *Scheduling {
if a == nil {
return nil
}
return a.Scheduling
}
func (a *PodTemplate) GetContainerNamespace() *ContainerNamespace {
if a == nil {
return nil
}
return a.ContainerNamespace
}
func (a *PodTemplate) Validate() error {
if a == nil {
return nil
}
return shared.WithErrors(
a.GetScheduling().Validate(),
a.GetContainerNamespace().Validate(),
a.GetSecurityPod().Validate(),
)
}

View file

@ -26,97 +26,9 @@
package v1
import (
corev1 "k8s.io/api/core/v1"
types "k8s.io/apimachinery/pkg/types"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ContainerNamespace) DeepCopyInto(out *ContainerNamespace) {
*out = *in
if in.ShareProcessNamespace != nil {
in, out := &in.ShareProcessNamespace, &out.ShareProcessNamespace
*out = new(bool)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerNamespace.
func (in *ContainerNamespace) DeepCopy() *ContainerNamespace {
if in == nil {
return nil
}
out := new(ContainerNamespace)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ContainerTemplate) DeepCopyInto(out *ContainerTemplate) {
*out = *in
if in.Image != nil {
in, out := &in.Image, &out.Image
*out = new(Image)
(*in).DeepCopyInto(*out)
}
if in.Resources != nil {
in, out := &in.Resources, &out.Resources
*out = new(Resources)
(*in).DeepCopyInto(*out)
}
if in.SecurityContainer != nil {
in, out := &in.SecurityContainer, &out.SecurityContainer
*out = new(SecurityContainer)
(*in).DeepCopyInto(*out)
}
if in.Environments != nil {
in, out := &in.Environments, &out.Environments
*out = new(Environments)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerTemplate.
func (in *ContainerTemplate) DeepCopy() *ContainerTemplate {
if in == nil {
return nil
}
out := new(ContainerTemplate)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Environments) DeepCopyInto(out *Environments) {
*out = *in
if in.Env != nil {
in, out := &in.Env, &out.Env
*out = make([]corev1.EnvVar, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.EnvFrom != nil {
in, out := &in.EnvFrom, &out.EnvFrom
*out = make([]corev1.EnvFromSource, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Environments.
func (in *Environments) DeepCopy() *Environments {
if in == nil {
return nil
}
out := new(Environments)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in HashList) DeepCopyInto(out *HashList) {
{
@ -137,37 +49,6 @@ func (in HashList) DeepCopy() HashList {
return *out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Image) DeepCopyInto(out *Image) {
*out = *in
if in.Image != nil {
in, out := &in.Image, &out.Image
*out = new(string)
**out = **in
}
if in.PullPolicy != nil {
in, out := &in.PullPolicy, &out.PullPolicy
*out = new(corev1.PullPolicy)
**out = **in
}
if in.PullSecrets != nil {
in, out := &in.PullSecrets, &out.PullSecrets
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Image.
func (in *Image) DeepCopy() *Image {
if in == nil {
return nil
}
out := new(Image)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Object) DeepCopyInto(out *Object) {
*out = *in
@ -194,162 +75,6 @@ func (in *Object) DeepCopy() *Object {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *PodTemplate) DeepCopyInto(out *PodTemplate) {
*out = *in
if in.Scheduling != nil {
in, out := &in.Scheduling, &out.Scheduling
*out = new(Scheduling)
(*in).DeepCopyInto(*out)
}
if in.ContainerNamespace != nil {
in, out := &in.ContainerNamespace, &out.ContainerNamespace
*out = new(ContainerNamespace)
(*in).DeepCopyInto(*out)
}
if in.SecurityPod != nil {
in, out := &in.SecurityPod, &out.SecurityPod
*out = new(SecurityPod)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodTemplate.
func (in *PodTemplate) DeepCopy() *PodTemplate {
if in == nil {
return nil
}
out := new(PodTemplate)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Resources) DeepCopyInto(out *Resources) {
*out = *in
if in.Resources != nil {
in, out := &in.Resources, &out.Resources
*out = new(corev1.ResourceRequirements)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resources.
func (in *Resources) DeepCopy() *Resources {
if in == nil {
return nil
}
out := new(Resources)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Scheduling) DeepCopyInto(out *Scheduling) {
*out = *in
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Affinity != nil {
in, out := &in.Affinity, &out.Affinity
*out = new(corev1.Affinity)
(*in).DeepCopyInto(*out)
}
if in.Tolerations != nil {
in, out := &in.Tolerations, &out.Tolerations
*out = make(SchedulingTolerations, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.SchedulerName != nil {
in, out := &in.SchedulerName, &out.SchedulerName
*out = new(string)
**out = **in
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Scheduling.
func (in *Scheduling) DeepCopy() *Scheduling {
if in == nil {
return nil
}
out := new(Scheduling)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in SchedulingTolerations) DeepCopyInto(out *SchedulingTolerations) {
{
in := &in
*out = make(SchedulingTolerations, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
return
}
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SchedulingTolerations.
func (in SchedulingTolerations) DeepCopy() SchedulingTolerations {
if in == nil {
return nil
}
out := new(SchedulingTolerations)
in.DeepCopyInto(out)
return *out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SecurityContainer) DeepCopyInto(out *SecurityContainer) {
*out = *in
if in.SecurityContext != nil {
in, out := &in.SecurityContext, &out.SecurityContext
*out = new(corev1.SecurityContext)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecurityContainer.
func (in *SecurityContainer) DeepCopy() *SecurityContainer {
if in == nil {
return nil
}
out := new(SecurityContainer)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *SecurityPod) DeepCopyInto(out *SecurityPod) {
*out = *in
if in.PodSecurityContext != nil {
in, out := &in.PodSecurityContext, &out.PodSecurityContext
*out = new(corev1.PodSecurityContext)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecurityPod.
func (in *SecurityPod) DeepCopy() *SecurityPod {
if in == nil {
return nil
}
out := new(SecurityPod)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServiceAccount) DeepCopyInto(out *ServiceAccount) {
*out = *in

View file

@ -7,7 +7,6 @@ v1alpha1:
description: Deployment specifies how the ML extension will be deployed into cluster
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -307,23 +306,16 @@ v1alpha1:
type: object
type: object
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -386,7 +378,6 @@ v1alpha1:
description: Prediction defines how Prediction workload will be deployed
properties:
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -433,7 +424,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -458,22 +448,18 @@ v1alpha1:
description: GPU defined if GPU Jobs are enabled for component. In use only for ArangoMLExtensionSpecDeploymentComponentPrediction and ArangoMLExtensionSpecDeploymentComponentTraining
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
port:
description: Port defines on which port the container will be listening for connections
format: int32
type: integer
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -492,7 +478,6 @@ v1alpha1:
type: object
type: object
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -556,7 +541,6 @@ v1alpha1:
description: Project defines how Project workload will be deployed
properties:
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -603,7 +587,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -628,22 +611,18 @@ v1alpha1:
description: GPU defined if GPU Jobs are enabled for component. In use only for ArangoMLExtensionSpecDeploymentComponentPrediction and ArangoMLExtensionSpecDeploymentComponentTraining
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
port:
description: Port defines on which port the container will be listening for connections
format: int32
type: integer
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -662,7 +641,6 @@ v1alpha1:
type: object
type: object
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -727,9 +705,6 @@ v1alpha1:
format: int32
type: integer
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
service:
description: Service defines how components will be exposed
@ -744,14 +719,8 @@ v1alpha1:
type: string
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -771,7 +740,6 @@ v1alpha1:
description: Training defines how Training workload will be deployed
properties:
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -818,7 +786,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -843,22 +810,18 @@ v1alpha1:
description: GPU defined if GPU Jobs are enabled for component. In use only for ArangoMLExtensionSpecDeploymentComponentPrediction and ArangoMLExtensionSpecDeploymentComponentTraining
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
port:
description: Port defines on which port the container will be listening for connections
format: int32
type: integer
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -877,7 +840,6 @@ v1alpha1:
type: object
type: object
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -939,13 +901,17 @@ v1alpha1:
type: object
type: object
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
init:
description: ArangoMLExtensionTemplate define Init job specification
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -1245,7 +1211,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -1292,7 +1257,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -1314,26 +1278,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -1392,16 +1354,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -1420,12 +1373,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -1485,14 +1434,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -1519,7 +1462,6 @@ v1alpha1:
description: CPU defines templates for CPU jobs
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -1819,7 +1761,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -1866,7 +1807,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -1888,26 +1828,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -1966,16 +1904,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -1994,12 +1923,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -2059,14 +1984,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -2087,7 +2006,6 @@ v1alpha1:
description: GPU defines templates for GPU jobs
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -2387,7 +2305,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -2434,7 +2351,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -2456,26 +2372,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -2534,16 +2448,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -2562,12 +2467,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -2627,14 +2528,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -2659,7 +2554,6 @@ v1alpha1:
description: CPU defines templates for CPU jobs
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -2959,7 +2853,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -3006,7 +2899,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -3028,26 +2920,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -3106,16 +2996,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -3134,12 +3015,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -3199,14 +3076,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -3227,7 +3098,6 @@ v1alpha1:
description: GPU defines templates for GPU jobs
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -3527,7 +3397,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -3574,7 +3443,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -3596,26 +3464,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -3674,16 +3540,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -3702,12 +3559,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -3767,14 +3620,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -3799,7 +3646,6 @@ v1alpha1:
description: CPU defines templates for CPU jobs
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -4099,7 +3945,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -4146,7 +3991,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -4168,26 +4012,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -4246,16 +4088,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -4274,12 +4107,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -4339,14 +4168,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -4367,7 +4190,6 @@ v1alpha1:
description: GPU defines templates for GPU jobs
properties:
affinity:
description: Affinity defines scheduling constraints for workload
properties:
nodeAffinity:
properties:
@ -4667,7 +4489,6 @@ v1alpha1:
type: object
type: object
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -4714,7 +4535,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -4736,26 +4556,24 @@ v1alpha1:
type: object
type: array
hostIPC:
description: HostIPC defines to use the host's ipc namespace.
type: boolean
hostNetwork:
description: |-
HostNetwork requests Host network for this pod. Use the host's network namespace.
If this option is set, the ports that will be used must be specified.
type: boolean
hostPID:
description: HostPID define to use the host's pid namespace.
type: boolean
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
nodeSelector:
additionalProperties:
type: string
description: NodeSelector is a selector that must be true for the workload to fit on a node.
type: object
podSecurityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
fsGroup:
format: int64
@ -4814,16 +4632,7 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -4842,12 +4651,8 @@ v1alpha1:
type: object
type: object
schedulerName:
description: |-
SchedulerName specifies, the pod will be dispatched by specified scheduler.
If not specified, the pod will be dispatched by default scheduler.
type: string
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean
@ -4907,14 +4712,8 @@ v1alpha1:
type: object
type: object
shareProcessNamespace:
description: |-
ShareProcessNamespace defines to share a single process namespace between all of the containers in a pod.
When this is set containers will be able to view and signal processes from other containers
in the same pod, and the first process in each container will not be assigned PID 1.
HostPID and ShareProcessNamespace cannot both be set.
type: boolean
tolerations:
description: Tolerations defines tolerations
items:
properties:
effect:
@ -4947,14 +4746,6 @@ v1alpha1:
type: string
type: object
type: object
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
storage:
description: Storage specifies the ArangoMLStorage used within Extension
properties:

View file

@ -73,7 +73,6 @@ v1alpha1:
format: int32
type: integer
env:
description: Env keeps the information about environment variables provided to the container
items:
properties:
name:
@ -120,7 +119,6 @@ v1alpha1:
type: object
type: array
envFrom:
description: EnvFrom keeps the information about environment variable sources provided to the container
items:
properties:
configMapRef:
@ -142,22 +140,18 @@ v1alpha1:
type: object
type: array
image:
description: Image define image details
type: string
imagePullPolicy:
type: string
imagePullSecrets:
items:
type: string
type: array
listenPort:
description: ListenPort defines on which port the sidecar container will be listening for connections
format: int32
type: integer
pullPolicy:
description: PullPolicy define Image pull policy
type: string
pullSecrets:
description: PullSecrets define Secrets used to pull Image from registry
items:
type: string
type: array
resources:
description: Resources holds resource requests & limits for container
properties:
claims:
items:
@ -176,7 +170,6 @@ v1alpha1:
type: object
type: object
securityContext:
description: PodSecurityContext holds pod-level security attributes and common container settings.
properties:
allowPrivilegeEscalation:
type: boolean

View file

@ -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.
@ -53,6 +53,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/probes"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
@ -892,7 +893,7 @@ func addLifecycle(name string, uuidRequired bool, license string, group api.Serv
p.Spec.Containers[0].VolumeMounts = append(p.Spec.Containers[0].VolumeMounts, k8sutil.LifecycleVolumeMount())
}
if _, ok := k8sutil.GetAnyContainerByName(p.Spec.InitContainers, "init-lifecycle"); !ok {
if _, ok := container.GetAnyContainerByName(p.Spec.InitContainers, "init-lifecycle"); !ok {
p.Spec.InitContainers = append(
[]core.Container{createTestLifecycleContainer(emptyResources)},
p.Spec.InitContainers...,
@ -900,7 +901,7 @@ func addLifecycle(name string, uuidRequired bool, license string, group api.Serv
}
}
if _, ok := k8sutil.GetAnyContainerByName(p.Spec.InitContainers, "uuid"); !ok {
if _, ok := container.GetAnyContainerByName(p.Spec.InitContainers, "uuid"); !ok {
binaryPath, _ := os.Executable()
p.Spec.InitContainers = append(
[]core.Container{

View file

@ -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.
@ -37,6 +37,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/handlers/utils"
"github.com/arangodb/kube-arangodb/pkg/logging"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/affinity"
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
@ -358,30 +359,30 @@ func (i *ImageUpdatePod) GetServiceAccountName() string {
}
func (i *ImageUpdatePod) GetPodAntiAffinity() *core.PodAntiAffinity {
a := core.PodAntiAffinity{}
a := &core.PodAntiAffinity{}
pod.AppendPodAntiAffinityDefault(i, &a)
pod.AppendPodAntiAffinityDefault(i, a)
pod.MergePodAntiAffinity(&a, i.spec.ID.Get().AntiAffinity)
a = affinity.MergePodAntiAffinity(a, i.spec.ID.Get().AntiAffinity)
return pod.ReturnPodAntiAffinityOrNil(a)
return affinity.OptionalPodAntiAffinity(a)
}
func (i *ImageUpdatePod) GetPodAffinity() *core.PodAffinity {
a := core.PodAffinity{}
a := &core.PodAffinity{}
pod.MergePodAffinity(&a, i.spec.ID.Get().Affinity)
a = affinity.MergePodAffinity(a, i.spec.ID.Get().Affinity)
return pod.ReturnPodAffinityOrNil(a)
return affinity.OptionalPodAffinity(a)
}
func (i *ImageUpdatePod) GetNodeAffinity() *core.NodeAffinity {
a := core.NodeAffinity{}
pod.AppendArchSelector(&a, i.spec.Architecture.AsNodeSelectorRequirement())
a := &core.NodeAffinity{}
pod.AppendArchSelector(a, i.spec.Architecture.AsNodeSelectorRequirement())
pod.MergeNodeAffinity(&a, i.spec.ID.Get().NodeAffinity)
a = affinity.MergeNodeAffinity(a, i.spec.ID.Get().NodeAffinity)
return pod.ReturnNodeAffinityOrNil(a)
return affinity.OptionalNodeAffinity(a)
}
func (i *ImageUpdatePod) Validate(_ interfaces.Inspector) error {

View file

@ -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.
@ -93,89 +93,3 @@ func AppendAffinityWithRole(p interfaces.PodCreator, a *core.PodAffinity, role s
},
})
}
func MergePodAntiAffinity(a, b *core.PodAntiAffinity) {
if a == nil || b == nil {
return
}
a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution,
b.PreferredDuringSchedulingIgnoredDuringExecution...)
a.RequiredDuringSchedulingIgnoredDuringExecution = append(a.RequiredDuringSchedulingIgnoredDuringExecution,
b.RequiredDuringSchedulingIgnoredDuringExecution...)
}
func MergePodAffinity(a, b *core.PodAffinity) {
if a == nil || b == nil {
return
}
a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution,
b.PreferredDuringSchedulingIgnoredDuringExecution...)
a.RequiredDuringSchedulingIgnoredDuringExecution = append(a.RequiredDuringSchedulingIgnoredDuringExecution,
b.RequiredDuringSchedulingIgnoredDuringExecution...)
}
func MergeNodeAffinity(a, b *core.NodeAffinity) {
if a == nil || b == nil {
return
}
a.PreferredDuringSchedulingIgnoredDuringExecution = append(a.PreferredDuringSchedulingIgnoredDuringExecution,
b.PreferredDuringSchedulingIgnoredDuringExecution...)
var newSelectorTerms []core.NodeSelectorTerm
if b.RequiredDuringSchedulingIgnoredDuringExecution == nil || len(b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 {
newSelectorTerms = a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
} else if a.RequiredDuringSchedulingIgnoredDuringExecution == nil || len(a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms) == 0 {
newSelectorTerms = b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms
} else {
for _, aTerms := range a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
for _, bTerms := range b.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
term := aTerms.DeepCopy()
if len(bTerms.MatchExpressions) != 0 {
term.MatchExpressions = append(term.MatchExpressions, bTerms.MatchExpressions...)
}
if len(bTerms.MatchFields) != 0 {
term.MatchFields = append(term.MatchFields, bTerms.MatchFields...)
}
newSelectorTerms = append(newSelectorTerms, *term)
}
}
}
a.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms = newSelectorTerms
}
func ReturnPodAffinityOrNil(a core.PodAffinity) *core.PodAffinity {
if len(a.RequiredDuringSchedulingIgnoredDuringExecution) > 0 || len(a.PreferredDuringSchedulingIgnoredDuringExecution) > 0 {
return &a
}
return nil
}
func ReturnPodAntiAffinityOrNil(a core.PodAntiAffinity) *core.PodAntiAffinity {
if len(a.RequiredDuringSchedulingIgnoredDuringExecution) > 0 || len(a.PreferredDuringSchedulingIgnoredDuringExecution) > 0 {
return &a
}
return nil
}
func ReturnNodeAffinityOrNil(a core.NodeAffinity) *core.NodeAffinity {
if len(a.PreferredDuringSchedulingIgnoredDuringExecution) > 0 {
return &a
}
if s := a.RequiredDuringSchedulingIgnoredDuringExecution; s != nil {
if len(s.NodeSelectorTerms) > 0 {
return &a
}
}
return nil
}

View file

@ -31,6 +31,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/rotation"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
)
func newRuntimeContainerImageUpdateAction(action api.Action, actionCtx ActionContext) Action {
@ -285,13 +286,13 @@ func (a actionRuntimeContainerImageUpdate) CheckProgress(ctx context.Context) (b
return true, false, nil
}
cspec, ok := k8sutil.GetContainerByName(pod, name)
cspec, ok := container.GetContainerByName(pod, name)
if !ok {
a.log.Info("Unable to find container spec")
return true, false, nil
}
cstatus, ok := k8sutil.GetContainerStatusByName(pod, name)
cstatus, ok := container.GetContainerStatusByName(pod, name)
if !ok {
a.log.Info("Unable to find container status")
return true, false, nil

View file

@ -35,6 +35,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/arangodb/kube-arangodb/pkg/deployment/topology"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/affinity"
"github.com/arangodb/kube-arangodb/pkg/util/collection"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
@ -367,37 +368,37 @@ func (m *MemberArangoDPod) GetImagePullSecrets() []string {
}
func (m *MemberArangoDPod) GetPodAntiAffinity() *core.PodAntiAffinity {
a := core.PodAntiAffinity{}
a := &core.PodAntiAffinity{}
pod.AppendPodAntiAffinityDefault(m, &a)
pod.AppendPodAntiAffinityDefault(m, a)
pod.MergePodAntiAffinity(&a, topology.GetTopologyAffinityRules(m.context.GetName(), m.deploymentStatus, m.group, m.status).PodAntiAffinity)
a = affinity.MergePodAntiAffinity(a, topology.GetTopologyAffinityRules(m.context.GetName(), m.deploymentStatus, m.group, m.status).PodAntiAffinity)
pod.MergePodAntiAffinity(&a, m.groupSpec.AntiAffinity)
a = affinity.MergePodAntiAffinity(a, m.groupSpec.AntiAffinity)
return pod.ReturnPodAntiAffinityOrNil(a)
return affinity.OptionalPodAntiAffinity(a)
}
func (m *MemberArangoDPod) GetPodAffinity() *core.PodAffinity {
a := core.PodAffinity{}
a := &core.PodAffinity{}
pod.MergePodAffinity(&a, m.groupSpec.Affinity)
a = affinity.MergePodAffinity(a, m.groupSpec.Affinity)
pod.MergePodAffinity(&a, topology.GetTopologyAffinityRules(m.context.GetName(), m.deploymentStatus, m.group, m.status).PodAffinity)
a = affinity.MergePodAffinity(a, topology.GetTopologyAffinityRules(m.context.GetName(), m.deploymentStatus, m.group, m.status).PodAffinity)
return pod.ReturnPodAffinityOrNil(a)
return affinity.OptionalPodAffinity(a)
}
func (m *MemberArangoDPod) GetNodeAffinity() *core.NodeAffinity {
a := core.NodeAffinity{}
a := &core.NodeAffinity{}
pod.AppendArchSelector(&a, m.status.Architecture.Default(m.spec.Architecture.GetDefault()).AsNodeSelectorRequirement())
pod.AppendArchSelector(a, m.status.Architecture.Default(m.spec.Architecture.GetDefault()).AsNodeSelectorRequirement())
pod.MergeNodeAffinity(&a, m.groupSpec.NodeAffinity)
a = affinity.MergeNodeAffinity(a, m.groupSpec.NodeAffinity)
pod.MergeNodeAffinity(&a, topology.GetTopologyAffinityRules(m.context.GetName(), m.deploymentStatus, m.group, m.status).NodeAffinity)
a = affinity.MergeNodeAffinity(a, topology.GetTopologyAffinityRules(m.context.GetName(), m.deploymentStatus, m.group, m.status).NodeAffinity)
return pod.ReturnNodeAffinityOrNil(a)
return affinity.OptionalNodeAffinity(a)
}
func (m *MemberArangoDPod) GetNodeSelector() map[string]string {

View file

@ -36,6 +36,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
"github.com/arangodb/kube-arangodb/pkg/deployment/pod"
"github.com/arangodb/kube-arangodb/pkg/handlers/utils"
"github.com/arangodb/kube-arangodb/pkg/util/affinity"
"github.com/arangodb/kube-arangodb/pkg/util/collection"
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
@ -227,35 +228,35 @@ func (m *MemberSyncPod) GetImagePullSecrets() []string {
}
func (m *MemberSyncPod) GetPodAntiAffinity() *core.PodAntiAffinity {
a := core.PodAntiAffinity{}
a := &core.PodAntiAffinity{}
pod.AppendPodAntiAffinityDefault(m, &a)
pod.AppendPodAntiAffinityDefault(m, a)
pod.MergePodAntiAffinity(&a, m.groupSpec.AntiAffinity)
a = affinity.MergePodAntiAffinity(a, m.groupSpec.AntiAffinity)
return pod.ReturnPodAntiAffinityOrNil(a)
return affinity.OptionalPodAntiAffinity(a)
}
func (m *MemberSyncPod) GetPodAffinity() *core.PodAffinity {
a := core.PodAffinity{}
a := &core.PodAffinity{}
if m.group == api.ServerGroupSyncWorkers {
pod.AppendAffinityWithRole(m, &a, api.ServerGroupDBServers.AsRole())
pod.AppendAffinityWithRole(m, a, api.ServerGroupDBServers.AsRole())
}
pod.MergePodAffinity(&a, m.groupSpec.Affinity)
a = affinity.MergePodAffinity(a, m.groupSpec.Affinity)
return pod.ReturnPodAffinityOrNil(a)
return affinity.OptionalPodAffinity(a)
}
func (m *MemberSyncPod) GetNodeAffinity() *core.NodeAffinity {
a := core.NodeAffinity{}
a := &core.NodeAffinity{}
pod.AppendArchSelector(&a, m.memberStatus.Architecture.Default(m.spec.Architecture.GetDefault()).AsNodeSelectorRequirement())
pod.AppendArchSelector(a, m.memberStatus.Architecture.Default(m.spec.Architecture.GetDefault()).AsNodeSelectorRequirement())
pod.MergeNodeAffinity(&a, m.groupSpec.NodeAffinity)
a = affinity.MergeNodeAffinity(a, m.groupSpec.NodeAffinity)
return pod.ReturnNodeAffinityOrNil(a)
return affinity.OptionalNodeAffinity(a)
}
func (m *MemberSyncPod) GetNodeSelector() map[string]string {

View file

@ -39,6 +39,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/info"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
@ -60,7 +61,7 @@ const (
)
func (r *Resources) handleRestartedPod(pod *core.Pod, memberStatus *api.MemberStatus, wasTerminated, markAsTerminated *bool) {
containerStatus, exist := k8sutil.GetContainerStatusByName(pod, api.ServerGroupReservedContainerNameServer)
containerStatus, exist := container.GetContainerStatusByName(pod, api.ServerGroupReservedContainerNameServer)
if exist && containerStatus.State.Terminated != nil {
// do not record termination time again in the code below
*wasTerminated = true
@ -177,11 +178,11 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
}
if markAsTerminated && memberStatus.Conditions.Update(api.ConditionTypeTerminated, true, "Pod Failed", "") {
if containers := k8sutil.GetFailedContainerNames(pod.Status.InitContainerStatuses); len(containers) > 0 {
for _, container := range containers {
switch container {
if containers := container.GetFailedContainerNames(pod.Status.InitContainerStatuses); len(containers) > 0 {
for id := range containers {
switch containers[id] {
case api.ServerGroupReservedInitContainerNameVersionCheck:
if c, ok := k8sutil.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, container); ok {
if c, ok := container.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok {
if t := c.State.Terminated; t != nil && t.ExitCode == 11 {
memberStatus.Upgrade = true
updateMemberStatusNeeded = true
@ -191,11 +192,11 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
memberStatus.Conditions.Update(api.ConditionTypeUpgradeFailed, true, "Upgrade Failed", "")
}
if c, ok := k8sutil.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, container); ok {
if c, ok := container.GetAnyContainerStatusByName(pod.Status.InitContainerStatuses, containers[id]); ok {
if t := c.State.Terminated; t != nil && t.ExitCode != 0 {
log.Str("member", memberStatus.ID).
Str("pod", pod.GetName()).
Str("container", container).
Str("container", containers[id]).
Str("uid", string(pod.GetUID())).
Int32("exit-code", t.ExitCode).
Str("reason", t.Reason).
@ -205,19 +206,19 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
Time("finished", t.FinishedAt.Time).
Warn("Pod failed in unexpected way: Init Container failed")
r.metrics.IncMemberInitContainerRestarts(memberStatus.ID, container, t.Reason, t.ExitCode)
r.metrics.IncMemberInitContainerRestarts(memberStatus.ID, containers[id], t.Reason, t.ExitCode)
}
}
}
}
if containers := k8sutil.GetFailedContainerNames(pod.Status.ContainerStatuses); len(containers) > 0 {
for _, container := range containers {
if c, ok := k8sutil.GetAnyContainerStatusByName(pod.Status.ContainerStatuses, container); ok {
if containers := container.GetFailedContainerNames(pod.Status.ContainerStatuses); len(containers) > 0 {
for id := range containers {
if c, ok := container.GetAnyContainerStatusByName(pod.Status.ContainerStatuses, containers[id]); ok {
if t := c.State.Terminated; t != nil && t.ExitCode != 0 {
log.Str("member", memberStatus.ID).
Str("pod", pod.GetName()).
Str("container", container).
Str("container", containers[id]).
Str("uid", string(pod.GetUID())).
Int32("exit-code", t.ExitCode).
Str("reason", t.Reason).
@ -227,7 +228,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter
Time("finished", t.FinishedAt.Time).
Warn("Pod failed in unexpected way: Core Container failed")
r.metrics.IncMemberContainerRestarts(memberStatus.ID, container, t.Reason, t.ExitCode)
r.metrics.IncMemberContainerRestarts(memberStatus.ID, containers[id], t.Reason, t.ExitCode)
}
}
}

View file

@ -34,6 +34,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/container"
)
// prepareAgencyPodTermination checks if the given agency pod is allowed to terminate
@ -174,7 +175,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, p *core.P
log.Err(err).Debug("Failed to access cluster")
if r.context.GetSpec().Recovery.Get().GetAutoRecover() {
if c, ok := k8sutil.GetContainerStatusByName(p, shared.ServerContainerName); ok {
if c, ok := container.GetContainerStatusByName(p, shared.ServerContainerName); ok {
if t := c.State.Terminated; t != nil {
return nil
}

View file

@ -33,6 +33,7 @@ import (
mlv1alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/ml/v1alpha1"
replicationv1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/replication/v1"
replicationv2alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/replication/v2alpha1"
schedulerv1alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/scheduler/v1alpha1"
storagev1alpha "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/storage/v1alpha"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
@ -48,6 +49,7 @@ type Interface interface {
MlV1alpha1() mlv1alpha1.MlV1alpha1Interface
ReplicationV1() replicationv1.ReplicationV1Interface
ReplicationV2alpha1() replicationv2alpha1.ReplicationV2alpha1Interface
SchedulerV1alpha1() schedulerv1alpha1.SchedulerV1alpha1Interface
StorageV1alpha() storagev1alpha.StorageV1alphaInterface
}
@ -61,6 +63,7 @@ type Clientset struct {
mlV1alpha1 *mlv1alpha1.MlV1alpha1Client
replicationV1 *replicationv1.ReplicationV1Client
replicationV2alpha1 *replicationv2alpha1.ReplicationV2alpha1Client
schedulerV1alpha1 *schedulerv1alpha1.SchedulerV1alpha1Client
storageV1alpha *storagev1alpha.StorageV1alphaClient
}
@ -99,6 +102,11 @@ func (c *Clientset) ReplicationV2alpha1() replicationv2alpha1.ReplicationV2alpha
return c.replicationV2alpha1
}
// SchedulerV1alpha1 retrieves the SchedulerV1alpha1Client
func (c *Clientset) SchedulerV1alpha1() schedulerv1alpha1.SchedulerV1alpha1Interface {
return c.schedulerV1alpha1
}
// StorageV1alpha retrieves the StorageV1alphaClient
func (c *Clientset) StorageV1alpha() storagev1alpha.StorageV1alphaInterface {
return c.storageV1alpha
@ -176,6 +184,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset,
if err != nil {
return nil, err
}
cs.schedulerV1alpha1, err = schedulerv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient)
if err != nil {
return nil, err
}
cs.storageV1alpha, err = storagev1alpha.NewForConfigAndClient(&configShallowCopy, httpClient)
if err != nil {
return nil, err
@ -208,6 +220,7 @@ func New(c rest.Interface) *Clientset {
cs.mlV1alpha1 = mlv1alpha1.New(c)
cs.replicationV1 = replicationv1.New(c)
cs.replicationV2alpha1 = replicationv2alpha1.New(c)
cs.schedulerV1alpha1 = schedulerv1alpha1.New(c)
cs.storageV1alpha = storagev1alpha.New(c)
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)

View file

@ -38,6 +38,8 @@ import (
fakereplicationv1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/replication/v1/fake"
replicationv2alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/replication/v2alpha1"
fakereplicationv2alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/replication/v2alpha1/fake"
schedulerv1alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/scheduler/v1alpha1"
fakeschedulerv1alpha1 "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/scheduler/v1alpha1/fake"
storagev1alpha "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/storage/v1alpha"
fakestoragev1alpha "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/typed/storage/v1alpha/fake"
"k8s.io/apimachinery/pkg/runtime"
@ -132,6 +134,11 @@ func (c *Clientset) ReplicationV2alpha1() replicationv2alpha1.ReplicationV2alpha
return &fakereplicationv2alpha1.FakeReplicationV2alpha1{Fake: &c.Fake}
}
// SchedulerV1alpha1 retrieves the SchedulerV1alpha1Client
func (c *Clientset) SchedulerV1alpha1() schedulerv1alpha1.SchedulerV1alpha1Interface {
return &fakeschedulerv1alpha1.FakeSchedulerV1alpha1{Fake: &c.Fake}
}
// StorageV1alpha retrieves the StorageV1alphaClient
func (c *Clientset) StorageV1alpha() storagev1alpha.StorageV1alphaInterface {
return &fakestoragev1alpha.FakeStorageV1alpha{Fake: &c.Fake}

View file

@ -30,6 +30,7 @@ import (
mlv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1"
replicationv1 "github.com/arangodb/kube-arangodb/pkg/apis/replication/v1"
replicationv2alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/replication/v2alpha1"
schedulerv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1"
storagev1alpha "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
@ -49,6 +50,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{
mlv1alpha1.AddToScheme,
replicationv1.AddToScheme,
replicationv2alpha1.AddToScheme,
schedulerv1alpha1.AddToScheme,
storagev1alpha.AddToScheme,
}

View file

@ -30,6 +30,7 @@ import (
mlv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/ml/v1alpha1"
replicationv1 "github.com/arangodb/kube-arangodb/pkg/apis/replication/v1"
replicationv2alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/replication/v2alpha1"
schedulerv1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1"
storagev1alpha "github.com/arangodb/kube-arangodb/pkg/apis/storage/v1alpha"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
@ -49,6 +50,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{
mlv1alpha1.AddToScheme,
replicationv1.AddToScheme,
replicationv2alpha1.AddToScheme,
schedulerv1alpha1.AddToScheme,
storagev1alpha.AddToScheme,
}

View file

@ -0,0 +1,24 @@
//
// 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
//
// Code generated by client-gen. DO NOT EDIT.
// This package has the automatically generated typed clients.
package v1alpha1

View file

@ -0,0 +1,24 @@
//
// 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
//
// Code generated by client-gen. DO NOT EDIT.
// Package fake has the automatically generated clients.
package fake

View file

@ -0,0 +1,39 @@
//
// 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
//
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
rest "k8s.io/client-go/rest"
testing "k8s.io/client-go/testing"
)
type FakeSchedulerV1alpha1 struct {
*testing.Fake
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *FakeSchedulerV1alpha1) RESTClient() rest.Interface {
var ret *rest.RESTClient
return ret
}

View file

@ -0,0 +1,23 @@
//
// 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
//
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1

View file

@ -0,0 +1,106 @@
//
// 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
//
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1
import (
"net/http"
v1alpha1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1"
"github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned/scheme"
rest "k8s.io/client-go/rest"
)
type SchedulerV1alpha1Interface interface {
RESTClient() rest.Interface
}
// SchedulerV1alpha1Client is used to interact with features provided by the scheduler.arangodb.com group.
type SchedulerV1alpha1Client struct {
restClient rest.Interface
}
// NewForConfig creates a new SchedulerV1alpha1Client for the given config.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(c *rest.Config) (*SchedulerV1alpha1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
httpClient, err := rest.HTTPClientFor(&config)
if err != nil {
return nil, err
}
return NewForConfigAndClient(&config, httpClient)
}
// NewForConfigAndClient creates a new SchedulerV1alpha1Client for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(c *rest.Config, h *http.Client) (*SchedulerV1alpha1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientForConfigAndClient(&config, h)
if err != nil {
return nil, err
}
return &SchedulerV1alpha1Client{client}, nil
}
// NewForConfigOrDie creates a new SchedulerV1alpha1Client for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *SchedulerV1alpha1Client {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}
// New creates a new SchedulerV1alpha1Client for the given RESTClient.
func New(c rest.Interface) *SchedulerV1alpha1Client {
return &SchedulerV1alpha1Client{c}
}
func setConfigDefaults(config *rest.Config) error {
gv := v1alpha1.SchemeGroupVersion
config.GroupVersion = &gv
config.APIPath = "/apis"
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
if config.UserAgent == "" {
config.UserAgent = rest.DefaultKubernetesUserAgent()
}
return nil
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *SchedulerV1alpha1Client) RESTClient() rest.Interface {
if c == nil {
return nil
}
return c.restClient
}

View file

@ -0,0 +1,209 @@
//
// 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 affinity
import core "k8s.io/api/core/v1"
func Merge(a, b *core.Affinity) *core.Affinity {
if a == nil && b == nil {
return nil
}
if a == nil {
return b.DeepCopy()
}
if b == nil {
return a.DeepCopy()
}
return Optional(&core.Affinity{
PodAntiAffinity: OptionalPodAntiAffinity(MergePodAntiAffinity(a.PodAntiAffinity, b.PodAntiAffinity)),
PodAffinity: OptionalPodAffinity(MergePodAffinity(a.PodAffinity, b.PodAffinity)),
NodeAffinity: OptionalNodeAffinity(MergeNodeAffinity(a.NodeAffinity, b.NodeAffinity)),
})
}
func Optional(a *core.Affinity) *core.Affinity {
if a.PodAntiAffinity == nil && a.NodeAffinity == nil && a.PodAffinity == nil {
return nil
}
return a
}
func MergePodAffinity(a, b *core.PodAffinity) *core.PodAffinity {
if a == nil && b == nil {
return nil
}
if a == nil {
return b.DeepCopy()
}
if b == nil {
return a.DeepCopy()
}
n := a.DeepCopy()
n.PreferredDuringSchedulingIgnoredDuringExecution = append(n.PreferredDuringSchedulingIgnoredDuringExecution,
b.PreferredDuringSchedulingIgnoredDuringExecution...)
n.RequiredDuringSchedulingIgnoredDuringExecution = append(n.RequiredDuringSchedulingIgnoredDuringExecution,
b.RequiredDuringSchedulingIgnoredDuringExecution...)
return n
}
func OptionalPodAffinity(a *core.PodAffinity) *core.PodAffinity {
if a == nil {
return nil
}
if len(a.RequiredDuringSchedulingIgnoredDuringExecution) > 0 || len(a.PreferredDuringSchedulingIgnoredDuringExecution) > 0 {
return a
}
return nil
}
func MergePodAntiAffinity(a, b *core.PodAntiAffinity) *core.PodAntiAffinity {
if a == nil && b == nil {
return nil
}
if a == nil {
return b.DeepCopy()
}
if b == nil {
return a.DeepCopy()
}
n := a.DeepCopy()
n.PreferredDuringSchedulingIgnoredDuringExecution = append(n.PreferredDuringSchedulingIgnoredDuringExecution,
b.PreferredDuringSchedulingIgnoredDuringExecution...)
n.RequiredDuringSchedulingIgnoredDuringExecution = append(n.RequiredDuringSchedulingIgnoredDuringExecution,
b.RequiredDuringSchedulingIgnoredDuringExecution...)
return n
}
func OptionalPodAntiAffinity(a *core.PodAntiAffinity) *core.PodAntiAffinity {
if a == nil {
return nil
}
if len(a.RequiredDuringSchedulingIgnoredDuringExecution) > 0 || len(a.PreferredDuringSchedulingIgnoredDuringExecution) > 0 {
return a
}
return nil
}
func MergeNodeAffinity(a, b *core.NodeAffinity) *core.NodeAffinity {
if a == nil && b == nil {
return nil
}
if a == nil {
return b.DeepCopy()
}
if b == nil {
return a.DeepCopy()
}
n := a.DeepCopy()
n.PreferredDuringSchedulingIgnoredDuringExecution = append(n.PreferredDuringSchedulingIgnoredDuringExecution,
b.PreferredDuringSchedulingIgnoredDuringExecution...)
n.RequiredDuringSchedulingIgnoredDuringExecution = MergeNodeSelector(n.RequiredDuringSchedulingIgnoredDuringExecution, b.RequiredDuringSchedulingIgnoredDuringExecution)
return n
}
func MergeNodeSelector(a, b *core.NodeSelector) *core.NodeSelector {
if a == nil && b == nil {
return nil
}
if a == nil {
return b.DeepCopy()
}
if b == nil {
return a.DeepCopy()
}
if len(a.NodeSelectorTerms) == 0 && len(b.NodeSelectorTerms) == 0 {
return nil
}
if len(a.NodeSelectorTerms) == 0 {
return b.DeepCopy()
}
if len(b.NodeSelectorTerms) == 0 {
return a.DeepCopy()
}
current := a.DeepCopy()
new := b.DeepCopy()
for id := range current.NodeSelectorTerms {
term := current.NodeSelectorTerms[id]
for _, newTerm := range new.NodeSelectorTerms {
if len(newTerm.MatchExpressions) != 0 {
term.MatchExpressions = append(term.MatchExpressions, newTerm.MatchExpressions...)
}
if len(newTerm.MatchFields) != 0 {
term.MatchFields = append(term.MatchFields, newTerm.MatchFields...)
}
}
current.NodeSelectorTerms[id] = term
}
return current
}
func OptionalNodeAffinity(a *core.NodeAffinity) *core.NodeAffinity {
if a == nil {
return nil
}
if len(a.PreferredDuringSchedulingIgnoredDuringExecution) > 0 {
return a
}
if s := a.RequiredDuringSchedulingIgnoredDuringExecution; s != nil {
if len(s.NodeSelectorTerms) > 0 {
return a
}
}
return nil
}

View file

@ -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.
@ -18,9 +18,22 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package k8sutil
package container
import core "k8s.io/api/core/v1"
import (
core "k8s.io/api/core/v1"
)
// GetContainerIDByName returns the container id in the given list with the given name.
// Returns -1 if not found.
func GetContainerIDByName(containers []core.Container, name string) int {
for id, c := range containers {
if c.Name == name {
return id
}
}
return -1
}
// GetContainerByName returns the container in the given pod with the given name.
// Returns false if not found.
@ -95,3 +108,15 @@ func IsResourceRequirementsChanged(wanted, given core.ResourceRequirements) bool
return checkList(wanted.Limits, given.Limits) || checkList(wanted.Requests, given.Requests)
}
// IsContainerFailed returns true if the arangodb container
// has terminated wih a non-zero exit code.
func IsContainerFailed(container *core.ContainerStatus) bool {
if c := container.State.Terminated; c != nil {
if c.ExitCode != 0 {
return true
}
}
return false
}

View file

@ -25,8 +25,8 @@ import (
core "k8s.io/api/core/v1"
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
@ -64,8 +64,8 @@ func GetArangoDBImageIDFromPod(pod *core.Pod) (string, error) {
}
// GetImageDetails Returns latest defined Image details
func GetImageDetails(images ...*sharedApi.Image) *sharedApi.Image {
var out *sharedApi.Image
func GetImageDetails(images ...*schedulerContainerResourcesApi.Image) *schedulerContainerResourcesApi.Image {
var out *schedulerContainerResourcesApi.Image
for _, image := range images {
if image != nil {
@ -75,42 +75,3 @@ func GetImageDetails(images ...*sharedApi.Image) *sharedApi.Image {
return out
}
// InjectImageDetails injects image details into the Pod definition
func InjectImageDetails(image *sharedApi.Image, pod *core.PodTemplateSpec, containers ...*core.Container) error {
if image == nil {
return errors.Errorf("Image not found")
} else if err := image.Validate(); err != nil {
return errors.Wrapf(err, "Unable to validate image")
}
for _, secret := range image.PullSecrets {
if HasImagePullSecret(pod.Spec.ImagePullSecrets, secret) {
continue
}
pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, core.LocalObjectReference{
Name: secret,
})
}
for _, container := range containers {
container.Image = *image.Image
if ps := image.PullPolicy; ps != nil {
container.ImagePullPolicy = *ps
}
}
return nil
}
func HasImagePullSecret(secrets []core.LocalObjectReference, secret string) bool {
for _, sec := range secrets {
if sec.Name == secret {
return true
}
}
return false
}

View file

@ -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.
@ -35,8 +35,9 @@ import (
"k8s.io/apimachinery/pkg/util/json"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container"
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/features"
"github.com/arangodb/kube-arangodb/pkg/deployment/patch"
"github.com/arangodb/kube-arangodb/pkg/handlers/utils"
@ -44,7 +45,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/constants"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/envs"
podv1 "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/pod/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
@ -265,18 +265,6 @@ func IsPodFailed(pod *core.Pod, coreContainers utils.StringList) bool {
return true
}
// IsContainerFailed returns true if the arangodb container
// has terminated wih a non-zero exit code.
func IsContainerFailed(container *core.ContainerStatus) bool {
if c := container.State.Terminated; c != nil {
if c.ExitCode != 0 {
return true
}
}
return false
}
// IsPodScheduled returns true if the pod has been scheduled.
func IsPodScheduled(pod *core.Pod) bool {
condition := getPodCondition(&pod.Status, core.PodScheduled)
@ -766,63 +754,10 @@ func GetFinalizers(spec api.ServerGroupSpec, group api.ServerGroup) []string {
return finalizers
}
func InjectPodTemplate(spec *sharedApi.PodTemplate, pod *core.PodTemplateSpec) error {
if scheduling := spec.GetScheduling(); scheduling != nil {
pod.Spec.Tolerations = scheduling.GetTolerations().DeepCopy()
pod.Spec.Affinity = scheduling.GetAffinity().DeepCopy()
pod.Spec.NodeSelector = util.CopyFullMap(scheduling.GetNodeSelector())
pod.Spec.SchedulerName = spec.GetSchedulerName()
}
if namespace := spec.GetContainerNamespace(); namespace != nil {
pod.Spec.HostNetwork = namespace.GetHostNetwork()
pod.Spec.HostPID = namespace.GetHostPID()
pod.Spec.HostIPC = namespace.GetHostIPC()
pod.Spec.ShareProcessNamespace = util.NewType(util.TypeOrDefault(namespace.GetShareProcessNamespace(), false))
}
if security := spec.GetSecurityPod(); security != nil {
pod.Spec.SecurityContext = security.PodSecurityContext.DeepCopy()
}
return nil
}
func InjectContainersTemplate(spec *sharedApi.ContainerTemplate, pod *core.PodTemplateSpec, containers ...*core.Container) error {
for _, container := range containers {
if err := InjectContainerTemplate(spec, pod, container); err != nil {
return err
}
}
return nil
}
func InjectContainerTemplate(spec *sharedApi.ContainerTemplate, pod *core.PodTemplateSpec, container *core.Container) error {
if err := InjectImageDetails(spec.GetImage(), pod, container); err != nil {
return err
}
if res := spec.GetResources(); res != nil {
container.Resources = util.TypeOrDefault(res.GetResources())
}
if security := spec.GetSecurityContainer(); security != nil {
container.SecurityContext = security.SecurityContext.DeepCopy()
}
if environments := spec.GetEnvironments(); environments != nil {
container.Env = envs.MergeEnvs(container.Env, environments.Env...)
container.EnvFrom = envs.MergeEnvFrom(container.EnvFrom, environments.EnvFrom...)
}
return nil
}
func CreateDefaultContainerTemplate(image *sharedApi.Image) *sharedApi.ContainerTemplate {
return &sharedApi.ContainerTemplate{
func CreateDefaultContainerTemplate(image *schedulerContainerResourcesApi.Image) *schedulerContainerApi.Container {
return &schedulerContainerApi.Container{
Image: image.DeepCopy(),
Resources: &sharedApi.Resources{
Resources: &schedulerContainerResourcesApi.Resources{
Resources: &core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse("100m"),
@ -834,7 +769,7 @@ func CreateDefaultContainerTemplate(image *sharedApi.Image) *sharedApi.Container
},
},
},
SecurityContainer: &sharedApi.SecurityContainer{
Security: &schedulerContainerResourcesApi.Security{
SecurityContext: &core.SecurityContext{
RunAsUser: util.NewType[int64](shared.DefaultRunAsUser),
RunAsGroup: util.NewType[int64](shared.DefaultRunAsGroup),

View file

@ -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.
@ -46,6 +46,15 @@ func TypeOrDefault[T interface{}](input *T, defaultValue ...T) T {
return *input
}
// WithDefault returns generic default value for type T if in is nil
func WithDefault[T interface{}](in *T) T {
if in == nil {
return Default[T]()
}
return *in
}
// Default returns generic default value for type T
func Default[T interface{}]() T {
var d T