Skip to content

Commit 2206eea

Browse files
committed
Allow for excluding CRD template files
Signed-off-by: Erik Godding Boye <egboye@gmail.com>
1 parent 8187c64 commit 2206eea

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

modules/helm/crds.mk

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ endif
4040
crds_dir ?= deploy/crds
4141
crds_dir_readme := $(dir $(lastword $(MAKEFILE_LIST)))/crds_dir.README.md
4242
crds_expression ?= .Values.crds.enabled
43+
crds_template_include_pattern := *.yaml
44+
# Space-separated list of basenames to exclude (e.g. foo.yaml *_test.yaml)
45+
crds_template_exclude_pattern ?=
46+
47+
define filter-out-basenames
48+
$(if $(strip $(2)), \
49+
$(foreach f,$(1),$(if $(filter $(2),$(notdir $(f))),,$(f))), \
50+
$(1))
51+
endef
52+
define crd-template-path
53+
$(helm_chart_source_dir)/templates/crd-$(1)
54+
endef
4355

4456
.PHONY: generate-crds
4557
## Generate CRD manifests.
@@ -57,14 +69,20 @@ generate-crds: | $(NEEDS_CONTROLLER-GEN) $(NEEDS_YQ)
5769

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

60-
@for i in $$(ls $(crds_gen_temp)); do \
61-
crd_name=$$($(YQ) eval '.metadata.name' $(crds_gen_temp)/$$i); \
62-
cat $(crd_template_header) > $(helm_chart_source_dir)/templates/crd-$$i; \
63-
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $(helm_chart_source_dir)/templates/crd-$$i; \
64-
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $(helm_chart_source_dir)/templates/crd-$$i; \
65-
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $(helm_chart_source_dir)/templates/crd-$$i; \
66-
$(YQ) -I2 '{"spec": .spec}' $(crds_gen_temp)/$$i >> $(helm_chart_source_dir)/templates/crd-$$i; \
67-
cat $(crd_template_footer) >> $(helm_chart_source_dir)/templates/crd-$$i; \
72+
$(eval crds_gen_temp_all_files := $(wildcard $(crds_gen_temp)/$(crds_template_include_pattern)))
73+
$(eval crds_gen_temp_files := $(if $(crds_template_exclude_pattern), \
74+
$(call filter-out-basenames,$(crds_gen_temp_all_files),$(crds_template_exclude_pattern)), \
75+
$(crds_gen_temp_all_files)))
76+
77+
@for i in $(crds_gen_temp_files); do \
78+
crd_name=$$($(YQ) eval '.metadata.name' $$i); \
79+
crd_template_file="$(call crd-template-path,$$(basename $$i))"; \
80+
cat $(crd_template_header) > $$crd_template_file; \
81+
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $$crd_template_file; \
82+
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $$crd_template_file; \
83+
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $$crd_template_file; \
84+
$(YQ) -I2 '{"spec": .spec}' $$i >> $$crd_template_file; \
85+
cat $(crd_template_footer) >> $$crd_template_file; \
6886
done
6987

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

0 commit comments

Comments
 (0)