Skip to content

Commit 82a8722

Browse files
authored
[Bugfix] Enable LazyLoader for CRD & CRD Schemas (#1582)
1 parent ffd9d52 commit 82a8722

16 files changed

+168
-109
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Documentation) Use relative links for generated docs
1010
- (Improvement) Change default logging level to info. Add --log.sampling (default true). Adjust log levels.
1111
- (Maintenance) Bump Go to 1.21.6
12+
- (Bugfix) Enable LazyLoader for CRD & CRD Schemas
1213

1314
## [1.2.36](https://github.com/arangodb/kube-arangodb/tree/1.2.36) (2024-01-08)
1415
- (Documentation) Improvements and fixes for rendered documentation (GH pages)

pkg/crd/crds/apps-job.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
AppsJobVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(appsJobs, appsJobsSchemaRaw, &appsJobsCRD, &appsJobsCRDSchemas)
37-
}
38-
3937
// Deprecated: use AppsJobWithOptions instead
4038
func AppsJob() *apiextensions.CustomResourceDefinition {
4139
return AppsJobWithOptions()
@@ -57,8 +55,8 @@ func AppsJobDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
5755
}
5856
}
5957

60-
var appsJobsCRD apiextensions.CustomResourceDefinition
61-
var appsJobsCRDSchemas crdSchemas
58+
var appsJobsCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](appsJobs)
59+
var appsJobsCRDSchemas = util.NewYamlLoader[crdSchemas](appsJobsSchemaRaw)
6260

6361
//go:embed apps-job.yaml
6462
var appsJobs []byte

pkg/crd/crds/backups-backup.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
BackupsBackupVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(backupsBackup, backupsBackupSchemaRaw, &backupsBackupCRD, &backupsBackupCRDSchemas)
37-
}
38-
3937
// Deprecated: use BackupsBackupWithOptions instead
4038
func BackupsBackup() *apiextensions.CustomResourceDefinition {
4139
return BackupsBackupWithOptions()
@@ -57,8 +55,8 @@ func BackupsBackupDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
5755
}
5856
}
5957

60-
var backupsBackupCRD apiextensions.CustomResourceDefinition
61-
var backupsBackupCRDSchemas crdSchemas
58+
var backupsBackupCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](backupsBackup)
59+
var backupsBackupCRDSchemas = util.NewYamlLoader[crdSchemas](backupsBackupSchemaRaw)
6260

6361
//go:embed backups-backup.yaml
6462
var backupsBackup []byte

pkg/crd/crds/backups-backuppolicy.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
BackupsBackupPolicyPolicyVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(backupsBackupPolicy, backupsBackupPolicySchemaRaw, &backupsBackupPolicyCRD, &backupsBackupPolicyCRDSchemas)
37-
}
38-
3937
// Deprecated: use BackupsBackupPolicyPolicyWithOptions instead
4038
func BackupsBackupPolicyPolicy() *apiextensions.CustomResourceDefinition {
4139
return BackupsBackupPolicyPolicyWithOptions()
@@ -57,8 +55,8 @@ func BackupsBackupPolicyDefinitionWithOptions(opts ...func(*CRDOptions)) Definit
5755
}
5856
}
5957

60-
var backupsBackupPolicyCRD apiextensions.CustomResourceDefinition
61-
var backupsBackupPolicyCRDSchemas crdSchemas
58+
var backupsBackupPolicyCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](backupsBackupPolicy)
59+
var backupsBackupPolicyCRDSchemas = util.NewYamlLoader[crdSchemas](backupsBackupPolicySchemaRaw)
6260

6361
//go:embed backups-backuppolicy.yaml
6462
var backupsBackupPolicy []byte

pkg/crd/crds/crds.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -24,9 +24,10 @@ import (
2424
"fmt"
2525

2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
27-
"k8s.io/apimachinery/pkg/util/yaml"
2827

2928
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
3031
)
3132

3233
type Definition struct {
@@ -65,16 +66,6 @@ func AllDefinitions() []Definition {
6566
}
6667
}
6768

68-
func mustLoadCRD(crdRaw, crdSchemasRaw []byte, crd *apiextensions.CustomResourceDefinition, schemas *crdSchemas) {
69-
if err := yaml.Unmarshal(crdRaw, crd); err != nil {
70-
panic(err)
71-
}
72-
73-
if err := yaml.Unmarshal(crdSchemasRaw, schemas); err != nil {
74-
panic(err)
75-
}
76-
}
77-
7869
type crdSchemas map[string]apiextensions.CustomResourceValidation
7970

8071
type CRDOptions struct {
@@ -97,13 +88,19 @@ func WithSchema() func(*CRDOptions) {
9788
}
9889
}
9990

100-
func getCRD(crd apiextensions.CustomResourceDefinition, schemas crdSchemas, opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
91+
func getCRD(crdLoader util.Loader[apiextensions.CustomResourceDefinition], schemasLoader util.Loader[crdSchemas], opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
10192
o := &CRDOptions{}
10293
for _, fn := range opts {
10394
fn(o)
10495
}
96+
97+
crd := crdLoader.MustGet()
98+
10599
if o.WithSchema {
106100
crdWithSchema := crd.DeepCopy()
101+
102+
schemas := schemasLoader.MustGet()
103+
107104
for i, v := range crdWithSchema.Spec.Versions {
108105
schema, ok := schemas[v.Name]
109106
if !ok {

pkg/crd/crds/database-clustersynchronization.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
DatabaseClusterSynchronizationVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(databaseClusterSynchronization, databaseClusterSynchronizationSchemaRaw, &databaseClusterSynchronizationCRD, &databaseClusterSynchronizationCRDSchemas)
37-
}
38-
3937
// Deprecated: use DatabaseClusterSynchronizationWithOptions instead
4038
func DatabaseClusterSynchronization() *apiextensions.CustomResourceDefinition {
4139
return DatabaseClusterSynchronizationWithOptions()
@@ -57,8 +55,8 @@ func DatabaseClusterSynchronizationDefinitionWithOptions(opts ...func(*CRDOption
5755
}
5856
}
5957

60-
var databaseClusterSynchronizationCRD apiextensions.CustomResourceDefinition
61-
var databaseClusterSynchronizationCRDSchemas crdSchemas
58+
var databaseClusterSynchronizationCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseClusterSynchronization)
59+
var databaseClusterSynchronizationCRDSchemas = util.NewYamlLoader[crdSchemas](databaseClusterSynchronizationSchemaRaw)
6260

6361
//go:embed database-clustersynchronization.yaml
6462
var databaseClusterSynchronization []byte

pkg/crd/crds/database-deployment.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
DatabaseDeploymentVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(databaseDeployment, databaseDeploymentSchemaRaw, &databaseDeploymentCRD, &databaseDeploymentCRDSchemas)
37-
}
38-
3937
// Deprecated: use DatabaseDeploymentWithOptions instead
4038
func DatabaseDeployment() *apiextensions.CustomResourceDefinition {
4139
return DatabaseDeploymentWithOptions()
@@ -57,8 +55,8 @@ func DatabaseDeploymentDefinitionWithOptions(opts ...func(*CRDOptions)) Definiti
5755
}
5856
}
5957

60-
var databaseDeploymentCRD apiextensions.CustomResourceDefinition
61-
var databaseDeploymentCRDSchemas crdSchemas
58+
var databaseDeploymentCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseDeployment)
59+
var databaseDeploymentCRDSchemas = util.NewYamlLoader[crdSchemas](databaseDeploymentSchemaRaw)
6260

6361
//go:embed database-deployment.yaml
6462
var databaseDeployment []byte

pkg/crd/crds/database-member.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
DatabaseMemberVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(databaseMember, databaseMemberSchemaRaw, &databaseMemberCRD, &databaseMemberCRDSchemas)
37-
}
38-
3937
// Deprecated: use DatabaseMemberWithOptions instead
4038
func DatabaseMember() *apiextensions.CustomResourceDefinition {
4139
return DatabaseMemberWithOptions()
@@ -57,8 +55,8 @@ func DatabaseMemberDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
5755
}
5856
}
5957

60-
var databaseMemberCRD apiextensions.CustomResourceDefinition
61-
var databaseMemberCRDSchemas crdSchemas
58+
var databaseMemberCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseMember)
59+
var databaseMemberCRDSchemas = util.NewYamlLoader[crdSchemas](databaseMemberSchemaRaw)
6260

6361
//go:embed database-member.yaml
6462
var databaseMember []byte

pkg/crd/crds/database-task.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
DatabaseTaskVersion = driver.Version("1.0.1")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(databaseTask, databaseTaskSchemaRaw, &databaseTaskCRD, &databaseTaskCRDSchemas)
37-
}
38-
3937
// Deprecated: use DatabaseTaskWithOptions instead
4038
func DatabaseTask() *apiextensions.CustomResourceDefinition {
4139
return DatabaseTaskWithOptions()
@@ -57,8 +55,8 @@ func DatabaseTaskDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
5755
}
5856
}
5957

60-
var databaseTaskCRD apiextensions.CustomResourceDefinition
61-
var databaseTaskCRDSchemas crdSchemas
58+
var databaseTaskCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](databaseTask)
59+
var databaseTaskCRDSchemas = util.NewYamlLoader[crdSchemas](databaseTaskSchemaRaw)
6260

6361
//go:embed database-task.yaml
6462
var databaseTask []byte

pkg/crd/crds/ml-extension.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -26,16 +26,14 @@ import (
2626
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727

2828
"github.com/arangodb/go-driver"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
)
3032

3133
const (
3234
MLExtensionVersion = driver.Version("1.0.0")
3335
)
3436

35-
func init() {
36-
mustLoadCRD(mlExtension, mlExtensionSchemaRaw, &mlExtensionCRD, &mlExtensionCRDSchemas)
37-
}
38-
3937
func MLExtensionWithOptions(opts ...func(*CRDOptions)) *apiextensions.CustomResourceDefinition {
4038
return getCRD(mlExtensionCRD, mlExtensionCRDSchemas, opts...)
4139
}
@@ -47,8 +45,8 @@ func MLExtensionDefinitionWithOptions(opts ...func(*CRDOptions)) Definition {
4745
}
4846
}
4947

50-
var mlExtensionCRD apiextensions.CustomResourceDefinition
51-
var mlExtensionCRDSchemas crdSchemas
48+
var mlExtensionCRD = util.NewYamlLoader[apiextensions.CustomResourceDefinition](mlExtension)
49+
var mlExtensionCRDSchemas = util.NewYamlLoader[crdSchemas](mlExtensionSchemaRaw)
5250

5351
//go:embed ml-extension.yaml
5452
var mlExtension []byte

0 commit comments

Comments
 (0)