Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Make generated CRDs first-class citizens #493

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 47c10e2ea2ff413fcff219c458df04a3feef2fc3
repo_path: modules/go
- folder_name: helm
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: 47c10e2ea2ff413fcff219c458df04a3feef2fc3
repo_url: https://github.com/erikgb/makefile-modules.git
repo_ref: new-gen-crds
repo_hash: 0d31381d7329c10857821ddc89d5ca1db05b0baf
repo_path: modules/helm
- folder_name: help
repo_url: https://github.com/cert-manager/makefile-modules.git
Expand Down
21 changes: 13 additions & 8 deletions make/_shared/helm/crds.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,34 @@ ifeq ($(HOST_OS),darwin)
sed_inplace := sed -i ''
endif

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

$(crds_dir):
mkdir -p $@

$(crds_dir)/README.md: $(crds_dir_readme) | $(crds_dir)
cp $< $@

.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)

$(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 $$(basename $(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