Skip to content

Commit

Permalink
WIP: Make generated CRDs first-class citizens
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Godding Boye <[email protected]>
  • Loading branch information
erikgb committed Nov 30, 2024
1 parent f3cd2f5 commit 57b55bf
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 24 deletions.
8 changes: 8 additions & 0 deletions deploy/crds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CRDs source directory

> **WARNING**: if you are an end-user, you probably should NOT need to use the
> files in this directory. These files are for **reference, development and testing purposes only**.
This directory contains 'source code' used to build our CustomResourceDefinition
resources consumed by our officially supported deployment methods (e.g. the Helm chart).
The CRDs in this directory might be incomplete, and should **NOT** be used to provision the operator.
441 changes: 441 additions & 0 deletions deploy/crds/trust.cert-manager.io_bundles.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions klone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ targets:
repo_hash: 67e71b61af17a44f8f619394d79d343134086e40
repo_path: modules/go
- folder_name: helm
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 67e71b61af17a44f8f619394d79d343134086e40
repo_url: https://github.com/erikgb/makefile-modules.git
repo_ref: new-gen-crds
repo_hash: 9f789c153a7238749f02a4e82c73bc4800c6077f
repo_path: modules/helm
- folder_name: help
repo_url: https://github.com/cert-manager/makefile-modules.git
Expand Down
16 changes: 9 additions & 7 deletions make/_shared/helm/crds.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,31 @@ ifeq ($(HOST_OS),darwin)
sed_inplace := sed -i ''
endif

crds_dir ?= deploy/crds
crds_dir_readme := $(dir $(lastword $(MAKEFILE_LIST)))/crds_dir.README.md

.PHONY: generate-crds
## Generate CRD manifests.
## @category [shared] Generate/ Verify
generate-crds: | $(NEEDS_CONTROLLER-GEN) $(NEEDS_YQ)
$(eval crds_gen_temp := $(bin_dir)/scratch/crds)
$(eval directories := $(shell ls -d */ | grep -v -e 'make' $(shell git check-ignore -- * | sed 's/^/-e /')))

rm -rf $(crds_gen_temp)
mkdir -p $(crds_gen_temp)
mkdir -p $(crds_dir)
cat $(crds_dir_readme) > $(crds_dir)/README.md

$(CONTROLLER-GEN) crd \
$(directories:%=paths=./%...) \
output:crd:artifacts:config=$(crds_gen_temp)
output:crd:artifacts:config=$(crds_dir)

echo "Updating CRDs with helm templating, writing to $(helm_chart_source_dir)/templates"

@for i in $$(ls $(crds_gen_temp)); do \
crd_name=$$($(YQ) eval '.metadata.name' $(crds_gen_temp)/$$i); \
@for i in $$(ls $(crds_dir).yaml); do \
crd_name=$$($(YQ) eval '.metadata.name' $(crds_dir)/$$i); \
cat $(crd_template_header) > $(helm_chart_source_dir)/templates/crd-$$i; \
echo "" >> $(helm_chart_source_dir)/templates/crd-$$i; \
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $(helm_chart_source_dir)/templates/crd-$$i; \
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $(helm_chart_source_dir)/templates/crd-$$i; \
$(YQ) -I2 '{"spec": .spec}' $(crds_gen_temp)/$$i >> $(helm_chart_source_dir)/templates/crd-$$i; \
$(YQ) -I2 '{"spec": .spec}' $(crds_dir)/$$i >> $(helm_chart_source_dir)/templates/crd-$$i; \
cat $(crd_template_footer) >> $(helm_chart_source_dir)/templates/crd-$$i; \
done

Expand Down
8 changes: 8 additions & 0 deletions make/_shared/helm/crds_dir.README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CRDs source directory

> **WARNING**: if you are an end-user, you probably should NOT need to use the
> files in this directory. These files are for **reference, development and testing purposes only**.
This directory contains 'source code' used to build our CustomResourceDefinition
resources consumed by our officially supported deployment methods (e.g. the Helm chart).
The CRDs in this directory might be incomplete, and should **NOT** be used to provision the operator.
9 changes: 1 addition & 8 deletions make/test-integration.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

trust_manager_crds := $(bin_dir)/scratch/trust.cert-manager.io_bundles.yaml
$(trust_manager_crds): $(helm_chart_archive) | $(NEEDS_HELM) $(NEEDS_YQ)
$(HELM) template test "$(helm_chart_archive)" | \
$(YQ) e '. | select(.kind == "CustomResourceDefinition")' \
> $@

.PHONY: test-integration
## Integration tests
## @category Testing
test-integration: | $(trust_manager_crds) $(NEEDS_GOTESTSUM) $(NEEDS_ETCD) $(NEEDS_KUBE-APISERVER) $(NEEDS_KUBECTL) $(ARTIFACTS)
TRUST_MANAGER_CRDS=$(CURDIR)/$(trust_manager_crds) \
test-integration: | $(NEEDS_GOTESTSUM) $(NEEDS_ETCD) $(NEEDS_KUBE-APISERVER) $(NEEDS_KUBECTL) $(ARTIFACTS)
KUBEBUILDER_ASSETS=$(CURDIR)/$(bin_dir)/tools \
$(GOTESTSUM) \
--junitfile=$(ARTIFACTS)/junit-go-e2e.xml \
Expand Down
10 changes: 4 additions & 6 deletions test/integration/bundle/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package test

import (
"os"
"path"

"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/envtest"
Expand All @@ -37,15 +37,13 @@ var (
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

crdsYamlFile := os.Getenv("TRUST_MANAGER_CRDS")
Expect(crdsYamlFile).NotTo(BeEmpty(), "TRUST_MANAGER_CRDS must be set to the path of the CRDs to install")

env = &envtest.Environment{
UseExistingCluster: ptr.To(false),
CRDDirectoryPaths: []string{
crdsYamlFile,
path.Join("..", "..", "..", "deploy", "crds"),
},
Scheme: trustapi.GlobalScheme,
ErrorIfCRDPathMissing: true,
Scheme: trustapi.GlobalScheme,
}

_, err := env.Start()
Expand Down

0 comments on commit 57b55bf

Please sign in to comment.