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

Make generated CRDs directly available for testing and development #214

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
_bin
_bin
.idea/
*.iml
21 changes: 13 additions & 8 deletions modules/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 modules/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.
Loading