Skip to content
Merged
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
31 changes: 23 additions & 8 deletions modules/helm/crds.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ endif
crds_dir ?= deploy/crds
crds_dir_readme := $(dir $(lastword $(MAKEFILE_LIST)))/crds_dir.README.md
crds_expression ?= .Values.crds.enabled
crds_template_include_pattern := *.yaml
# Space-separated list of basenames to exclude (e.g. foo.yaml *_test.yaml)
crds_template_exclude_pattern ?=

define filter-out-basenames
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this works, but I trust you that it works.

$(if $(strip $(2)), \
$(foreach f,$(1),$(if $(filter $(2),$(notdir $(f))),,$(f))), \
$(1))
endef

.PHONY: generate-crds
## Generate CRD manifests.
Expand All @@ -57,14 +66,20 @@ generate-crds: | $(NEEDS_CONTROLLER-GEN) $(NEEDS_YQ)

@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); \
cat $(crd_template_header) > $(helm_chart_source_dir)/templates/crd-$$i; \
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $(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; \
cat $(crd_template_footer) >> $(helm_chart_source_dir)/templates/crd-$$i; \
$(eval crds_gen_temp_all_files := $(wildcard $(crds_gen_temp)/$(crds_template_include_pattern)))
$(eval crds_gen_temp_files := $(if $(crds_template_exclude_pattern), \
$(call filter-out-basenames,$(crds_gen_temp_all_files),$(crds_template_exclude_pattern)), \
$(crds_gen_temp_all_files)))

@for f in $(crds_gen_temp_files); do \
crd_name=$$($(YQ) eval '.metadata.name' $$f); \
crd_template_file="$(helm_chart_source_dir)/templates/crd-$$(basename $$f)"; \
cat $(crd_template_header) > $$crd_template_file; \
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $$crd_template_file; \
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $$crd_template_file; \
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $$crd_template_file; \
$(YQ) -I2 '{"spec": .spec}' $$f >> $$crd_template_file; \
cat $(crd_template_footer) >> $$crd_template_file; \
done

@if [ -n "$$(ls $(crds_gen_temp) 2>/dev/null)" ]; then \
Expand Down
Loading