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

[Feature] [Scheduler] Add Status Conditions (#1720)

This commit is contained in:
Adam Janikowski 2024-09-10 15:34:45 +02:00 committed by GitHub
parent 6404de3ce4
commit 9e7ed8dbad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 530 additions and 61 deletions

View file

@ -79,6 +79,8 @@ linters-settings:
pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container
- alias: schedulerContainerResourcesApi
pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container/resources
- alias: schedulerIntegrationApi
pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration
- alias: schedulerPodApi
pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod
- alias: schedulerPodResourcesApi

View file

@ -28,6 +28,7 @@
- (Feature) (Gateway) ArangoDB Auth Token
- (Feature) (Gateway) Dynamic Configuration
- (Feature) DebugPackage ArangoRoutes
- (Feature) (Scheduler) Add Status Conditions
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries

View file

@ -452,7 +452,7 @@ update-generated:
"github.com/arangodb/kube-arangodb/pkg/apis" \
"shared:v1 \
scheduler:v1alpha1/container scheduler:v1alpha1/container/resources scheduler:v1alpha1/pod scheduler:v1alpha1/pod/resources \
scheduler:v1beta1/container scheduler:v1beta1/container/resources scheduler:v1beta1/pod scheduler:v1beta1/pod/resources" \
scheduler:v1beta1/integration scheduler:v1beta1/container scheduler:v1beta1/container/resources scheduler:v1beta1/pod scheduler:v1beta1/pod/resources" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)

View file

@ -3110,7 +3110,7 @@ Links:
### .spec.gateway.sidecar.controllerListenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration.go#L36)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration/integration.go#L16)</sup>
ControllerListenPort defines on which port the sidecar container will be listening for controller requests
@ -3168,7 +3168,7 @@ Lifecycle keeps actions that the management system should take in response to co
### .spec.gateway.sidecar.listenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration.go#L32)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration/integration.go#L12)</sup>
ListenPort defines on which port the sidecar container will be listening for connections

View file

@ -798,7 +798,7 @@ Links:
### .spec.integrationSidecar.controllerListenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration.go#L36)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration/integration.go#L16)</sup>
ControllerListenPort defines on which port the sidecar container will be listening for controller requests
@ -856,7 +856,7 @@ Lifecycle keeps actions that the management system should take in response to co
### .spec.integrationSidecar.listenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration.go#L32)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration/integration.go#L12)</sup>
ListenPort defines on which port the sidecar container will be listening for connections

View file

@ -394,5 +394,5 @@ Links:
### .spec.template.priority
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/profile_template.go#L30)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/profile_template.go#L31)</sup>

View file

@ -440,7 +440,7 @@ Links:
### .spec.integrationSidecar.controllerListenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration.go#L36)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration/integration.go#L16)</sup>
ControllerListenPort defines on which port the sidecar container will be listening for controller requests
@ -498,7 +498,7 @@ Lifecycle keeps actions that the management system should take in response to co
### .spec.integrationSidecar.listenPort
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration.go#L32)</sup>
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.42/pkg/apis/scheduler/v1beta1/integration/integration.go#L12)</sup>
ListenPort defines on which port the sidecar container will be listening for connections

View file

@ -180,6 +180,7 @@ func Test_GenerateAPIDocs(t *testing.T) {
"scheduler/v1beta1",
"scheduler/v1beta1/container",
"scheduler/v1beta1/container/resources",
"scheduler/v1beta1/integration",
"scheduler/v1beta1/pod",
"scheduler/v1beta1/pod/resources",
},
@ -253,6 +254,7 @@ func Test_GenerateAPIDocs(t *testing.T) {
"scheduler/v1beta1",
"scheduler/v1beta1/container",
"scheduler/v1beta1/container/resources",
"scheduler/v1beta1/integration",
"scheduler/v1beta1/pod",
"scheduler/v1beta1/pod/resources",
},
@ -284,6 +286,7 @@ func Test_GenerateAPIDocs(t *testing.T) {
"scheduler/v1beta1",
"scheduler/v1beta1/container",
"scheduler/v1beta1/container/resources",
"scheduler/v1beta1/integration",
"scheduler/v1beta1/pod",
"scheduler/v1beta1/pod/resources",
},
@ -323,6 +326,7 @@ func Test_GenerateAPIDocs(t *testing.T) {
"shared/v1",
"scheduler/v1beta1/container",
"scheduler/v1beta1/container/resources",
"scheduler/v1beta1/integration",
"scheduler/v1beta1/pod",
"scheduler/v1beta1/pod/resources",
},

View file

@ -21,7 +21,7 @@
package v1alpha1
import (
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
schedulerIntegrationApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
@ -34,7 +34,7 @@ type GraphAnalyticsEngineSpec struct {
Deployment *GraphAnalyticsEngineSpecDeployment `json:"deployment,omitempty"`
// IntegrationSidecar define the integration sidecar spec
IntegrationSidecar *schedulerApi.IntegrationSidecar `json:"integrationSidecar,omitempty"`
IntegrationSidecar *schedulerIntegrationApi.Sidecar `json:"integrationSidecar,omitempty"`
}
func (a *GraphAnalyticsEngineSpec) GetDeployment() *GraphAnalyticsEngineSpecDeployment {
@ -44,7 +44,7 @@ func (a *GraphAnalyticsEngineSpec) GetDeployment() *GraphAnalyticsEngineSpecDepl
return a.Deployment
}
func (a *GraphAnalyticsEngineSpec) GetIntegrationSidecar() *schedulerApi.IntegrationSidecar {
func (a *GraphAnalyticsEngineSpec) GetIntegrationSidecar() *schedulerIntegrationApi.Sidecar {
if a == nil || a.IntegrationSidecar == nil {
return nil
}

View file

@ -27,8 +27,8 @@ package v1alpha1
import (
deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
v1beta1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
container "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
integration "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
pod "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
v1 "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
corev1 "k8s.io/api/core/v1"
@ -111,7 +111,7 @@ func (in *GraphAnalyticsEngineSpec) DeepCopyInto(out *GraphAnalyticsEngineSpec)
}
if in.IntegrationSidecar != nil {
in, out := &in.IntegrationSidecar, &out.IntegrationSidecar
*out = new(v1beta1.IntegrationSidecar)
*out = new(integration.Sidecar)
(*in).DeepCopyInto(*out)
}
return

View file

@ -21,7 +21,7 @@
package v1
import (
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
schedulerIntegrationApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
)
@ -42,7 +42,7 @@ type DeploymentSpecGateway struct {
Image *string `json:"image"`
// Sidecar define the integration sidecar spec
Sidecar *schedulerApi.IntegrationSidecar `json:"sidecar,omitempty"`
Sidecar *schedulerIntegrationApi.Sidecar `json:"sidecar,omitempty"`
}
// IsEnabled returns whether the gateway is enabled.
@ -63,7 +63,7 @@ func (d *DeploymentSpecGateway) IsDynamic() bool {
return *d.Dynamic
}
func (d *DeploymentSpecGateway) GetSidecar() *schedulerApi.IntegrationSidecar {
func (d *DeploymentSpecGateway) GetSidecar() *schedulerIntegrationApi.Sidecar {
if d == nil || d.Sidecar == nil {
return nil
}

View file

@ -28,7 +28,7 @@ package v1
import (
time "time"
v1beta1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
integration "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
sharedv1 "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -1192,7 +1192,7 @@ func (in *DeploymentSpecGateway) DeepCopyInto(out *DeploymentSpecGateway) {
}
if in.Sidecar != nil {
in, out := &in.Sidecar, &out.Sidecar
*out = new(v1beta1.IntegrationSidecar)
*out = new(integration.Sidecar)
(*in).DeepCopyInto(*out)
}
return

View file

@ -21,7 +21,7 @@
package v2alpha1
import (
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
schedulerIntegrationApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
)
@ -42,7 +42,7 @@ type DeploymentSpecGateway struct {
Image *string `json:"image"`
// Sidecar define the integration sidecar spec
Sidecar *schedulerApi.IntegrationSidecar `json:"sidecar,omitempty"`
Sidecar *schedulerIntegrationApi.Sidecar `json:"sidecar,omitempty"`
}
// IsEnabled returns whether the gateway is enabled.
@ -63,7 +63,7 @@ func (d *DeploymentSpecGateway) IsDynamic() bool {
return *d.Dynamic
}
func (d *DeploymentSpecGateway) GetSidecar() *schedulerApi.IntegrationSidecar {
func (d *DeploymentSpecGateway) GetSidecar() *schedulerIntegrationApi.Sidecar {
if d == nil || d.Sidecar == nil {
return nil
}

View file

@ -28,7 +28,7 @@ package v2alpha1
import (
time "time"
v1beta1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
integration "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
sharedv1 "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -1192,7 +1192,7 @@ func (in *DeploymentSpecGateway) DeepCopyInto(out *DeploymentSpecGateway) {
}
if in.Sidecar != nil {
in, out := &in.Sidecar, &out.Sidecar
*out = new(v1beta1.IntegrationSidecar)
*out = new(integration.Sidecar)
(*in).DeepCopyInto(*out)
}
return

View file

@ -21,7 +21,7 @@
package v1beta1
import (
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
schedulerIntegrationApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
)
@ -44,7 +44,7 @@ type ArangoMLExtensionSpec struct {
JobsTemplates *ArangoMLJobsTemplates `json:"jobsTemplates,omitempty"`
// IntegrationSidecar define the integration sidecar spec
IntegrationSidecar *schedulerApi.IntegrationSidecar `json:"integrationSidecar,omitempty"`
IntegrationSidecar *schedulerIntegrationApi.Sidecar `json:"integrationSidecar,omitempty"`
}
func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetadataService {
@ -85,7 +85,7 @@ func (a *ArangoMLExtensionSpec) GetJobsTemplates() *ArangoMLJobsTemplates {
return a.JobsTemplates
}
func (a *ArangoMLExtensionSpec) GetIntegrationSidecar() *schedulerApi.IntegrationSidecar {
func (a *ArangoMLExtensionSpec) GetIntegrationSidecar() *schedulerIntegrationApi.Sidecar {
if a == nil || a.IntegrationSidecar == nil {
return nil
}

View file

@ -27,8 +27,8 @@ package v1beta1
import (
deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
schedulerv1beta1 "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
container "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
integration "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
pod "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
v1 "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
corev1 "k8s.io/api/core/v1"
@ -126,7 +126,7 @@ func (in *ArangoMLExtensionSpec) DeepCopyInto(out *ArangoMLExtensionSpec) {
}
if in.IntegrationSidecar != nil {
in, out := &in.IntegrationSidecar, &out.IntegrationSidecar
*out = new(schedulerv1beta1.IntegrationSidecar)
*out = new(integration.Sidecar)
(*in).DeepCopyInto(*out)
}
return

View file

@ -0,0 +1,28 @@
//
// 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 v1beta1
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
const (
ReadyCondition api.ConditionType = "Ready"
SpecValidCondition api.ConditionType = "SpecValid"
)

View file

@ -27,7 +27,6 @@ import (
"github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/interfaces"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
)
@ -114,13 +113,17 @@ func (c Containers) With(other Containers) Containers {
}
func (c Containers) Validate() error {
for name, container := range c {
if err := container.Validate(); err != nil {
return errors.Wrapf(err, "Container %s failed", name)
return shared.ValidateMap(c, func(s string, container Container) error {
if err := shared.ValidateResourceName(s); err != nil {
return err
}
}
return nil
if err := container.Validate(); err != nil {
return err
}
return nil
})
}
var _ interfaces.Container[Container] = &Container{}

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 integration

View file

@ -18,7 +18,7 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package v1beta1
package integration
import (
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
@ -26,7 +26,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
type IntegrationSidecar struct {
type Sidecar struct {
// ListenPort defines on which port the sidecar container will be listening for connections
// +doc/default: 9201
ListenPort *uint16 `json:"listenPort,omitempty"`
@ -39,7 +39,7 @@ type IntegrationSidecar struct {
*schedulerContainerApi.Container `json:",inline"`
}
func (s *IntegrationSidecar) GetContainer() *schedulerContainerApi.Container {
func (s *Sidecar) GetContainer() *schedulerContainerApi.Container {
if s == nil || s.Container == nil {
return nil
}
@ -47,9 +47,9 @@ func (s *IntegrationSidecar) GetContainer() *schedulerContainerApi.Container {
return s.Container
}
func (s *IntegrationSidecar) Validate() error {
func (s *Sidecar) Validate() error {
if s == nil {
s = &IntegrationSidecar{}
s = &Sidecar{}
}
var err []error
@ -67,14 +67,14 @@ func (s *IntegrationSidecar) Validate() error {
return shared.WithErrors(err...)
}
func (s *IntegrationSidecar) GetListenPort() uint16 {
func (s *Sidecar) GetListenPort() uint16 {
if s == nil || s.ListenPort == nil {
return 9201
}
return *s.ListenPort
}
func (s *IntegrationSidecar) GetControllerListenPort() uint16 {
func (s *Sidecar) GetControllerListenPort() uint16 {
if s == nil || s.ControllerListenPort == nil {
return 9202
}

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 integration
import (
container "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Sidecar) DeepCopyInto(out *Sidecar) {
*out = *in
if in.ListenPort != nil {
in, out := &in.ListenPort, &out.ListenPort
*out = new(uint16)
**out = **in
}
if in.ControllerListenPort != nil {
in, out := &in.ControllerListenPort, &out.ControllerListenPort
*out = new(uint16)
**out = **in
}
if in.Container != nil {
in, out := &in.Container, &out.Container
*out = new(container.Container)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Sidecar.
func (in *Sidecar) DeepCopy() *Sidecar {
if in == nil {
return nil
}
out := new(Sidecar)
in.DeepCopyInto(out)
return out
}

View file

@ -0,0 +1,29 @@
//
// 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 v1beta1
type ProfileAcceptedTemplate struct {
// Checksum keeps accepted template checksum
Checksum string `json:"checksum,omitempty"`
// Template keeps the Profile Template
Template *ProfileTemplate `json:"template,omitempty"`
}

View file

@ -20,4 +20,13 @@
package v1beta1
type ProfileStatus struct{}
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
type ProfileStatus struct {
// Conditions specific to the entire extension
// +doc/type: api.Conditions
Conditions api.ConditionList `json:"conditions,omitempty"`
// Accepted keeps accepted template
Accepted *ProfileAcceptedTemplate `json:"accepted,omitempty"`
}

View file

@ -21,6 +21,8 @@
package v1beta1
import (
"encoding/json"
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
@ -78,6 +80,19 @@ func (p *ProfileTemplate) With(other *ProfileTemplate) *ProfileTemplate {
}
}
func (p *ProfileTemplate) Checksum() (string, error) {
if p == nil {
return "", nil
}
data, err := json.Marshal(p)
if err != nil {
return "", err
}
return util.SHA256(data), nil
}
func (p *ProfileTemplate) Validate() error {
if p == nil {
return nil

View file

@ -26,6 +26,7 @@
package v1beta1
import (
deploymentv1 "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
container "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
pod "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -38,7 +39,7 @@ func (in *ArangoProfile) DeepCopyInto(out *ArangoProfile) {
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
out.Status = in.Status
in.Status.DeepCopyInto(&out.Status)
return
}
@ -94,32 +95,22 @@ func (in *ArangoProfileList) DeepCopyObject() runtime.Object {
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *IntegrationSidecar) DeepCopyInto(out *IntegrationSidecar) {
func (in *ProfileAcceptedTemplate) DeepCopyInto(out *ProfileAcceptedTemplate) {
*out = *in
if in.ListenPort != nil {
in, out := &in.ListenPort, &out.ListenPort
*out = new(uint16)
**out = **in
}
if in.ControllerListenPort != nil {
in, out := &in.ControllerListenPort, &out.ControllerListenPort
*out = new(uint16)
**out = **in
}
if in.Container != nil {
in, out := &in.Container, &out.Container
*out = new(container.Container)
if in.Template != nil {
in, out := &in.Template, &out.Template
*out = new(ProfileTemplate)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IntegrationSidecar.
func (in *IntegrationSidecar) DeepCopy() *IntegrationSidecar {
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProfileAcceptedTemplate.
func (in *ProfileAcceptedTemplate) DeepCopy() *ProfileAcceptedTemplate {
if in == nil {
return nil
}
out := new(IntegrationSidecar)
out := new(ProfileAcceptedTemplate)
in.DeepCopyInto(out)
return out
}
@ -202,6 +193,18 @@ func (in *ProfileSpec) DeepCopy() *ProfileSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ProfileStatus) DeepCopyInto(out *ProfileStatus) {
*out = *in
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make(deploymentv1.ConditionList, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.Accepted != nil {
in, out := &in.Accepted, &out.Accepted
*out = new(ProfileAcceptedTemplate)
(*in).DeepCopyInto(*out)
}
return
}

View file

@ -92,6 +92,26 @@ func (h *handler) Handle(ctx context.Context, item operation.Item) error {
}
func (h *handler) handle(ctx context.Context, item operation.Item, extension *schedulerApi.ArangoProfile, status *schedulerApi.ProfileStatus) (bool, error) {
return operator.HandleP3WithCondition(ctx, &status.Conditions, schedulerApi.ReadyCondition, item, extension, status, h.HandleSpecValidity, h.HandleTemplate)
}
func (h *handler) HandleSpecValidity(ctx context.Context, item operation.Item, extension *schedulerApi.ArangoProfile, status *schedulerApi.ProfileStatus) (bool, error) {
if err := extension.Spec.Validate(); err != nil {
// We have received an error in the spec!
logger.Err(err).Warn("Invalid Spec on %s", item.String())
if status.Conditions.Update(schedulerApi.SpecValidCondition, false, "Spec is invalid", "Spec is invalid") || status.Accepted != nil {
status.Accepted = nil
return true, operator.Stop("Invalid spec")
}
return false, operator.Stop("Invalid spec")
}
if status.Conditions.Update(schedulerApi.SpecValidCondition, true, "Spec is valid", "Spec is valid") {
return true, operator.Reconcile("Conditions updated")
}
return false, nil
}

View file

@ -0,0 +1,57 @@
//
// 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 profile
import (
"context"
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
operator "github.com/arangodb/kube-arangodb/pkg/operatorV2"
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
)
func (h *handler) HandleTemplate(ctx context.Context, item operation.Item, extension *schedulerApi.ArangoProfile, status *schedulerApi.ProfileStatus) (bool, error) {
templ := extension.Spec.Template
c, err := templ.Checksum()
if err != nil {
return false, err
}
if t := status.Accepted; t != nil {
if c == "" || t.Checksum != c {
status.Accepted = nil
return true, operator.Reconcile("Template changed")
}
return false, nil
} else {
if c != "" {
status.Accepted = &schedulerApi.ProfileAcceptedTemplate{
Checksum: c,
Template: templ.DeepCopy(),
}
return true, operator.Reconcile("Template changed")
}
return false, nil
}
}

View file

@ -0,0 +1,213 @@
//
// 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 profile
import (
"testing"
"github.com/stretchr/testify/require"
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod/resources"
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
"github.com/arangodb/kube-arangodb/pkg/util/tests"
)
func Test_Handler_Template(t *testing.T) {
handler := newFakeHandler()
// Arrange
extension := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test",
func(t *testing.T, obj *schedulerApi.ArangoProfile) {
obj.Spec.Template = &schedulerApi.ProfileTemplate{}
})
refresh := tests.CreateObjects(t, handler.kubeClient, handler.client, &extension)
// Test
require.NoError(t, tests.Handle(handler, tests.NewItem(t, operation.Update, extension)))
// Refresh
refresh(t)
// Assert
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.SpecValidCondition))
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.ReadyCondition))
require.NotNil(t, extension.Status.Accepted)
require.Equal(t, extension.Spec.Template, extension.Status.Accepted.Template)
require.Equal(t, "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a", extension.Status.Accepted.Checksum)
}
func Test_Handler_InvalidTemplate(t *testing.T) {
handler := newFakeHandler()
// Arrange
extension := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test",
func(t *testing.T, obj *schedulerApi.ArangoProfile) {
obj.Spec.Template = &schedulerApi.ProfileTemplate{
Container: &schedulerApi.ProfileContainerTemplate{
Containers: schedulerContainerApi.Containers{
"^%$@#": {},
},
},
}
})
refresh := tests.CreateObjects(t, handler.kubeClient, handler.client, &extension)
// Test
require.NoError(t, tests.Handle(handler, tests.NewItem(t, operation.Update, extension)))
// Refresh
refresh(t)
// Assert
require.False(t, extension.Status.Conditions.IsTrue(schedulerApi.SpecValidCondition))
require.False(t, extension.Status.Conditions.IsTrue(schedulerApi.ReadyCondition))
require.Nil(t, extension.Status.Accepted)
}
func Test_Handler_Template_Update(t *testing.T) {
handler := newFakeHandler()
// Arrange
extension := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test",
func(t *testing.T, obj *schedulerApi.ArangoProfile) {
obj.Spec.Template = &schedulerApi.ProfileTemplate{}
})
refresh := tests.CreateObjects(t, handler.kubeClient, handler.client, &extension)
t.Run("First", func(t *testing.T) {
// Test
require.NoError(t, tests.Handle(handler, tests.NewItem(t, operation.Update, extension)))
// Refresh
refresh(t)
// Assert
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.SpecValidCondition))
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.ReadyCondition))
require.NotNil(t, extension.Status.Accepted)
require.Equal(t, extension.Spec.Template, extension.Status.Accepted.Template)
require.Equal(t, "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a", extension.Status.Accepted.Checksum)
require.Nil(t, extension.Status.Accepted.Template.Pod)
})
t.Run("Second", func(t *testing.T) {
// Arrange
extension.Spec.Template = &schedulerApi.ProfileTemplate{
Pod: &schedulerPodApi.Pod{
Image: &schedulerPodResourcesApi.Image{
ImagePullSecrets: schedulerPodResourcesApi.ImagePullSecrets{
"test",
},
},
},
}
tests.UpdateObjects(t, handler.kubeClient, handler.client, &extension)
// Test
require.NoError(t, tests.Handle(handler, tests.NewItem(t, operation.Update, extension)))
// Refresh
refresh(t)
// Assert
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.SpecValidCondition))
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.ReadyCondition))
require.NotNil(t, extension.Status.Accepted)
require.Equal(t, extension.Spec.Template, extension.Status.Accepted.Template)
require.Equal(t, "f48e2e30be82828a43873befdf9eb877ee4d34d45b2eb45a2f253020955e022a", extension.Status.Accepted.Checksum)
require.NotNil(t, extension.Status.Accepted.Template.Pod)
require.Equal(t, &schedulerPodApi.Pod{
Image: &schedulerPodResourcesApi.Image{
ImagePullSecrets: schedulerPodResourcesApi.ImagePullSecrets{
"test",
},
},
}, extension.Status.Accepted.Template.Pod)
})
}
func Test_Handler_Template_UpdateInvalid(t *testing.T) {
handler := newFakeHandler()
// Arrange
extension := tests.NewMetaObject[*schedulerApi.ArangoProfile](t, tests.FakeNamespace, "test",
func(t *testing.T, obj *schedulerApi.ArangoProfile) {
obj.Spec.Template = &schedulerApi.ProfileTemplate{}
})
refresh := tests.CreateObjects(t, handler.kubeClient, handler.client, &extension)
t.Run("First", func(t *testing.T) {
// Test
require.NoError(t, tests.Handle(handler, tests.NewItem(t, operation.Update, extension)))
// Refresh
refresh(t)
// Assert
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.SpecValidCondition))
require.True(t, extension.Status.Conditions.IsTrue(schedulerApi.ReadyCondition))
require.NotNil(t, extension.Status.Accepted)
require.Equal(t, extension.Spec.Template, extension.Status.Accepted.Template)
require.Equal(t, "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a", extension.Status.Accepted.Checksum)
require.Nil(t, extension.Status.Accepted.Template.Pod)
})
t.Run("Second", func(t *testing.T) {
// Arrange
extension.Spec.Template = &schedulerApi.ProfileTemplate{
Container: &schedulerApi.ProfileContainerTemplate{
Containers: schedulerContainerApi.Containers{
"^%$@#": {},
},
},
}
tests.UpdateObjects(t, handler.kubeClient, handler.client, &extension)
// Test
require.NoError(t, tests.Handle(handler, tests.NewItem(t, operation.Update, extension)))
// Refresh
refresh(t)
// Assert
require.False(t, extension.Status.Conditions.IsTrue(schedulerApi.SpecValidCondition))
require.False(t, extension.Status.Conditions.IsTrue(schedulerApi.ReadyCondition))
require.Nil(t, extension.Status.Accepted)
})
}

View file

@ -14,6 +14,7 @@ import (
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1"
schedulerContainerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container"
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/container/resources"
schedulerIntegrationApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/integration"
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod"
schedulerPodResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1beta1/pod/resources"
"github.com/arangodb/kube-arangodb/pkg/util"
@ -60,7 +61,7 @@ type Integration interface {
Validate() error
}
func NewIntegration(image *schedulerContainerResourcesApi.Image, integration *schedulerApi.IntegrationSidecar, coreContainers []string, integrations ...Integration) (*schedulerApi.ProfileTemplate, error) {
func NewIntegration(image *schedulerContainerResourcesApi.Image, integration *schedulerIntegrationApi.Sidecar, coreContainers []string, integrations ...Integration) (*schedulerApi.ProfileTemplate, error) {
for _, integration := range integrations {
if err := integration.Validate(); err != nil {
name := strings.Join(integration.Name(), "/")