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

[Bugfix] Fix Schema Apply Checksum (#1652)

This commit is contained in:
Adam Janikowski 2024-04-29 11:56:10 +02:00 committed by GitHub
parent bb45038808
commit 2397c7523a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 284 additions and 340 deletions

View file

@ -4,6 +4,7 @@
- (Maintenance) Bump Prometheus API Version
- (Bugfix) Prevent unexpected rotation in case of SecurityContext change
- (Bugfix) Ensure PDB is created
- (Bugfix) Fix Schema Apply Checksum
## [1.2.40](https://github.com/arangodb/kube-arangodb/tree/1.2.40) (2024-04-10)
- (Feature) Add Core fields to the Scheduler Container Spec

View file

@ -67,6 +67,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
"github.com/arangodb/kube-arangodb/pkg/util/probe"
"github.com/arangodb/kube-arangodb/pkg/util/retry"
"github.com/arangodb/kube-arangodb/pkg/util/shutdown"
"github.com/arangodb/kube-arangodb/pkg/version"
)
@ -378,7 +379,7 @@ func executeMain(cmd *cobra.Command, args []string) {
}
if crdOptions.install {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(shutdown.Context(), time.Minute)
defer cancel()
crdOpts, err := prepareCRDOptions(crdOptions.validationSchema)

View file

@ -34,6 +34,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/crd/crds"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
"github.com/arangodb/kube-arangodb/pkg/util/shutdown"
)
var (
@ -108,7 +109,7 @@ func cmdCRDInstallRun(cmd *cobra.Command, args []string) {
return
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(shutdown.Context(), time.Minute)
defer cancel()
err = crd.EnsureCRDWithOptions(ctx, client, crd.EnsureCRDOptions{IgnoreErrors: false, CRDOptions: crdOpts, ForceUpdate: crdInstallOptions.force})

View file

@ -28,8 +28,6 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/crd/crds"
"github.com/arangodb/kube-arangodb/pkg/logging"
kresources "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/resources"
@ -65,13 +63,13 @@ func EnsureCRDWithOptions(ctx context.Context, client kclient.Client, opts Ensur
continue
}
var opt *crds.CRDOptions
var opt = &crdReg.defaultOpts
if o, ok := opts.CRDOptions[crdName]; ok {
opt = &o
}
def := crdReg.getter(opt)
err := tryApplyCRD(ctx, client, def, opts.ForceUpdate)
err := tryApplyCRD(ctx, client, def, opt, opts.ForceUpdate)
if !opts.IgnoreErrors && err != nil {
return err
}
@ -79,11 +77,19 @@ func EnsureCRDWithOptions(ctx context.Context, client kclient.Client, opts Ensur
return nil
}
func tryApplyCRD(ctx context.Context, client kclient.Client, def crds.Definition, forceUpdate bool) error {
func tryApplyCRD(ctx context.Context, client kclient.Client, def crds.Definition, opts *crds.CRDOptions, forceUpdate bool) error {
crdDefinitions := client.KubernetesExtensions().ApiextensionsV1().CustomResourceDefinitions()
crdName := def.CRD.Name
definitionVersion, definitionSchemaVersion := def.DefinitionData.Checksum()
logger := logger.Str("version", definitionVersion)
if opts.GetWithSchema() {
logger = logger.Str("schema", definitionSchemaVersion)
}
c, err := crdDefinitions.Get(ctx, crdName, meta.GetOptions{})
if err != nil {
if !errors.IsNotFound(err) {
@ -102,12 +108,16 @@ func tryApplyCRD(ctx context.Context, client kclient.Client, def crds.Definition
ObjectMeta: meta.ObjectMeta{
Name: crdName,
Labels: map[string]string{
Version: string(def.Version),
Version: definitionVersion,
},
},
Spec: def.CRD.Spec,
}
if opts.GetWithSchema() {
c.Labels[Schema] = definitionSchemaVersion
}
if _, err := crdDefinitions.Create(ctx, c, meta.CreateOptions{}); err != nil {
logger.Err(err).Str("crd", crdName).Warn("Create Operations is not allowed due to error")
return err
@ -127,14 +137,20 @@ func tryApplyCRD(ctx context.Context, client kclient.Client, def crds.Definition
c.ObjectMeta.Labels = map[string]string{}
}
if v, ok := c.ObjectMeta.Labels[Version]; ok && v != "" {
if !forceUpdate && !isUpdateRequired(def.Version, driver.Version(v)) {
if !forceUpdate {
if v, ok := c.ObjectMeta.Labels[Version]; ok && v == definitionVersion {
if v, ok := c.ObjectMeta.Labels[Schema]; (opts.GetWithSchema() && (ok && v == definitionSchemaVersion)) || (!opts.GetWithSchema() && !ok) {
logger.Str("crd", crdName).Info("CRD Update not required")
return nil
}
}
}
c.ObjectMeta.Labels[Version] = string(def.Version)
c.ObjectMeta.Labels[Version] = definitionVersion
delete(c.ObjectMeta.Labels, Schema)
if opts.GetWithSchema() {
c.ObjectMeta.Labels[Schema] = definitionSchemaVersion
}
c.Spec = def.CRD.Spec
if _, err := crdDefinitions.Update(ctx, c, meta.UpdateOptions{}); err != nil {

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.
@ -22,6 +22,7 @@ package crd
import (
"context"
"encoding/json"
"testing"
"time"
@ -51,6 +52,11 @@ func dropLogMessages(t *testing.T, s tests.LogScanner) map[string]string {
lines[p] = m
}
d, err := json.Marshal(lines)
require.NoError(t, err)
t.Logf("Lines: %s", string(d))
return lines
}
@ -133,27 +139,88 @@ func runApply(t *testing.T, crdOpts map[string]crds.CRDOptions) {
t.Run("Create", func(t *testing.T) {
d := crds.AllDefinitions()[0]
q := d.CRD.DeepCopy()
q.Labels = map[string]string{
Version: string(d.Version),
Version: "version",
}
_, err := c.KubernetesExtensions().ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), q, meta.CreateOptions{})
require.NoError(t, err)
})
t.Run("Ensure", func(t *testing.T) {
t.Run("Ensure without schema", func(t *testing.T) {
crdOpts = updateMap(t, crdOpts, func(t *testing.T, key string, el crds.CRDOptions) crds.CRDOptions {
el.WithSchema = false
return el
})
require.NoError(t, EnsureCRDWithOptions(context.Background(), c, EnsureCRDOptions{IgnoreErrors: false, CRDOptions: crdOpts}))
for k, v := range dropLogMessages(t, s) {
t.Run(k, func(t *testing.T) {
if k == crds.AllDefinitions()[0].CRD.GetName() {
require.Equal(t, "CRD Update not required", v)
require.Equal(t, "CRD Updated", v)
} else {
require.Equal(t, "CRD Created", v)
}
})
}
})
t.Run("Rerun without schema", func(t *testing.T) {
crdOpts = updateMap(t, crdOpts, func(t *testing.T, key string, el crds.CRDOptions) crds.CRDOptions {
el.WithSchema = false
return el
})
require.NoError(t, EnsureCRDWithOptions(context.Background(), c, EnsureCRDOptions{IgnoreErrors: false, CRDOptions: crdOpts}))
for k, v := range dropLogMessages(t, s) {
t.Run(k, func(t *testing.T) {
require.Equal(t, "CRD Update not required", v)
})
}
})
t.Run("Ensure with schema", func(t *testing.T) {
crdOpts = updateMap(t, crdOpts, func(t *testing.T, key string, el crds.CRDOptions) crds.CRDOptions {
el.WithSchema = true
return el
})
require.NoError(t, EnsureCRDWithOptions(context.Background(), c, EnsureCRDOptions{IgnoreErrors: false, CRDOptions: crdOpts}))
for k, v := range dropLogMessages(t, s) {
t.Run(k, func(t *testing.T) {
require.Equal(t, "CRD Updated", v)
})
}
})
t.Run("Rerun with schema", func(t *testing.T) {
crdOpts = updateMap(t, crdOpts, func(t *testing.T, key string, el crds.CRDOptions) crds.CRDOptions {
el.WithSchema = true
return el
})
require.NoError(t, EnsureCRDWithOptions(context.Background(), c, EnsureCRDOptions{IgnoreErrors: false, CRDOptions: crdOpts}))
for k, v := range dropLogMessages(t, s) {
t.Run(k, func(t *testing.T) {
require.Equal(t, "CRD Update not required", v)
})
}
})
})
})
}
func updateMap[T comparable](t *testing.T, in map[string]T, f func(t *testing.T, key string, el T) T) map[string]T {
r := make(map[string]T, len(in))
for k, v := range in {
r[k] = f(t, k, v)
}
return r
}

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
AppsJobVersion = driver.Version("1.0.1")
)
// Deprecated: use AppsJobWithOptions instead
@ -40,7 +32,7 @@ func AppsJob() *apiextensions.CustomResourceDefinition {
}
func AppsJobWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(appsJobsCRD, appsJobsCRDSchemas, opts...)
return getCRD(AppsJobDefinitionData(), opts...)
}
// Deprecated: use AppsJobDefinitionWithOptions instead
@ -50,13 +42,17 @@ func AppsJobDefinition() Definition {
func AppsJobDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: AppsJobVersion,
DefinitionData: AppsJobDefinitionData(),
CRD: AppsJobWithOptions(opts...),
}
}
var appsJobsCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](appsJobs)
var appsJobsCRDSchemas = util.NewYamlLoader[crdSchemas](appsJobsSchemaRaw)
func AppsJobDefinitionData() DefinitionData {
return DefinitionData{
definition: appsJobs,
schemaDefinition: appsJobsSchemaRaw,
}
}
//go:embed apps-job.yaml
var appsJobs []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
BackupsBackupVersion = driver.Version("1.0.1")
)
// Deprecated: use BackupsBackupWithOptions instead
@ -40,7 +32,7 @@ func BackupsBackup() *apiextensions.CustomResourceDefinition {
}
func BackupsBackupWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(backupsBackupCRD, backupsBackupCRDSchemas, opts...)
return getCRD(BackupsBackupDefinitionData(), opts...)
}
// Deprecated: use BackupsBackupDefinitionWithOptions instead
@ -50,13 +42,17 @@ func BackupsBackupDefinition() Definition {
func BackupsBackupDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: BackupsBackupVersion,
DefinitionData: BackupsBackupDefinitionData(),
CRD: BackupsBackupWithOptions(opts...),
}
}
var backupsBackupCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](backupsBackup)
var backupsBackupCRDSchemas = util.NewYamlLoader[crdSchemas](backupsBackupSchemaRaw)
func BackupsBackupDefinitionData() DefinitionData {
return DefinitionData{
definition: backupsBackup,
schemaDefinition: backupsBackupSchemaRaw,
}
}
//go:embed backups-backup.yaml
var backupsBackup []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
BackupsBackupPolicyPolicyVersion = driver.Version("1.0.1")
)
// Deprecated: use BackupsBackupPolicyPolicyWithOptions instead
@ -40,7 +32,7 @@ func BackupsBackupPolicyPolicy() *apiextensions.CustomResourceDefinition {
}
func BackupsBackupPolicyPolicyWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(backupsBackupPolicyCRD, backupsBackupPolicyCRDSchemas, opts...)
return getCRD(BackupsBackupPolicyDefinitionData(), opts...)
}
// Deprecated: use func BackupsBackupPolicyDefinitionWithOptions instead
@ -50,13 +42,17 @@ func BackupsBackupPolicyDefinition() Definition {
func BackupsBackupPolicyDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: BackupsBackupPolicyPolicyVersion,
DefinitionData: BackupsBackupPolicyDefinitionData(),
CRD: BackupsBackupPolicyPolicyWithOptions(opts...),
}
}
var backupsBackupPolicyCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](backupsBackupPolicy)
var backupsBackupPolicyCRDSchemas = util.NewYamlLoader[crdSchemas](backupsBackupPolicySchemaRaw)
func BackupsBackupPolicyDefinitionData() DefinitionData {
return DefinitionData{
definition: backupsBackupPolicy,
schemaDefinition: backupsBackupPolicySchemaRaw,
}
}
//go:embed backups-backuppolicy.yaml
var backupsBackupPolicy []byte

View file

@ -25,16 +25,37 @@ import (
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
type Definition struct {
Version driver.Version
DefinitionData
CRD *apiextensions.CustomResourceDefinition
}
type DefinitionData struct {
definition []byte
schemaDefinition []byte
}
func (d DefinitionData) definitionLoader() util.Loader[apiextensions.CustomResourceDefinition] {
return util.NewYamlLoader[apiextensions.CustomResourceDefinition](d.definition)
}
func (d DefinitionData) schemaDefinitionLoader() util.Loader[crdSchemas] {
return util.NewYamlLoader[crdSchemas](d.schemaDefinition)
}
func (d DefinitionData) Checksum() (definition, schema string) {
if len(d.definition) > 0 {
definition = util.SHA256(d.definition)
}
if len(d.schemaDefinition) > 0 {
schema = util.SHA256(d.schemaDefinition)
}
return
}
func AllDefinitions() []Definition {
return []Definition{
// Deployment
@ -75,6 +96,14 @@ type CRDOptions struct {
WithSchema bool
}
func (o *CRDOptions) GetWithSchema() bool {
if o == nil {
return false
}
return o.WithSchema
}
func (o *CRDOptions) AsFunc() func(*CRDOptions) {
return func(opts *CRDOptions) {
if o == nil || opts == nil {
@ -91,18 +120,18 @@ func WithSchema() func(*CRDOptions) {
}
}
func getCRD(crdLoader util.Loader[apiextensions.CustomResourceDefinition], schemasLoader util.Loader[crdSchemas], opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
func getCRD(data DefinitionData, opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
o := &CRDOptions{}
for _, fn := range opts {
fn(o)
}
crd := crdLoader.MustGet()
crd := data.definitionLoader().MustGet()
if o.WithSchema {
crdWithSchema := crd.DeepCopy()
schemas := schemasLoader.MustGet()
schemas := data.schemaDefinitionLoader().MustGet()
for i, v := range crdWithSchema.Spec.Versions {
schema, ok := schemas[v.Name]

View file

@ -88,8 +88,20 @@ func Test_CRD(t *testing.T) {
}
func Test_AllDefinitionsDefined(t *testing.T) {
registered := map[string]bool{}
for _, def := range AllDefinitions() {
require.NotEmpty(t, def.Version)
a, b := def.Checksum()
require.NotEmpty(t, a)
require.NotEmpty(t, b)
require.NotContains(t, registered, a)
require.NotContains(t, registered, b)
registered[a] = true
registered[b] = true
require.NotNil(t, def.CRD)
}
}

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
DatabaseClusterSynchronizationVersion = driver.Version("1.0.1")
)
// Deprecated: use DatabaseClusterSynchronizationWithOptions instead
@ -40,7 +32,7 @@ func DatabaseClusterSynchronization() *apiextensions.CustomResourceDefinition {
}
func DatabaseClusterSynchronizationWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(databaseClusterSynchronizationCRD, databaseClusterSynchronizationCRDSchemas, opts...)
return getCRD(DatabaseClusterSynchronizationDefinitionData(), opts...)
}
// Deprecated: use DatabaseClusterSynchronizationDefinitionWithOptions instead
@ -50,13 +42,17 @@ func DatabaseClusterSynchronizationDefinition() Definition {
func DatabaseClusterSynchronizationDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: DatabaseClusterSynchronizationVersion,
DefinitionData: DatabaseClusterSynchronizationDefinitionData(),
CRD: DatabaseClusterSynchronizationWithOptions(opts...),
}
}
var databaseClusterSynchronizationCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseClusterSynchronization)
var databaseClusterSynchronizationCRDSchemas = util.NewYamlLoader[crdSchemas](databaseClusterSynchronizationSchemaRaw)
func DatabaseClusterSynchronizationDefinitionData() DefinitionData {
return DefinitionData{
definition: databaseClusterSynchronization,
schemaDefinition: databaseClusterSynchronizationSchemaRaw,
}
}
//go:embed database-clustersynchronization.yaml
var databaseClusterSynchronization []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
DatabaseDeploymentVersion = driver.Version("1.0.1")
)
// Deprecated: use DatabaseDeploymentWithOptions instead
@ -40,7 +32,7 @@ func DatabaseDeployment() *apiextensions.CustomResourceDefinition {
}
func DatabaseDeploymentWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(databaseDeploymentCRD, databaseDeploymentCRDSchemas, opts...)
return getCRD(DatabaseDeploymentDefinitionData(), opts...)
}
// Deprecated: use DatabaseDeploymentDefinitionWithOptions instead
@ -50,13 +42,17 @@ func DatabaseDeploymentDefinition() Definition {
func DatabaseDeploymentDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: DatabaseDeploymentVersion,
DefinitionData: DatabaseDeploymentDefinitionData(),
CRD: DatabaseDeploymentWithOptions(opts...),
}
}
var databaseDeploymentCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseDeployment)
var databaseDeploymentCRDSchemas = util.NewYamlLoader[crdSchemas](databaseDeploymentSchemaRaw)
func DatabaseDeploymentDefinitionData() DefinitionData {
return DefinitionData{
definition: databaseDeployment,
schemaDefinition: databaseDeploymentSchemaRaw,
}
}
//go:embed database-deployment.yaml
var databaseDeployment []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
DatabaseMemberVersion = driver.Version("1.0.1")
)
// Deprecated: use DatabaseMemberWithOptions instead
@ -40,7 +32,7 @@ func DatabaseMember() *apiextensions.CustomResourceDefinition {
}
func DatabaseMemberWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(databaseMemberCRD, databaseMemberCRDSchemas, opts...)
return getCRD(DatabaseMemberDefinitionData(), opts...)
}
// Deprecated: use DatabaseMemberDefinitionWithOptions instead
@ -50,13 +42,17 @@ func DatabaseMemberDefinition() Definition {
func DatabaseMemberDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: DatabaseMemberVersion,
DefinitionData: DatabaseMemberDefinitionData(),
CRD: DatabaseMemberWithOptions(opts...),
}
}
var databaseMemberCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseMember)
var databaseMemberCRDSchemas = util.NewYamlLoader[crdSchemas](databaseMemberSchemaRaw)
func DatabaseMemberDefinitionData() DefinitionData {
return DefinitionData{
definition: databaseMember,
schemaDefinition: databaseMemberSchemaRaw,
}
}
//go:embed database-member.yaml
var databaseMember []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
DatabaseTaskVersion = driver.Version("1.0.1")
)
// Deprecated: use DatabaseTaskWithOptions instead
@ -40,7 +32,7 @@ func DatabaseTask() *apiextensions.CustomResourceDefinition {
}
func DatabaseTaskWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(databaseTaskCRD, databaseTaskCRDSchemas, opts...)
return getCRD(DatabaseTaskDefinitionData(), opts...)
}
// Deprecated: use DatabaseTaskDefinitionWithOptions instead
@ -50,13 +42,17 @@ func DatabaseTaskDefinition() Definition {
func DatabaseTaskDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: DatabaseTaskVersion,
DefinitionData: DatabaseTaskDefinitionData(),
CRD: DatabaseTaskWithOptions(opts...),
}
}
var databaseTaskCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseTask)
var databaseTaskCRDSchemas = util.NewYamlLoader[crdSchemas](databaseTaskSchemaRaw)
func DatabaseTaskDefinitionData() DefinitionData {
return DefinitionData{
definition: databaseTask,
schemaDefinition: databaseTaskSchemaRaw,
}
}
//go:embed database-task.yaml
var databaseTask []byte

View file

@ -24,29 +24,25 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
MLExtensionVersion = driver.Version("1.0.0")
)
func MLExtensionWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(mlExtensionCRD, mlExtensionCRDSchemas, opts...)
return getCRD(MLExtensionDefinitionData(), opts...)
}
func MLExtensionDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: MLExtensionVersion,
DefinitionData: MLExtensionDefinitionData(),
CRD: MLExtensionWithOptions(opts...),
}
}
var mlExtensionCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](mlExtension)
var mlExtensionCRDSchemas = util.NewYamlLoader[crdSchemas](mlExtensionSchemaRaw)
func MLExtensionDefinitionData() DefinitionData {
return DefinitionData{
definition: mlExtension,
schemaDefinition: mlExtensionSchemaRaw,
}
}
//go:embed ml-extension.yaml
var mlExtension []byte

View file

@ -24,29 +24,25 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
MLBatchJobVersion = driver.Version("1.0.0")
)
func MLBatchJobWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(mlBatchJobCRD, mlBatchJobCRDSchemas, opts...)
return getCRD(MLBatchJobDefinitionData(), opts...)
}
func MLBatchJobDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: MLBatchJobVersion,
DefinitionData: MLBatchJobDefinitionData(),
CRD: MLBatchJobWithOptions(opts...),
}
}
var mlBatchJobCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](mlBatchJob)
var mlBatchJobCRDSchemas = util.NewYamlLoader[crdSchemas](mlBatchJobSchemaRaw)
func MLBatchJobDefinitionData() DefinitionData {
return DefinitionData{
definition: mlBatchJob,
schemaDefinition: mlBatchJobSchemaRaw,
}
}
//go:embed ml-job-batch.yaml
var mlBatchJob []byte

View file

@ -24,29 +24,25 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
MLCronJobVersion = driver.Version("1.0.0")
)
func MLCronJobWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(mlCronJobCRD, mlCronJobCRDSchemas, opts...)
return getCRD(MLCronJobDefinitionData(), opts...)
}
func MLCronJobDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: MLCronJobVersion,
DefinitionData: MLCronJobDefinitionData(),
CRD: MLCronJobWithOptions(opts...),
}
}
var mlCronJobCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](mlCronJob)
var mlCronJobCRDSchemas = util.NewYamlLoader[crdSchemas](mlCronJobSchemaRaw)
func MLCronJobDefinitionData() DefinitionData {
return DefinitionData{
definition: mlCronJob,
schemaDefinition: mlCronJobSchemaRaw,
}
}
//go:embed ml-job-cron.yaml
var mlCronJob []byte

View file

@ -24,29 +24,25 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
MLStorageVersion = driver.Version("1.0.0")
)
func MLStorageWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(mlStorageCRD, mlStorageCRDSchemas, opts...)
return getCRD(MLStorageDefinitionData(), opts...)
}
func MLStorageDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: MLStorageVersion,
DefinitionData: MLStorageDefinitionData(),
CRD: MLStorageWithOptions(opts...),
}
}
var mlStorageCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](mlStorage)
var mlStorageCRDSchemas = util.NewYamlLoader[crdSchemas](mlStorageSchemaRaw)
func MLStorageDefinitionData() DefinitionData {
return DefinitionData{
definition: mlStorage,
schemaDefinition: mlStorageSchemaRaw,
}
}
//go:embed ml-storage.yaml
var mlStorage []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
ReplicationDeploymentReplicationVersion = driver.Version("1.0.1")
)
// Deprecated: use ReplicationDeploymentReplicationWithOptions instead
@ -40,7 +32,7 @@ func ReplicationDeploymentReplication() *apiextensions.CustomResourceDefinition
}
func ReplicationDeploymentReplicationWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(replicationDeploymentReplicationCRD, replicationDeploymentReplicationCRDSchemas, opts...)
return getCRD(ReplicationDeploymentReplicationDefinitionData(), opts...)
}
// Deprecated: use ReplicationDeploymentReplicationDefinitionWithOptions instead
@ -50,13 +42,17 @@ func ReplicationDeploymentReplicationDefinition() Definition {
func ReplicationDeploymentReplicationDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: ReplicationDeploymentReplicationVersion,
DefinitionData: ReplicationDeploymentReplicationDefinitionData(),
CRD: ReplicationDeploymentReplicationWithOptions(opts...),
}
}
var replicationDeploymentReplicationCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](replicationDeploymentReplication)
var replicationDeploymentReplicationCRDSchemas = util.NewYamlLoader[crdSchemas](replicationDeploymentReplicationSchemaRaw)
func ReplicationDeploymentReplicationDefinitionData() DefinitionData {
return DefinitionData{
definition: replicationDeploymentReplication,
schemaDefinition: replicationDeploymentReplicationSchemaRaw,
}
}
//go:embed replication-deploymentreplication.yaml
var replicationDeploymentReplication []byte

View file

@ -24,29 +24,25 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
SchedulerProfileVersion = driver.Version("1.0.0")
)
func SchedulerProfileWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(schedulerProfileCRD, schedulerProfileCRDSchemas, opts...)
return getCRD(SchedulerProfileDefinitionData(), opts...)
}
func SchedulerProfileDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: SchedulerProfileVersion,
DefinitionData: SchedulerProfileDefinitionData(),
CRD: SchedulerProfileWithOptions(opts...),
}
}
var schedulerProfileCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](schedulerProfile)
var schedulerProfileCRDSchemas = util.NewYamlLoader[crdSchemas](schedulerProfileSchemaRaw)
func SchedulerProfileDefinitionData() DefinitionData {
return DefinitionData{
definition: schedulerProfile,
schemaDefinition: schedulerProfileSchemaRaw,
}
}
//go:embed scheduler-profile.yaml
var schedulerProfile []byte

View file

@ -24,14 +24,6 @@ import (
_ "embed"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/arangodb/go-driver"
"github.com/arangodb/kube-arangodb/pkg/util"
)
const (
StorageLocalStorageVersion = driver.Version("1.0.1")
)
// Deprecated: use StorageLocalStorageWithOptions instead
@ -40,7 +32,7 @@ func StorageLocalStorage() *apiextensions.CustomResourceDefinition {
}
func StorageLocalStorageWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
return getCRD(storageLocalStorageCRD, storageLocalStorageCRDSchemas, opts...)
return getCRD(StorageLocalStorageDefinitionData(), opts...)
}
// Deprecated: use StorageLocalStorageDefinitionWithOptions instead
@ -50,13 +42,17 @@ func StorageLocalStorageDefinition() Definition {
func StorageLocalStorageDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
return Definition{
Version: StorageLocalStorageVersion,
DefinitionData: StorageLocalStorageDefinitionData(),
CRD: StorageLocalStorageWithOptions(opts...),
}
}
var storageLocalStorageCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](storageLocalStorage)
var storageLocalStorageCRDSchemas = util.NewYamlLoader[crdSchemas](storageLocalStorageSchemaRaw)
func StorageLocalStorageDefinitionData() DefinitionData {
return DefinitionData{
definition: storageLocalStorage,
schemaDefinition: storageLocalStorageSchemaRaw,
}
}
//go:embed storage-localstorage.yaml
var storageLocalStorage []byte

View file

@ -27,7 +27,10 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
const Version = "arangodb.com/version"
const (
Version = "arangodb.com/version"
Schema = "arangodb.com/schema"
)
type crdDefinitionGetter func(opts *crds.CRDOptions) crds.Definition

View file

@ -1,57 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 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 crd
import (
"strconv"
"strings"
"github.com/arangodb/go-driver"
)
func isVersionValid(a driver.Version) bool {
q := strings.SplitN(string(a), ".", 3)
if len(q) < 2 {
// We do not have 2 parts
return false
}
_, err := strconv.Atoi(q[0])
if err != nil {
return false
}
_, err = strconv.Atoi(q[1])
return err == nil
}
func isUpdateRequired(a, b driver.Version) bool {
if a == b {
return false
}
if !isVersionValid(b) {
return true
}
return a.CompareTo(b) > 0
}

View file

@ -1,73 +0,0 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 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 crd
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/arangodb/go-driver"
)
func Test_Versions(t *testing.T) {
type c struct {
update bool
a, b driver.Version
}
cases := map[string]c{
"Empty": {
update: false,
},
"Local to empty": {
update: true,
a: "1.0.0",
b: "",
},
"Local to nonparsable": {
update: true,
a: "1.0.0",
b: "ffdfdasfdasdfsa",
},
"Same": {
update: false,
a: "1.0.0",
b: "1.0.0",
},
"Below": {
update: true,
a: "1.1.0",
b: "1.0.0",
},
"Above": {
update: false,
a: "1.0.0",
b: "1.1.0",
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
require.Equal(t, c.update, isUpdateRequired(c.a, c.b))
})
}
}

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.
@ -49,7 +49,7 @@ func (l *logScanner) GetData(t *testing.T, timeout time.Duration, obj interface{
if s, ok := l.Get(timeout); !ok {
return false
} else {
require.NoError(t, json.Unmarshal([]byte(s), obj))
require.NoError(t, json.Unmarshal([]byte(s), obj), s)
return true
}
}