Skip to content

Commit 87b385e

Browse files
josvazgs-urbaniak
andauthored
CLOUDP-358677: Embed CRDs (#2949)
* CLOUDP-358677: Embed CRDs * fix unit test Signed-off-by: jose.vazquez <[email protected]> --------- Signed-off-by: jose.vazquez <[email protected]> Co-authored-by: Sergiusz Urbaniak <[email protected]>
1 parent 972914a commit 87b385e

File tree

5 files changed

+2262
-1
lines changed

5 files changed

+2262
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ x509-cert: ## Create X.509 cert at path tmp/x509/ (see docs/x509-user.md)
500500
clean: ## Clean built binaries
501501
rm -rf bin/*
502502
rm -rf config/manifests/bases/
503-
rm config/generated/crd/bases/crds.yaml
503+
rm -f config/generated/crd/bases/crds.yaml
504504
rm -f config/crd/bases/*.yaml
505505
rm -f config/rbac/clusterwide/role.yaml
506506
rm -f config/rbac/namespaced/role.yaml
@@ -886,6 +886,7 @@ gen-crds: tools/openapi2crd/bin/openapi2crd
886886
$(MAKE) -C tools/openapi2crd build
887887
$(OPENAPI2CRD) --config config/openapi2crd.yaml \
888888
--output $(realpath .)/config/generated/crd/bases/crds.yaml $(OPENAPI2CRD_OVERRIDE)
889+
cp $(realpath .)/config/generated/crd/bases/crds.yaml $(realpath .)/internal/generated/crds/crds.yaml
889890

890891
gen-go-types:
891892
@echo "==> Generating Go models from CRDs..."

internal/generated/crds/crds.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package crds
16+
17+
import (
18+
"bufio"
19+
"bytes"
20+
_ "embed"
21+
"fmt"
22+
23+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
24+
)
25+
26+
//go:embed crds.yaml
27+
var crdsYAML []byte
28+
29+
// EmbeddedCRD tried to load the given kind from a set of embedded CRDs
30+
func EmbeddedCRD(kind string) (*apiextensionsv1.CustomResourceDefinition, error) {
31+
for {
32+
crd, err := ParseCRD(bufio.NewScanner(bytes.NewBuffer(crdsYAML)))
33+
if err != nil {
34+
return nil, fmt.Errorf("failed to parse CRDs YAML for %q: %w", kind, err)
35+
}
36+
if crd.Spec.Names.Kind == kind {
37+
return crd, nil
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)