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
3233type 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-
7869type crdSchemas map [string ]apiextensions.CustomResourceValidation
7970
8071type 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 {
0 commit comments